Dashboard > RIFE > ... > Templates > Localization through ResourceBundles > Information > Page Comparison
RIFE Log In   View a printable version of the current page.
Localization through ResourceBundles


Version 5 by Geert Bevin
on Jul 06, 2004 21:31.


compared with
Current by Emmanuel Okyere II
on Nov 07, 2005 21:45.

(show comment)
 
Key
These lines were removed. This word was removed.
These lines were added. This word was added.

View page history


There are 1 changes. View first change.

   
  
  {anchor:top}
 It's possible to easily localize templates through the standard {{ResourceBundle}} mechanism that's available in Java. The strings that are localized are automatically filtered and replaced values tags, just as for config value replacement. The format for localized values is:
  
 {code:xml}
 <!--V 'L10N:key'-->default value<!--/V-->
 {code}
  
 Of course, before replacement, the template instance has to know where to look for the key. An additional {{setResourceBundle(ResourceBundle bundle)}} method has been added to the {{Template}} class, just for this purpose.
  
 For example, consider the following resource bundles:
  
 h4. text_nl.properties
 {noformat}
 hello = Hallo
 {noformat}
  
 h4. text_fr.properties
 {noformat}
 hello = Bonjour
 {noformat}
  
 and a template
 h4. text.html
 {code:xml}
 Hey mister, I said: "<!--V 'L10N:hello'/-->!"
 {code}
  
 The following Java code:
  
 {code:java}
 Template template_html = TemplateFactory.HTML.get("text");
 ResourceBundle bundle = Localization.getResourceBundle("text", "fr");
 template_html.addResourceBundle(bundle);
 System.out.println(template.getContent());
 {code}
  
 will output:
  
 {noformat}Hey mister, I said: "Bonjour!"{noformat}
  
 and just replacing the second line with the following:
  
 {code:java}
 ...
 ResourceBundle bundle = Localization.getResourceBundle("text", "nl");
 ...
 {code}
  
 will output:
  
 {noformat}Hey mister, I said: "Hallo!"{noformat}
  
 The examples use the convenience class {{Localization}} that's available in {{com.uwyn.rife.tools}}, but any other means of obtaining a {{ResourceBundle}} can be used. The advantage of the Localization class is that it closely integrates with RIFE's configuration and it thus picks up the default settings for the resource bundle basename, language and country if they haven't been specified through method arguments. The corresponding configuration parameter names are:
  
 {noformat}
 L10N_DEFAULT_RESOURCEBUNDLE
 L10N_DEFAULT_LANGUAGE
 L10N_DEFAULT_COUNTRY
 {noformat}
  
 So consider the following configuration setup:
  
 {code:xml}
 <param name="L10N_DEFAULT_RESOURCEBUNDLE">myapplication</param>
 <param name="L10N_DEFAULT_LANGUAGE">nl</param>
 {code}
  
 Java code is then able to just write the following line to obtain the ResourceBundle:
  
 {code:java}
 ...
 ResourceBundle bundle = Localization.getResourceBundle();
 ...
 {code}
  
 This makes it extremely easily to ship a localized application and allow the users to set up a fixed language beforehand, while still allowing a lot of flexibility to allow dynamic localization behaviour.


Are you enjoying Confluence? Please consider purchasing it today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.1a Build:#515 May 19, 2006) - Bug/feature request - Contact Administrators