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
interface TranslationService {
String translate(TranslationContext context, String text) (1)
String translate(TranslationContext context, String singularText, String pluralText, int num) (2)
Mode getMode() (3)
TranslationService identity() (4)
}
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 |
3 | getMode()
Whether this implementation is operating in read or in write mode. |
4 | identity()
Can be used as fallback in the absence of a TranslationService implementation. Acts as a text pass-through, not translating anything. |
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..
identity()
Can be used as fallback in the absence of a TranslationService implementation. Acts as a text pass-through, not translating anything.
Implementation
The Core Runtime Services module provides a default implementation, TranslationServicePo.
It 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.
Related Services
-
enumerates the mode that the translation service is currently in, as per getMode().
-
Used by the default implementation (
TranslationServicePo
) to return theLocale
of the current user. -
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.