I learnt from Google that Internationalization is the process by which I can make my
web application to use all languages. I want to understand Unicode for the process of internationalization, so I learnt about Unicode from here and there.
I am able to understand about Unicode that how a charset set in encoded to bytes and again bytes decoded to charset. But I don't know how to move forward further. I want to learn how to compare strings and I need to know how to implement internationalization in my web application. Any Suggestions Please? Please guide me.
My Objective:
My main objective is to develop a Web Application for Translation (English to Arabic & vice versa). I want to follow Internationalization. I wish to run my web Application for translation in all the three browsers namely FF, Chrome, IE. How do I achieve this?
In case of a basic JSP/Servlet webapplication, the basic approach would be using JSTL fmt taglib in combination with resource bundles. Resource bundles contain key-value pairs where the key is a constant which is the same for all languages and the value differs per language. Resource bundles are usually properties files which are loaded by ResourceBundle API. This can however be customized so that you can load the key-value pairs from for example a database.
Here's an example how to internationalize the login form of your webapplication with properties file based resource bundles.
Create the following files and put them in some package, e.g. com.example.i18n (in case of Maven, put them in the package structure inside src/main/resources).
text.properties (contains key-value pairs in the default language, usually English)
login.label.username = Username
login.label.password = Password
login.button.submit = Sign in
text_nl.properties (contains Dutch (nl) key-value pairs)
login.label.username = Gebruikersnaam
login.label.password = Wachtwoord
login.button.submit = Inloggen
text_es.properties (contains Spanish (es) key-value pairs)
login.label.username = Nombre de usuario
login.label.password = Contraseña
login.button.submit = Acceder
The resource bundle filename should adhere the following pattern name_ll_CC.properties. The _ll part should be the lowercase ISO 693-1 language code. It is optional and only required whenever the _CC part is present. The _CC part should be the uppercase ISO 3166-1 Alpha-2 country code. It is optional and often only used to distinguish between country-specific language dialects, like American English (_en_US) and British English (_en_GB).
If not done yet, install JSTL as per instructions in this answer: How to install JSTL? The absolute uri: http://java.sun.com/jstl/core cannot be resolved.
Create the following example JSP file and put it in web content folder.
login.jsp
<%# page pageEncoding="UTF-8" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="language" value="${not empty param.language ? param.language : not empty language ? language : pageContext.request.locale}" scope="session" />
<fmt:setLocale value="${language}" />
<fmt:setBundle basename="com.example.i18n.text" />
<!DOCTYPE html>
<html lang="${language}">
<head>
<title>JSP/JSTL i18n demo</title>
</head>
<body>
<form>
<select id="language" name="language" onchange="submit()">
<option value="en" ${language == 'en' ? 'selected' : ''}>English</option>
<option value="nl" ${language == 'nl' ? 'selected' : ''}>Nederlands</option>
<option value="es" ${language == 'es' ? 'selected' : ''}>Español</option>
</select>
</form>
<form method="post">
<label for="username"><fmt:message key="login.label.username" />:</label>
<input type="text" id="username" name="username">
<br>
<label for="password"><fmt:message key="login.label.password" />:</label>
<input type="password" id="password" name="password">
<br>
<fmt:message key="login.button.submit" var="buttonValue" />
<input type="submit" name="submit" value="${buttonValue}">
</form>
</body>
</html>
The <c:set var="language"> manages the current language. If the language was supplied as request parameter (by language dropdown), then it will be set. Else if the language was already previously set in the session, then stick to it instead. Else use the user supplied locale in the request header.
The <fmt:setLocale> sets the locale for resource bundle. It's important that this line is before the <fmt:setBundle>.
The <fmt:setBundle> initializes the resource bundle by its base name (that is, the full qualified package name until with the sole name without the _ll_CC specifier).
The <fmt:message> retrieves the message value by the specified bundle key.
The <html lang="${language}"> informs the searchbots what language the page is in so that it won't be marked as duplicate content (thus, good for SEO).
The language dropdown will immediately submit by JavaScript when another language is chosen and the page will be refreshed with the newly chosen language.
You however need to keep in mind that properties files are by default read using ISO-8859-1 character encoding. You would need to escape them by unicode escapes. This can be done using the JDK-supplied native2ascii.exe tool. See also this article section for more detail.
A theoretical alternative would be to supply a bundle with a custom Control to load those files as UTF-8, but that's unfortunately not supported by the basic JSTL fmt taglib. You would need to manage it all yourself with help of a Filter. There are (MVC) frameworks which can handle this in a more transparent manner, like JSF, see also this article.
In addition to what BalusC said, you have to take care about directionality (since English is written Left-To-Right and Arabic the other way round). The easiest way would be to add dir attribute to html element of your JSP web page and externalize it, so the value comes from properties file (just like with other elements or attributes):
<html dir="${direction}">
...
</html>
Also, there are few issues with styling such application - you should to say the least avoid absolute positioning. If you cannot avoid that for some reason, you could either use different stylesheets per (each?) language or do something that is verboten, that is use tables for managing layout. If you want to use div elements, I'd suggest to use relative positioning with "symmetric" left and right style attributes (both having the same value), since this is what makes switching directionality work.
You could find more about Bi-Directional websites here.
based on this tutorial, I am using the following on GAE - Google's App Engine:
A jsp file as follows:
<%# page import="java.io.* %>
<%
String lang = "fr"; //Assign the correct language either by page or user-selected or browser language etc.
ResourceBundle RB = ResourceBundle.getBundle("app", new Locale(lang));
%>
<!DOCTYPE html>
<%# page contentType="text/html;charset=UTF-8" language="java"%>
<head>
</head>
<body>
<p>
<%= RB.getString("greeting") %>
</p>
</body>
And adding the files named: app.properties (default) and app_fr.properties (and so on for every language). Each of these files should contain the strings you need as follows: key:value_in_language, e.g. app_fr.properties contains:
greeting=Bonjour!
app.properties contains:
greeting=Hello!
That's all
Related
I'm trying to add refinements to my google custom search.
I have meta tags on just about every page of the site, such as
<meta name="type-id" content="241" />
Where there are many different types, and I want to have one refinement for each type.
In the docs, it says
You can also use these more:pagemap: operators with refinement labels
But I have been unable to do that.
Note that I have had success using more:pagemap:metatags-type-id:241 in the search input, or as a webSearchQueryAddition - but despite googles docs, I haven't been able to get it to work with a refinement.
Here's a sample from my cse.xml (removing some attributes from the CustomSearchEngine tag):
<?xml version="1.0" encoding="UTF-8"?>
<CustomSearchEngine>
<Title>Test</Title>
<Context>
<Facet>
<FacetItem>
<Label name="videos" mode="FILTER">
<Rewrite>more:p:metatags-article-keyword:121</Rewrite>
</Label>
<Title>Videos</Title>
</FacetItem>
</Facet>
</Context>
</CustomSearchEngine>
Is this supposed to work? Am I using wrong syntax in the rewrite rule? Has anyone else done something like this?
Your label in the facet should be mode="BOOST" if you want to restrict to a structured data field within the scope of your engine.
<Facet>
<FacetItem>
<Label name="videos" mode="BOOST">
<Rewrite>more:p:metatags-article-keyword:121</Rewrite>
</Label>
<Title>Videos</Title>
</FacetItem>
</Facet>
I am using AngleSharp to "open" a URL, change the value attribute of an input and then submit the form.
BUT when I get the HTML code from the URL, I get an unrecognized char in the name attribute of the input that interests me. See:
<!DOCTYPE html>
<html>
<head></head>
<body>
<hr>
<center>USER MENU<hr></center>
<form method="post" name="input" enctype="text/plain">
<fieldset>
<legend>ENTER USER CODE</legend>
ENTER USER CODE: <input type="password" name="�00" maxlength="4">
<br>
<button type="submit" formenctype="text/plain">SEND</button>
</fieldset>
</form>
</body>
</html>
As you can see this is the only input in the form so I can "catch" it (to change the value) by other attributes of it as selectors. Like this: [type=password]
context.Active.QuerySelector(Of IHtmlInputElement)("[type=password]").SetAttribute("value", "1111")
So, the problem is when I submit the form, it sends the post data with wrong name and they cannot get recognized. I learned what the unrecognizable character is by opening this URL in browser, and double check it using Wireshark (to get the HEX value of the char).
Finally, the char was a greek A in the browser source view and as Wireshark said it was the Symbol of C1 which is Á with description: Latin capital letter A with acute (see http://www.ascii-code.com/)
I know the man who created this web interface and he told me he used a greek A by fault and he cannot change it (I will explain why).
So, now that I know what the server expects I thought I could set the name attribute too and then send the form. But when I do it doesn't get recognized neither cause as I check in Wireshark the char is not the same char the browser sends when you submit the form. (I struggled to set the right name with no luck).
I also thought it may be some kind of encoding issue but I didn't manage to set the encoding in the context configuration. I set the culture to "el-GR" before I get the HTML but nothing changed.
What can I do? Do you have any suggestions?
PS. This is a low security web interface hosted by a microcontroller. The HTML cannot be changed because the device has already got a certification. Also, the interface works perfectly when used in browser.
I had to create a class that Implements the IEncodingProvider interface and then supply an instance of this class to the Configuration constructor via the with method.
Here is the class:
Private Class FixedEncodingProvider
Implements IEncodingProvider
Public Function Suggest(locale As String) As Encoding Implements IEncodingProvider.Suggest
Return Encoding.GetEncoding(1253)
End Function
End Class
and then use it like this:
Dim Config = Configuration.Default.WithDefaultLoader.With(New FixedEncodingProvider())
Dim context = BrowsingContext.[New](Config)
Special Thanks to the library's creator FlorianRappl for the guidance!
For the following markup:
<dl class="dl-horizontal">
<dt>A few words describing the term</dt>
<dd>The data associated with the term</dd>
</dl>
The dt term element is fixed width (at 180px) and cannot be changed with col- due to specificity of CSS. For example, the below does not work:
<dl class="dl-horizontal">
<dt class="col-sm-3">A few words describing the term</dt>
<dd class="col-sm-9">The data associated with the term</dd>
</dl>
Description lists are for name-value pairs and a fixed width is not suitable for some languages where the single word term is longer than 180px. Truncating is not possible (it truncates valuable meaning) and word-wrapping (using Stack Overflow overrides) is not readable.
Do I need to add extra classes or should I chase up with Twitter Bootstrap?
Edit
Given the lack of answers, I have opened an issue with bootstrap:
https://github.com/twbs/bootstrap/issues/14983
...you can always write overwrite code for the col-sm-3 and col-sm-9 classes (following the exact example), but I guess it would be easier to write your own classes using media queries and the same breakpoints you are using in your bootstrap file. You can also use this custom class to set a new minimum width.
#media (min-width:XXX) and (max-width:XXX) {
dt.col-sm-3 {
width:25%;
}
dt.col-sm-9 {
width:75%;
}
}
After the recent updates in Moqui I am facing a problem in rendering the FTL code using <render-mode> tag.
Let me try to explain the problem,
Earlier I have rendered the FTL code using <render-mode> in <form-list> tag it was working properly but when I took the update of Moqui, it is displaying the whole FTL code written in the tag on browser.
Also after the update of Moqui when I use the same code outside the <form-list>, it is working as expected.
Is this the desired behavior or we should do some changes at framework level.
Below is the sample code for the same.
<form-list name="demoName" list="nameList" >
<field name="name">
<default-field title="Name">
<render-mode>
<text><![CDATA[
<#if name=='Demo Name 1'>
<span class="label label-success">Demo Name 1</span>
<#elseif name=='Demo Name 2'>
<span class="label label-info">Demo Name 2</span>
</#if>
]]></text>
</render-mode>
</default-field>
</field>
</form-list>
This is how the code is being rendered on the screen at revision #891b4d5.
This was the output that we used to get in Moqui revision #983a9e1
Can we use render-mode in form-list the way we are using it in the above code snippet?
For proper usage of the render-mode.text element you should specify a text.#type attribute. It defaults to "all" so the text will be used for all types, but your content contains HTML so it should have text.#type=html.
Still, what you include should work fine. Here is an example from the apps.xml screen in the latest version of Moqui (in the git repo) that runs with every apps screen render and works with interpretation of the inline text as a template:
<render-mode><text type="html"><![CDATA[
<#assign footerItemList = sri.getThemeValues("STRT_FOOTER_ITEM")>
<div id="apps-footer-content">
<#list footerItemList! as footerItem>
${footerItem}
</#list>
</div>
]]></text></render-mode>
I saw in Expression Engine I can use {embed:title} and {site_name} variables, but now I need a variable to pull an excerpt or description of the article itself. Is there such a variable/tag?
ExpressionEngine tags are based solely on custom fields which you yourself have defined. So in the field group for your "articles" channel, you'll have some fields, maybe {article_summary}, {article_body}, {article_image}, etc. To display your summary, just use {article_summary} in your template.
I'm assuming that you're coming from something like WordPress maybe, where every piece of content has the_content() and the_excerpt() ... aside from a handful of global variables, and some fields which are universal to all entries (like {title}, {entry_date}, etc), ExpressionEngine isn't like that. You define what fields you use for each channel - you have complete control.
Here is the actual code you have to include in your EE template.
{exp:channel:entries channel="article" limit="5" dynamic="no"}
<div class="home_thumb">
<h1>{title}</h1>
<div class="home_thumb_img">
<img src="{article_image}">
{if article_content}
<p>{article_content}</p>
{/if}
</div>
</div>
{/exp:channel:entries}