Project

General

Profile

Actions

How to localize a program in Scol ?

Allow the translation of your application is often a good thing. Several ways exist, we will see one.

For an given application, we have a subdirectory with all language files :
myapp.english.lang
myapp.spanish.lang
myapp.italian.lang
myapp.french.lang
...

In a file language, we put a reference and its translation for each line :

REFERENCE_1 word_translated
REFERENCE_2 string translated
REFERENCE_3 substring_1 ## substring_2 ## substring_3
...

Each ## will be replaced by a provided parameter, if needed

Next, go to locked/lib directory et open loc.pkg in your favorite text editor.

- startloc is the function to load the language file for a given user.
- loc is the function for a simple translation.
- strloc loc are the functions for a translation with parameters

Example :

The package

First, we create our application "mylocapp". The file is named "mylocapp.pkg" in the "tutorials" directory :

fun main ()=
    _showconsole;

    /*
    load the language file to the given user

    startloc defines automatically the user language. 
    If no translation exist, english version will be used.
    */
    startloc "tutorials/lang/mylocapp";

    /*
    loc returns the content from a key, without parameter
    strloc loc returns the content from a key with parameters.
    Parameters are in a list, '##' will be replaced by them, in the same order
    */
    _fooS loc "WELCOME";
    _fooS strloc loc "HELLO" (_getress "DefaultName") :: nil;
    let localtime time -> [_ mn h _ _ _ _ _] in
    _fooS strloc loc "DATE" (itoa h) :: (itoa mn) :: nil;
    _fooS loc "BYE";

    0;;

Next, we create our files languages. For example, in english and in french

In english

The file is "mylocapp.english.lang", in "tutorials/lang/". Each '##' will be replaced by the provided parameters in the source code.

BYE Good bye !
DATE It is ## hours and ## minutes
HELLO Hi ## !
WELCOME Welcome on my application

In french

The file is "mylocapp.french.lang", in "tutorials/lang/".

BYE Au-revoir !
DATE Il est ## heures and ## minutes
HELLO Salut ## !
WELCOME Bienvenu sur mon application

The script

Finally, we write the launcher :


_load "locked/lib/loc.pkg" 
_load "tutorials/mylocapp.pkg" 
main

Note that add the loc.pkg at first !
Save all and launch the .scol.

This application is readable from the repository

License : CC-BY-SA-2.0
Tutorial by iri
Updated by /

Updated by iri about 12 years ago · 2 revisions