www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Internationalization code generator

reply Ecstatic Coder <ecstatic.coder gmail.com> writes:
For those interested, I've open-sourced my localization code 
generator here :

https://github.com/senselogic/LINGUI

It converts human-readable translation scripts into compilable 


For instance, this script :

     Game
         New_game
         Welcome first_name last_name
         Pears count

     English : Game
         New_game
             "New game"

         Welcome first_name last_name
             "Welcome, "
             first_name
             " "
             last_name
             "!"

         Pears count
             *count
             " "
             if  count = one
                 "pear"
             else
                 "pears"

     German : Game
         New_game
             "Neues Spiel"

         Welcome first_name last_name
             "Willkommen, "
             first_name
             " "
             last_name
             "!"

         Pears count
             *count
             " "
             if  count = one
                 "Birne"
             else
                 "Birnen"

     French : Game
         New_game
             "Nouveau jeu"

         Welcome first_name last_name
             "Bienvenue, "
             first_name
             " "
             last_name
             " !"

         Pears count
             *count
             " "
             if  count = one
                 "poire"
             else
                 "poires"

Can be used this way :

     // -- IMPORTS

     import std.stdio : writeln;
     import ENGLISH_LANGUAGE_MODULE;
     import FRENCH_LANGUAGE_MODULE;
     import GAME_LANGUAGE_MODULE;
     import GERMAN_LANGUAGE_MODULE;
     import TRANSLATION_MODULE;

     // -- FUNCTIONS

     void Test(
         GAME_LANGUAGE game_language
         )
     {
         writeln( game_language.New_game() );
         writeln( game_language.Welcome( TRANSLATION( "Jack" ), 
TRANSLATION( "Sparrow" ) ) );
         writeln( game_language.Pears( TRANSLATION( 0 ) ) );
         writeln( game_language.Pears( TRANSLATION( 1 ) ) );
         writeln( game_language.Pears( TRANSLATION( 2 ) ) );
     }

     // ~~

     void main(
         string[] argument_array
         )
     {
         Test( new ENGLISH_LANGUAGE() );
         Test( new GERMAN_LANGUAGE() );
         Test( new FRENCH_LANGUAGE() );
     }

Which will thus print :

     New game
     Welcome, Jack Sparrow!
     0 pears
     1 pear
     2 pears
     Neues Spiel
     Willkommen, Jack Sparrow!
     0 Birnen
     1 Birne
     2 Birnen
     Nouveau jeu
     Bienvenue, Jack Sparrow !
     0 poire
     1 poire
     2 poires

I know there are other ways to do this, but for Unity games this 
was what best matched my needs, especially performance-wise...
May 31 2018
parent Niels Vilsk <niels.vilsk gmail.com> writes:
Nice job!
May 31 2018