atrium-impl-robstoll / ch.tutteli.atrium.reporting.translating / ResourceBundleBasedTranslator

ResourceBundleBasedTranslator

class ResourceBundleBasedTranslator : ArgumentsSupportingTranslator

Represents an ITranslator which reuses ResourceBundle properties based capabilities but uses an enhanced fallback mechanism. Instead of falling back to Locale.getDefault one is able to specify fallback Locale oneself. Whether this includes Locale.getDefault or not is up to the user.

Creating a ResourceBundleBasedTranslator is done via the static create methods. Here one has the possibility to specify the additional fallback Locales.

The translations are located in properties files structured per entity (enum, object or class). For instance, the translations for ch.tutteli.atrium.DescriptionAnyAssertion and the Locale de_CH are stored in a properties file named DescriptionAnyAssertion_de_CH.properties in the folder /ch/tutteli/atrium/.

An entry in such a file would look like as follows: TO_BE = a translation for TO_BE

Inherited Properties

primaryLocale

val primaryLocale: Locale

The Locale to which the translator translates per default as well as the Locale which will be used in java.lang.String.format, which in turn is used to substitute the placeholders in the resulting translation of ITranslatableWithArgs.translatable with the ITranslatableWithArgs.arguments.

Functions

translateWithoutArgs

fun translateWithoutArgs(translatable: ITranslatable): String

Do not call this method in case you want to translate a ITranslatableWithArgs use translate in this case.

Inherited Functions

translate

fun translate(translatable: ITranslatable): String

Returns the translation of the given translatable or its getDefault in case there is not a translation defined for it.

Companion Object Functions

create

fun create(primaryLocale: Locale, vararg fallbackLocales: Locale): ResourceBundleBasedTranslator

Creates a ResourceBundleBasedTranslator and aggregates it with a ResourceBundle.Control which either makes use of the given fallbackLocales if provided or uses only the given primaryLocale.