Documentation of 'tig.TigBundle' Java class
TigBundle
tig

Class TigBundle

  • All Implemented Interfaces:
    GeneralConstants


    public class TigBundle
    extends java.lang.Object
    implements GeneralConstants
    This class can be used instead of ResourceBundle. It has been written for these reasons :
  • Permit to choose the place where the file containing the bundle (in general a '.properties') is stored ;
  • Put the Strings of different languages in a same file.
  • Avoid having Exceptions thrown when a key can't be found (the getString(String) method returns a empty string if a key can't be found in the bundle).
  • Usage

  • As with the standard API, you put your internationalized strings in bundle files (which don't have to be suffixed by '.properties'). The difference is that all the strings related to the same display are located in the same file.
  • You fill the bundle files with the standard syntax ("key = value")
  • Like in the standard mechanism, languages, countries and variants are handled.
  • The language and the locale are identified by the suffixes of the key ; the syntax is :
    myKey_country_locale_variant (ex : myKey_en_US).


  • The constructors of TigBundle only store the necessary strings (corresponding to the Locale specified in the constructor).

  • WARNING : this implementation does NOT permit to have underscores ( _ )in the names of the keys.
    Example : if you internationalize with French and English, you can have in your file :
    myKey_en = myEnglishValue
    myKey_fr = myFrenchValue
    
    But the following example is not valid, because of underscores :
    my_Key_en = myEnglishValue
    my_Key_fr = myFrenchValue
    
  • Typical usage :
    TigBundle myBundle = new TigBundle("C:\\data\\MyBundle.properties", new Locale("en", "US"));
    String str = myBundle.getString("myKey");
    
  • Alternative usage :
    In the main constructor (TigBundle(String, Locale)), a java.io.IOException is thrown if the resource file can't be loaded. An other constructor is provided to be able to load "manually" the bundle : (TigBundle(Properties, Locale)).
    Properties p = new Properties();
    p.setProperty("myKey_fr", "myFrenchValue");
    p.setProperty("myKey", "myEnglishValue");
    TigBundle myBundle = new TigBundle(p, new Locale("en", "US"));
    String str = myBundle.getString("myKey");
    
  • In this alternative usage

    Retrieval mechanism

    When getString("myKey") is called, it tries to find, in this order :
  • "myKey_country_locale_variant"
  • "myKey_country_locale"
  • "myKey_country"
  • "myKey"

  • If nothing is found, it returns a empty string.

    This permits to avoid repeating strings shared by several language, and have default values :
    Imagine you handle Spanish, French and English, and that the word "OK" should be expressed by "OK" in French and English, and "Oke" in spanish. You would put in the bundle :
    OK_sp = Oke
    OK    = OK
    
Parameters:
key - The key corresponding to the String to retrieve.
Skip navigation links

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.