Package de.uni_trier.wi2.procake.utils.multilanguage

CAKE Multilanguage Support

CAKE supports an unified method to translate all kinds of system message. All system messages are identified by a component name, a component key, and the classloader whose object wants to translate a message.

Translation Files

The translation files are loaded from the classpath and must be located in the directory MessageFormatter.DEFAULT_RESOURCE_PREFIX. This default location can be changed by a factory implementations. But the factory implementations should use the this path as default.

The translation files are loaded as resource bundles using ResourceBundle. Resource bundles contain locale-specific objects. They belong to families whose members share a common base name (the component name in CAKE), but whose names also have additional components that identify their locales. For example, the base name of de.uni_trier.wi2.procake.data.model is "datamodel" (see LogComponentIdentifier.COMPONENT). The datamodel should have a default resource bundle which simply has the same name as its family - "datamodel" - and will be used as the bundle of last resort if a specific locale is not supported. The family can then provide as many locale-specific members as needed, for example a German one named "datamodel_de".

Each resource bundle in a family contains the same keys, but the keys have been translated for the locale represented by that resource bundle. For example, both "datamodel" and "datamodel_de" have a String that's used to indicate that a class is not editable (see @link DataClass#LOG_CLASS_NOT_EDITABLE}). In "dataclass" the String contains "Class is not editable" and in "dataclass_de" it may contain "Klasse kann nicht editiert werden".

If there are different resources for different countries, you can make specializations: for example, "dataclass_de_CH" contains objects for the German language (de) in Switzerland (CH). If you want to only modify some of the resources in the specialization, you can do so.

The locale can be changed with MessageFormatter.setLocale(Locale). The default is the system locale.

LogComponentIdentifier

To identify each component and each key it is important that the component-key pair is unique. This is realised with special interfaces that are located in each package that wants to log. These interfaces are always named LogComponentIdentifer. This interface always contains the following information:

  • The name of the component, stored in the constant COMPONENT
  • For each class that logs a message the interface provides a constant with a prefix for the log key. This prefix must be used by a class to create unique keys, in general, the the prefix is appended by two further digits.

Message Formating

A detailed description of the message formating technique can be found in MessageFormatter