Project

General

Profile

How to localize a program in Scol » History » Version 2

iri, 09/25/2012 01:08 AM

1 1 iri
h1. How to localize a program in Scol ?
2
3
Allow the translation of your application is often a good thing. Several ways exist, we will see one.
4
5
For an given application, we have a subdirectory with all language files :
6
myapp.english.lang
7
myapp.spanish.lang
8
myapp.italian.lang
9
myapp.french.lang
10
...
11
12
In a file language, we put a reference and its translation for each line :
13
<pre>
14
REFERENCE_1 word_translated
15
REFERENCE_2 string translated
16
REFERENCE_3 substring_1 ## substring_2 ## substring_3
17
...
18
</pre>
19
20
Each ## will be replaced by a provided parameter, if needed
21
22 2 iri
Next, go to *locked/lib* directory et open *loc.pkg* in your favorite text editor.
23 1 iri
24
- *startloc* is the function to load the language file for a given user.
25
- *loc* is the function for a simple translation.
26
- *strloc* loc are the functions for a translation with parameters
27
28
h2. Example :
29
30
h3. The package
31
32
First, we create our application "mylocapp". The file is named "mylocapp.pkg" in the "tutorials" directory :
33
34
<pre>
35
fun main ()=
36
	_showconsole;
37
	
38
	/*
39
	load the language file to the given user
40
	
41 2 iri
	startloc defines automatically the user language. 
42
    If no translation exist, english version will be used.
43 1 iri
	*/
44
	startloc "tutorials/lang/mylocapp";
45
	
46
	/*
47
	loc returns the content from a key, without parameter
48 2 iri
	strloc loc returns the content from a key with parameters.
49
    Parameters are in a list, '##' will be replaced by them, in the same order
50 1 iri
	*/
51
	_fooS loc "WELCOME";
52
	_fooS strloc loc "HELLO" (_getress "DefaultName") :: nil;
53
	let localtime time -> [_ mn h _ _ _ _ _] in
54
	_fooS strloc loc "DATE" (itoa h) :: (itoa mn) :: nil;
55
	_fooS loc "BYE";
56
	
57
	0;;
58
</pre>
59
	
60
Next, we create our files languages. For example, in english and in french
61
62
h3. In english
63
64
The file is "mylocapp.english.lang", in "tutorials/lang/". Each '##' will be replaced by the provided parameters in the source code.
65
66
<pre>
67
BYE Good bye !
68
DATE It is ## hours and ## minutes
69
HELLO Hi ## !
70
WELCOME Welcome on my application
71
</pre>
72
73
h3. In french
74
75
The file is "mylocapp.french.lang", in "tutorials/lang/".
76
77
<pre>
78
BYE Au-revoir !
79
DATE Il est ## heures and ## minutes
80
HELLO Salut ## !
81
WELCOME Bienvenu sur mon application
82
</pre>
83
84
h3. The script
85
86
Finally, we write the launcher :
87
<pre>
88
89
_load "locked/lib/loc.pkg"
90
_load "tutorials/mylocapp.pkg"
91
main
92
</pre>
93
94
Note that add the loc.pkg at first !
95
Save all and launch the .scol.
96
97
This application is readable from the "repository":http://redmine.scolring.org/projects/tutorials/repository/show/localization
98
99
100
License : "CC-BY-SA-2.0":https://creativecommons.org/licenses/by-sa/2.0/
101
Tutorial by iri
102
Updated by /