Internationalizing Strings in Java and JSP Code
The com.day.cq.i18n Java package enables you to display localized strings in your UI. The I18n class provides the get method that retrieves localized strings from the AEM dictionary. The only required parameter of the get method is the string literal in the English language. English is the default langauge for the UI. The following example localizes the word Search :
Identifying the string in the English language differs from typical internationalization frameworks where an ID identifies a string and is used to reference the string at runtime. Using the English string literal provides the following benefits:
1. Code is easy to understand.
2. The string in the default language is always available.
Determining the User's Language
There are two ways to determine the language that the user prefers:
1. For authenticated users, determine the language from the preferences in the user account.
2. The locale of the requested page.
The language property of the user account is the preferred method because it is more reliable. However, the user must be logged in to use this method.