Class Translator
-
- All Implemented Interfaces:
public final class TranslatorPolyTranslator is an i18n/l10n system used by PolyUI. It finds a language file according to the following spec:
/translationDir/lang_COUNTRY.langfor 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 exampleen_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
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 {0} objects using {1}!
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classTranslator.TextInternal representation of a string in PolyUI.
The string can be translated if there is an attached Translator to this instance and the key is present in the file.
-
Constructor Summary
Constructors Constructor Description Translator(PolyUI polyUI, String translationDir)
-
Method Summary
Modifier and Type Method Description final BooleangetDontWarn()Set to true to disable warnings when a translation is not found. final UnitsetDontWarn(@ApiStatus.Internal() Boolean dontWarn)Set to true to disable warnings when a translation is not found. final UnitsetLocale(String locale)set the locale of this translator. final UnitloadKeys(String resource, Boolean now)Add a file to the translation table, which will be used to load keys. final UnitaddKeys(Map<out String, String> keys)Add a map of keys to the translation table. final UnitaddKeys(Pair<String, String> pairs)Add a set of keys to the translation table. final UnitaddKey(String key, String value)Add a key to the translation table. final Stringtranslate(Translator.Text text)translate the provided key, returning the key as per the translation table. final static Translator.Textlocalised(String $self, Object objects)Use {idx} in the key for the object substitution -
-
Method Detail
-
getDontWarn
final Boolean getDontWarn()
Set to true to disable warnings when a translation is not found.
-
setDontWarn
final Unit setDontWarn(@ApiStatus.Internal() Boolean dontWarn)
Set to true to disable warnings when a translation is not found.
-
setLocale
final Unit setLocale(String locale)
set the locale of this translator. All the keys are cleared, and PolyUI is reloaded.
-
loadKeys
final Unit loadKeys(String resource, Boolean now)
Add a file to the translation table, which will be used to load keys.
Unless now is
true, the file will only be loaded if the key is not found in the existing table.
-
addKeys
final Unit addKeys(Map<out String, String> keys)
Add a map of keys to the translation table.
-
addKeys
final Unit addKeys(Pair<String, String> pairs)
Add a set of keys to the translation table. You can use the Kotlin map syntax here:
addKeys( "my.key" to "hello there!", "hello.world" to "This works well!", )
-
translate
final String translate(Translator.Text text)
translate the provided key, returning the key as per the translation table.
If the key is not present in the table, then the resourcePath file is checked for the key. The value is then returned. Warnings will be issued if the file/key does not exist.
-
localised
final static Translator.Text localised(String $self, Object objects)
Use {idx} in the key for the object substitution
-
-
-
-