Translator

class Translator(settings: Settings, translationDir: String, map: HashMap<String, Translator.Text>? = null)

PolyTranslator

PolyTranslator is an i18n/l10n system used by PolyUI. It finds a language file according to the following spec:

/translationDir/lang_COUNTRY.lang

for example /translationDir/en_GB.lang.

This can also be set with -Dpolyui.locale="ll_CC" or using Settings.defaultLocale.

If the file cannot be found, PolyUI will check for a file named ll_default.lang (for example en_default.lang) and use that instead if present. If that isn't found, it will use the default locale (above), and if that isn't found it will crash.

Keys can also be added using

The file contains a simple table of my.key=value, with each line meaning a new translation. It will return the key if the file is found but the key is not present. We recommend using dot notation for your keys:

my.key=hello there!
hello.world=This works well!
something.else=I can also substitute in %s objects using %s!
really.useful=I use the sprintf(3) type format strings as specified by java.lang.String.format().

See also

Constructors

Link copied to clipboard
constructor(settings: Settings, translationDir: String, map: HashMap<String, Translator.Text>? = null)

Types

Link copied to clipboard
interface Text

Properties

Link copied to clipboard
@ApiStatus.Internal
var dontWarn: Boolean

Set to true to disable warnings when a translation is not found.

Functions

Link copied to clipboard
fun addDelegate(translationDir: String): Translator

add a delegate translator to this master translator.

Link copied to clipboard
fun addKey(key: String, value: String): Translator

Add a key to the translation table.

Link copied to clipboard
fun addKeys(vararg pairs: Pair<String, String>): Translator

Add a set of keys to the translation table. You can use the Kotlin map syntax here:

fun addKeys(keys: Map<out String, String>): Translator

Add a map of keys to the translation table.

Link copied to clipboard
@ApiStatus.Internal
fun loadKeys(resource: String, now: Boolean = false): Translator

Add a file to the translation table, which will be used to load keys.

Link copied to clipboard

set the locale of this translator. All the keys are cleared, and PolyUI is reloaded.

Link copied to clipboard

translate the provided key, returning the key as per the translation table.

fun translate(key: String, vararg args: Any?): Translator.Text.Formatted