i18n - becoming multilingual

Supporting different languages can be very important. This framework offers an easy way to use i18n using the TextManager. This manager is directly accessible in your controller code using the getTextManager method. When instantiated for the first time the TextManager will load the language properties file based on the locale with the name application_language_{locale}.properties. For any language you need to implement just make sure you have the corresponding file in your classpath. When developing with jZonic the easiest way is to place these files in the ect subdirectory. They will be deployed automatically to right location.

Example

The first example will show how to use the TextManager in your controller. Here is a short snippet:

public void login() {
 .... // some logic that fails
  getFlash().add("error",getTextManager()..getText("error.no_permission"));
}

It will get the property called error.no_permission. If the property is not found it will instead return an error message.

i18n in your templates

The TextManager is automatically added to the velocity context and therefore directly available as $tm in your templates. You can do something like:

<html>
<body>
<h1>$tm.getText("page.header")</h1>
</body>
</html>

Again make sure that you have a property called page.header in your language properties files.

Page: UsingInternationalisation last edited by admin on 03/24/2009 22:02 revision: 1
Labels:  (none)    Permalink