This sample shows the use of Google Web Toolkit's internationalization classes. In a truly internationalized application, all strings (including this one) and styles (including the CSS used to style this page), would also be internationalized. Although English is the default language for this sample, it is also localized for French. Append locale=fr to the query string to view the French version.
Class NumberFormat
supports locale-sensitive formatting and parsing of numbers using a flexible pattern-based syntax.
In addition to custom patterns, several standard patterns are also available for convenience.
See the GWT class reference for details of the pattern syntax.
Class DateTimeFormat
supports locale-sensitive formatting and parsing of date and time values, like NumberFormat
, using a flexible pattern-based syntax.
Both custom patterns and standard patterns are supported.
See the GWT class reference for details of the pattern syntax.
Interface Constants
makes it possible to localize strings, numbers, and maps of strings onto strings.
This example isn't terribly exciting, but it does demonstrate how to localize constants.
The labels and colors choices below are provided by the localized implementation of the sample interface ConstantsExampleConstants
, defined as follows:
public interface ConstantsExampleConstants extends Constants { Map colorMap(); String favoriteColor(); String firstName(); String lastName(); }
Interface ConstantsWithLookup
makes it possible to dynamically look up localized values using method names as string keys.
This example interacts with the sample interface Colors
, defined as follows:
public interface ColorConstants extends ConstantsWithLookup { String black(); String blue(); String green(); String grey(); String lightGrey(); String red(); String white(); String yellow(); }
Using the Dictionary
class, you can lookup localized values within JavaScript objects defined in the host HTML page rather than compiling them into your GWT code.
This is useful if your translations change frequently, because your HTML server can emit updated translations into the host page HTML as often as needed.
It can also a useful way to integrate a GWT module with existing localized web applications.
Note that a dictionary's values depend only on the host page HTML and are not influenced by the GWT locale
client property.
For this example, the JavaScript variable declaration appears in the source for this HTML page. It looks like this:
var userInfo = { name: "Amelie Crutcher", timeZone: "EST", userID: "123", lastLogOn: "2/2/2006" };