/
Internationalization / Localization

Internationalization / Localization

Content

 


How to use localization in your code


JEAF X-Fun provides a rather simple but powerful mechanism to localize all kinds of strings like messages, UI labels etc.

This mechanism is based on a resource where the actual messages in all localization are stored and a generated Java class with constants for all localized strings (so called message constants). Message constants will be generated by JEAF Generator, a simple Maven Plugin, that is integrated into your build process (also see section about JEAF Maven Plugins). As a resource for messages either plain XML files or Excel sheets can be used. Excel files will be transformed into XML files by JEAF Generator Maven Plugin to avoid dependencies on Excel libraries at runtime.



JEAF Generator will generate a Java class with message constants for every message resource. This class will have a constant for every message. Depending on the type of the message the constant will be of a different type.

JEAF knows the following types of messages:

  • LocalizedString can used used for any kind of text that should be localized such as labels for UI etc.

  • MessageID Any kind of message that should be also be traceable.

  • ErrorCode should be used in case of business or technical errors and can be used to provide error message e.g. as part of exceptions.

Message Constants generated by JEAF Generator

/** * Demo class for generation of message constants. * * @author JEAF Development Team * @version 1.5.x */ @MessageResource(path = "accounting-messages.xml") public final class AccountingMessages { /** * Localized text for user interface label showing transaction amount. */ public static final LocalizedString TX_AMOUNT_LABEL; /**