Project

General

Profile

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

iri, 09/25/2012 01:07 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
Next, go to _locked/lib_ directory et open _loc.pkg_ in your favorite text editor.
23
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
	startloc defines automatically the user language. If no translation exist, english version will be used.
42
	*/
43
	startloc "tutorials/lang/mylocapp";
44
	
45
	/*
46
	loc returns the content from a key, without parameter
47
	strloc loc returns the content from a key with parameters. Parameters are in a list, '##' will be replaced by them, in the same order
48
	*/
49
	_fooS loc "WELCOME";
50
	_fooS strloc loc "HELLO" (_getress "DefaultName") :: nil;
51
	let localtime time -> [_ mn h _ _ _ _ _] in
52
	_fooS strloc loc "DATE" (itoa h) :: (itoa mn) :: nil;
53
	_fooS loc "BYE";
54
	
55
	0;;
56
</pre>
57
	
58
Next, we create our files languages. For example, in english and in french
59
60
h3. In english
61
62
The file is "mylocapp.english.lang", in "tutorials/lang/". Each '##' will be replaced by the provided parameters in the source code.
63
64
<pre>
65
BYE Good bye !
66
DATE It is ## hours and ## minutes
67
HELLO Hi ## !
68
WELCOME Welcome on my application
69
</pre>
70
71
h3. In french
72
73
The file is "mylocapp.french.lang", in "tutorials/lang/".
74
75
<pre>
76
BYE Au-revoir !
77
DATE Il est ## heures and ## minutes
78
HELLO Salut ## !
79
WELCOME Bienvenu sur mon application
80
</pre>
81
82
h3. The script
83
84
Finally, we write the launcher :
85
<pre>
86
87
_load "locked/lib/loc.pkg"
88
_load "tutorials/mylocapp.pkg"
89
main
90
</pre>
91
92
Note that add the loc.pkg at first !
93
Save all and launch the .scol.
94
95
This application is readable from the "repository":http://redmine.scolring.org/projects/tutorials/repository/show/localization
96
97
98
License : "CC-BY-SA-2.0":https://creativecommons.org/licenses/by-sa/2.0/
99
Tutorial by iri
100
Updated by /