TranslationService

Provides translated versions of the various elements within the framework’s metamodel: service and object classes, properties, collections, actions, action parameters; and also to translate business rule (disable/valid) messages, and exceptions. These translations provide for both singular and plural forms.

As such, this domain service is the cornerstone of the framework’s i18n support.

API

TranslationService.java
interface TranslationService {
  String translate(TranslationContext context, String text)     (1)
  String translate(TranslationContext context, String singularText, String pluralText, int num)     (2)
  Mode getMode()     (3)
}
1 translate(TranslationContext, String)

Return a translation of the text, in the locale of the "current user".

2 translate(TranslationContext, String, String, int)

Return a translation of either the singular or the plural text, dependent on the num parameter, in the locale of the "current user".

3 getMode()

Whether this implementation is operating in read or in write mode.

Members

translate(TranslationContext, String)

Return a translation of the text, in the locale of the "current user".

The mechanism to determine the locale is implementation-specific.

translate(TranslationContext, String, String, int)

Return a translation of either the singular or the plural text, dependent on the num parameter, in the locale of the "current user".

The mechanism to determine the locale is implementation-specific.

getMode()

Whether this implementation is operating in read or in write mode.

If in read mode, then the translations are expected to be present. In such cases, the #translate(TranslationContext, String) translate #translate(TranslationContext, String, String, int) method s should be lazily called, if only because there will (most likely) need to be a session in progress (such that the locale of the current user can be determined).

If in write mode, then the implementation is saving translation keys, and will always return the untranslated translation. In such cases, the #translate(TranslationContext, String) translate #translate(TranslationContext, String, String, int) method s should be eagerly called such that all pathways are exercised..

Implementation

The Apache Causeway framework provides a default implementation (o.a.c.core.runtimeservices.i18n.po.TranslationServicePo) that uses the GNU .pot and .po files for translations.

Usage Notes

For the "big picture" and further details on the framework’s support, see here.

  • Mode

    enumerates the mode that the translation service is currently in, as per getMode().

  • LanguageProvider

    Used by the default implementation (TranslationServicePo) to return the Locale of the current user.

  • TranslationsResolver

    Used by the default implementation (TranslationServicePo) to read existing translations.

  • The framework also provides a supporting TranslationServicePoMenu provides menu items under the "Prototyping" secondary menu for controlling this service and downloading .pot files for translation.

    If the menu items are not required then these can be suppressed either using security or by implementing a vetoing subscriber.

    For more details on the implementation, see i18n support.