Localization system (allow change locale on-the-fly)

About Monkey 2 Forums Monkey 2 Code Library Localization system (allow change locale on-the-fly)

This topic contains 4 replies, has 3 voices, and was last updated by  Diffrenzy 10 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #15288


    Hi everyone.

    Some time ago I published localization system on github: https://github.com/engor/m2-localization

    It is easy to use lightweight system that allow you to keep all texts localized on-the-fly.

    Supported formats – json and ini. And you can add own format via registering loaders.

    There are few demos on github that describe different usecases.

    I just pushed some improvements.


    • All binded texts will be localized on-the-fly when locale will be changed;
    • You can register any format loader, android-strings for example via extending LocLoader class;
    • You can bring localization support into any classes via adding just one method Localize( t:String ), and you can do it via extension – so you needn’t to extend classes, and you can add this method even into Final classes! Note: extension way works with latest develop branch of monkey2, so will work out of the box starting from next release.
    • Lightweight and easy to use – there are polymorphic Localized function out of the box with different types that register you elements to be localized;
    • You can override any custom constant in realtime – load texts from file and replace any value(s) for given lang and given key.

    Example of file with translations (json format):

    Usage in code:

    For more complex examples look at demo projects on github.

    Support is welcome. 🙂






    Do you have a suggestion as how to implement randomized texts?

    In my own module I do:

    _multitexts = New StringMap<StringStack>

    Local key:= “btn_ok”
    _multitexts.Add(key,New StringStack)
    _multitexts.Get(key).Add(“Will Do”)

    and then the module looks to see if there is a multitext map, and if so picks  random entry. before looking in the regular StringMap

    In the language file, I’d like to avoid having key-01,key-02,key-03 naming, so that I kan just edit without thinking to much.

    Would it be possible to allow, button-remove = Remove;Get rid of, Kill, Die!; syntax or similar, and then somefunction to get Random text, or  is such functions beyond the scope of your module?



    I just pushed improvements to github.

    Look at new demo-multivalue.monkey2.

    Now we can register custom value-providers to override behaviour.

    As far as there is Null value for String type is empty string and empty string can be valid value,

    I created a bit monstrouse function defenition with Bool Ptr (omg!) to have two return values.

    if such provider func set eaten=True then we get/found actual value and must return it even if it’s an empty string.


    For example, we want to censoring all texts by keys, for example by key “java”. 🙂

    Now all keys containing word “java” will return “[censored]” string.



    That is absolutely brilliant! Thank you very much. 🙂

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.