-
Notifications
You must be signed in to change notification settings - Fork 25
Internationalization
The basic examples allow you to create most views that you would normally construct in Java (with a lot more code, by the way), but this is not everything that LML does. One of the additional features of LML, which might make you want to forget about creating Scene2D
UI any other way, is easier internationalization.
There is a LmlData
interface, which basically contains methods that return and set data needed to construct LML views. DefaultLmlData
(standard implementation) allows you to register - among others - I18NBundle
objects, which will be used for localized text. Basically, anywhere a value is being parsed (even if a String
is not the needed type), you can proceed it with @
and it will be extracted from a i18n bundle.
For example, given this bundle.properties
file:
label=Some content.
maybe=true
...this template:
<table>
<label expand=@maybe>@label</label>
</table>
...would be processed like this:
<table>
<label expand=true>Some content.</label>
</table>
This allows you not only to have your game fully localized with little effort, but also have different settings chosen based on the language. For example, you can extract some padding values from i18n bundle, with each language having unique paddings that work best with the lengths of text in this particular translation.
You can also easily register I18NBundle
while constructing your parser with:
Lml.parser().i18nBundle(I18NBundle.createBundle(Gdx.files.internal("bundle")))
// TODO Other parser settings.
.build();
Multiple bundles are supported. To access a particular i18n bundle that you registered, proceed bundle line key with its name and a dot. For example:
@thisWillBeExtractedFromDefaultBundle
@custom.thisWillBeExtractedFromBundleMappedToCustomKey
The second line, quite obviously, will look for "thisWillBeExtractedFromBundleMappedToCustomKey" in i18n bundle mapped to "custom".
You can also pass arguments to bundle lines. Arguments can even be i18n bundle lines themselves! (Or preferences, or methods). Given this default bundle:
key=This is {0} for {1}
arg=show
...this:
@key|only|@arg
...will be converted to: "This is only for show". Note that nesting i18n bundle lines with arguments as arguments for other lines is forbidden. This shouldn't be much of an issue anyway, as I don't imagine anyone would ever need to nest even simple bundle lines - but just be aware that it does work.
MJ 2016