Page 1 of 1

[Mod] Localisation [1.1] [localisation]

PostPosted: Mon Oct 01, 2012 18:45
by Jonjeg
Here is my mod concerning the localisation of your mods.
This mod are just here pour help you to translate easily your text and names.
Features
This mod supports messages with inner parameters from 0 up to 9 placeholders.
The minetest settting 'language' is used for the choice of the language and is set by default to EN if absent from your minetest.conf.
This mod allows Patch Language for mods using this mod (see the readme for details).

License : LGPL -- http://www.gnu.org/licenses/lgpl-2.1.html
Download link http://github.com/Jonjeg/localisation/zipball/master
GitHub : https://github.com/Jonjeg/localisation
Dependancy : None

Exemple (from the README.txt):
Translations
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local translations = {
        EN = {
            message1 = "english version",
            message_with_parameter = "$1 will be replaced by the first additionnal parameter",
            message_existing_in_english_only = "lorem ipsum"
            ...etc
        },
        FR = {
            message1 = "version française"
            message_with_parameter = "$1 va être remplacé par la 1ère valeur additionnelle"
            message_with_some_parameters = "$1,$2,$3"
        }
    }

Registering the translations
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
    localisation.register_translations("your_mod_name",your_var_containing_translations)

Usage in your code
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
    localisation.translate("your_mod_name:message1") -> "english version" -- si language = EN
    localisation.translate("your_mod_name:message1") -> "version française" -- si language = FR
    localisation.translate("your_mod_name:message1") -> "english version" -- si language = other than FR
    localisation.translate("your_mod_name:message_existing_in_english_only") -> "lorem ipsum"
    localisation.translate("your_mod_name:message_with_parameter","value") -> "value will be replaced by the first additionnal parameter" -- si language = EN
    localisation.translate("your_mod_name:message_with_parameter","value") -> "value va être remplacé par la 1ère valeur additionnelle" -- si language = FR
    localisation.translate("your_mod_name:message_with_some_parameters","value",2,3.5) -> "value,2,3.5"
    localisation.translate("your_mod_name:message_inexistant","value",2,3.5) -> "Translate(EN,message_inexistant) = No translations available" -- si language = EN
    localisation.translate("bad_message_without_mod_name","value",2,3.5) -> "No mod_name specified or other error message"


The old version(1.0) got a flaw in the point that a needed a variable to store translations and that this variable would pollute the global environment for other mods.

PostPosted: Tue Oct 02, 2012 06:29
by cornernote
+1 this is a good idea, but can make mod development a little more tedious.

if anyone wants any of my mods to include this then I will be happy to do it, let the community demand, and it shall be given

PostPosted: Tue Oct 02, 2012 14:49
by GJH105775
This would be very useful. +1

PostPosted: Thu Oct 04, 2012 12:01
by Jonjeg
Here is an update of the mod with new features as global translations registration and language patching mods.