Brief introduction
Wikipedia defines internationalization as the ability to adapt software applications to a variety of languages and regions without having to make engineering changes. (see Resources). According to this definition, in order to get internationalized software, there are three elements essential:
An element responsible for informing the software of the local locale to which it is running
A set of translation files that can be applied to the software's current local locale
One component responsible for connecting the first two elements
In this article, we'll create a simple internationalized WEB application and showcase the Dojo Toolkit standards for the first two elements (more about dojo, see Resources). After that, we'll examine two Dojo use cases: HTML files or widgets for the third element.
Setting up a local locale within a Dojo-based application
The local locale is a parameter that defines the language that the application user interface should use. Sometimes, just specifying a language may not be enough. It is possible for different countries to use almost the same language, there are only a few nuances, such as a different spelling (for example, "center" in the American language, "centre" in English), and a different word for the same meaning (for example, "Elevator" in American English, and " Lift "). Therefore, local locale parameters include the country code in addition to the language code, which specifies the specific language that should be used.
Dojo provides two mechanisms for specifying a WEB application's local locale. The first is programmatically (at runtime or at design time), and the other is set by the browser's default local locale (defined during browser installation).
Programmatically setting the local locale is actually specifying the value of the "locale" attribute within the global object Djconfig. The example in Listing 1 shows how to set the local locale to en-us at design time:
Listing 1: Setting up a local locale at design time using a programmatic approach
<script type="text/javascript" SRC="dojo.js" djConfig="locale:'en-us'"></script>
Another possibility is to programmatically compute the local locale (for example, by extracting from a URL) and then setting the local locale. The example in Listing 2 shows how to set up a local locale programmatically at run time:
Listing 2: Setting up a local locale at run time using a programmatic approach
<script type="text/javascript">
// Note: this must be done before dojo loads!!!
var djConfig = new Object();
var theLocale = getLocale(); // this function is responsible to determine
// the appropriate locale
djConfig.locale = theLocale;
function getLocale()
{
return “en-us”;
}
</script>
The last possibility is to not specify the locale, but rather to use the browser's default locale, which is extracted by Dojo from the navigation object. The default behavior, like any default setting, is useful when you can anticipate the client's browser and machine configuration. This is rarely the case, but it is more common for browsers to use non-native language installations or language installations that are unfamiliar to the application (so you should avoid this approach).