add localization gateway
[scilab.git] / scilab / modules / localization / src / setgetlanguage.c
1 /*-----------------------------------------------------------------------------------*/\r
2 /* INRIA 2007 */\r
3 /* Allan CORNET */\r
4 /*-----------------------------------------------------------------------------------*/ \r
5 #include <string.h>\r
6 #include "setgetlanguage.h"\r
7 #include "MALLOC.h"\r
8 /*-----------------------------------------------------------------------------------*/ \r
9 #define LengthAlpha2code 3\r
10 typedef struct languages_struct \r
11 {\r
12         int code;\r
13         char alpha2code[LengthAlpha2code];\r
14         char languagename[96];      /** its name **/\r
15 } LanguagesTable;\r
16 /*-----------------------------------------------------------------------------------*/ \r
17 #define NumberLanguages 204\r
18 static LanguagesTable TabLanguages[NumberLanguages]=\r
19 /**\r
20 *  ISO 639-1 Code\r
21 *   http://www.loc.gov/standards/iso639-2/php/code_list.php \r
22 */\r
23 {\r
24         {  1,   "aa",   "Afar"},\r
25         {  2,   "ab",   "Abkhazian"},\r
26         {  3,   "af",   "Afrikaans"},\r
27         {  4,   "ak",   "Akan"},\r
28         {  5,   "sq",   "Albanian"},\r
29         {  6,   "am",   "Amharic"},\r
30         {  7,   "ar",   "Arabic"},\r
31         {  8,   "an",   "Aragonese"},\r
32         {  9,   "hy",   "Armenian"},\r
33         { 10,   "as",   "Assamese"},\r
34         { 11,   "av",   "Avaric"},\r
35         { 12,   "ae",   "Avestan"},\r
36         { 13,   "ay",   "Aymara"},\r
37         { 14,   "az",   "Azerbaijani"},\r
38         { 15,   "ba",   "Bashkir"},\r
39         { 16,   "bm",   "Bambara"},\r
40         { 17,   "eu",   "Basque"},\r
41         { 18,   "be",   "Belarusian"},\r
42         { 19,   "bn",   "Bengali"},\r
43         { 20,   "bh",   "Bihari"},\r
44         { 21,   "bi",   "Bislama"},\r
45         { 22,   "bo",   "Tibetan"},\r
46         { 23,   "bs",   "Bosnian"},\r
47         { 24,   "br",   "Breton"},\r
48         { 25,   "bg",   "Bulgarian"},\r
49         { 26,   "my",   "Burmese"},\r
50         { 27,   "ca",   "Catalan; Valencian"},\r
51         { 28,   "cs",   "Czech"},\r
52         { 29,   "ch",   "Chamorro"},\r
53         { 30,   "ce",   "Chechen"},\r
54         { 31,   "zh",   "Chinese"},\r
55         { 32,   "cu",   "Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic"},\r
56         { 33,   "cv",   "Chuvash"},\r
57         { 34,   "kw",   "Cornish"},\r
58         { 35,   "co",   "Corsican"},\r
59         { 36,   "cr",   "Cree"},\r
60         { 37,   "cy",   "Welsh"},\r
61         { 38,   "cs",   "Czech"},\r
62         { 39,   "da",   "Danish"},\r
63         { 40,   "de",   "German"},\r
64         { 41,   "dv",   "Divehi; Dhivehi; Maldivian"},\r
65         { 42,   "nl",   "Dutch; Flemish"},\r
66         { 43,   "dz",   "Dzongkha"},\r
67         { 44,   "el",   "Greek, Modern (1453-)"},\r
68         { 45,   "en",   "English"},\r
69         { 46,   "eo",   "Esperanto"},\r
70         { 47,   "et",   "Estonian "},\r
71         { 48,   "eu",   "Basque"},\r
72         { 49,   "ee",   "Ewe"},\r
73         { 50,   "fo",   "Faroese"},\r
74         { 51,   "fa",   "Persian"},\r
75         { 52,   "fj",   "Fijian"},\r
76         { 53,   "fi",   "Finnish"},\r
77         { 54,   "fr",   "French"},\r
78         { 55,   "fy",   "Western Frisian"},\r
79         { 56,   "ff",   "Fulah"},\r
80         { 57,   "ka",   "Georgian"},\r
81         { 58,   "de",   "German"},\r
82         { 59,   "gd",   "Gaelic; Scottish Gaelic"},\r
83         { 60,   "ga",   "Irish"},\r
84         { 61,   "gl",   "Galician"},\r
85         { 62,   "gv",   "Manx"},\r
86         { 63,   "el",   "Greek, Modern (1453-)"},\r
87         { 64,   "gn",   "Guarani"},\r
88         { 65,   "gu",   "Gujarati"},\r
89         { 66,   "ht",   "Haitian; Haitian Creole"},\r
90         { 67,   "ha",   "Hausa"},\r
91         { 68,   "he",   "Hebrew"},\r
92         { 69,   "hz",   "Herero"},\r
93         { 70,   "hi",   "Hindi"},\r
94         { 71,   "ho",   "Hiri Motu"},\r
95         { 72,   "hr",   "Croatian"},\r
96         { 73,   "hu",   "Hungarian"},\r
97         { 74,   "hy",   "Armenian"},\r
98         { 75,   "ig",   "Igbo"},\r
99         { 76,   "is",   "Icelandic"},\r
100         { 77,   "io",   "Ido"},\r
101         { 78,   "ii",   "Sichuan Yi"},\r
102         { 79,   "iu",   "Inuktitut"},\r
103         { 80,   "ie",   "Interlingue"},\r
104         { 81,   "ia",   "Interlingua (International Auxiliary Language Association)"},\r
105         { 82,   "id",   "Indonesian"},\r
106         { 83,   "ik",   "Inupiaq"},\r
107         { 84,   "is",   "Icelandic"},\r
108         { 85,   "it",   "Italian"},\r
109         { 86,   "jv",   "Javanese"},\r
110         { 87,   "ja",   "Japanese"},\r
111         { 88,   "kl",   "Kalaallisut; Greenlandic"},\r
112         { 89,   "kn",   "Kannada"},\r
113         { 90,   "ks",   "Kashmiri"},\r
114         { 91,   "ka",   "Georgian"},\r
115         { 92,   "kr",   "Kanuri"},\r
116         { 93,   "kk",   "Kazakh"},\r
117         { 94,   "km",   "Central Khmer"},\r
118         { 95,   "ki",   "Kikuyu; Gikuyu"},\r
119         { 96,   "rw",   "Kinyarwanda"},\r
120         { 97,   "ky",   "Kirghiz; Kyrgyz"},\r
121         { 98,   "kv",   "Komi"},\r
122         { 99,   "kg",   "Kongo"},\r
123         {100,   "ko",   "Korean"},\r
124         {101,   "kj",   "Kuanyama; Kwanyama"},\r
125         {102,   "ku",   "Kurdish"},\r
126         {103,   "lo",   "Lao"},\r
127         {104,   "la",   "Latin"},\r
128         {105,   "lv",   "Latvian"},\r
129         {106,   "li",   "Limburgan; Limburger; Limburgish"},\r
130         {107,   "ln",   "Lingala"},\r
131         {108,   "lt",   "Lithuanian"},\r
132         {109,   "lb",   "Luxembourgish; Letzeburgesch"},\r
133         {110,   "lu",   "Luba-Katanga"},\r
134         {111,   "lg",   "Ganda"},\r
135         {112,   "mk",   "Macedonian"},\r
136         {113,   "mh",   "Marshallese"},\r
137         {114,   "ml",   "Malayalam"},\r
138         {115,   "mi",   "Maori"},\r
139         {116,   "mr",   "Marathi"},\r
140         {117,   "ms",   "Malay"},\r
141         {118,   "mk",   "Macedonian"},\r
142         {119,   "mg",   "Malagasy"},\r
143         {120,   "mt",   "Maltese"},\r
144         {121,   "mo",   "Moldavian"},\r
145         {122,   "mn",   "Mongolian"},\r
146         {123,   "mi",   "Maori"},\r
147         {124,   "ms",   "Malay"},\r
148         {125,   "my",   "Burmese"},\r
149         {126,   "na",   "Nauru"},\r
150         {127,   "nv",   "Navajo; Navaho"},\r
151         {128,   "nr",   "Ndebele, South; South Ndebele"},\r
152         {129,   "nd",   "Ndebele, North; North Ndebele"},\r
153         {130,   "ng",   "Ndonga"},\r
154         {131,   "ne",   "Nepali"},\r
155         {132,   "nl",   "Dutch; Flemish"},\r
156         {133,   "nn",   "Norwegian Nynorsk; Nynorsk, Norwegian"},\r
157         {134,   "nb",   "Bokmål, Norwegian; Norwegian Bokmål"},\r
158         {135,   "no",   "Norwegian"},\r
159         {136,   "ny",   "Chichewa; Chewa; Nyanja"},\r
160         {137,   "oc",   "Occitan (post 1500); Provençal"},\r
161         {138,   "oj",   "Ojibwa"},\r
162         {139,   "or",   "Oriya"},\r
163         {140,   "om",   "Oromo"},\r
164         {141,   "os",   "Ossetian; Ossetic"},\r
165         {142,   "pa",   "Panjabi; Punjabi"},\r
166         {143,   "fa",   "Persian"},\r
167         {144,   "pi",   "Pali"},\r
168         {145,   "pl",   "Polish"},\r
169         {146,   "pt",   "Portuguese"},\r
170         {147,   "ps",   "Pushto"},\r
171         {148,   "qu",   "Quechua"},\r
172         {149,   "rm",   "Romansh"},\r
173         {150,   "ro",   "Romanian"},\r
174         {151,   "rn",   "Rundi"},\r
175         {152,   "ru",   "Russian"},\r
176         {153,   "sg",   "Sango"},\r
177         {154,   "sa",   "Sanskrit"},\r
178         {155,   "sr",   "Serbian"},\r
179         {156,   "hr",   "Croatian"},\r
180         {157,   "si",   "Sinhala; Sinhalese"},\r
181         {158,   "sk",   "Slovak"},\r
182         {159,   "sl",   "Slovenian"},\r
183         {160,   "se",   "Northern Sami"},\r
184         {161,   "sm",   "Samoan"},\r
185         {162,   "sn",   "Shona"},\r
186         {163,   "sd",   "Sindhi"},\r
187         {164,   "so",   "Somali"},\r
188         {165,   "st",   "Sotho, Southern"},\r
189         {166,   "es",   "Spanish; Castilian"},\r
190         {167,   "sq",   "Albanian"},\r
191         {168,   "sc",   "Sardinian"},\r
192         {169,   "sr",   "Serbian"},\r
193         {170,   "ss",   "Swati"},\r
194         {171,   "su",   "Sundanese"},\r
195         {172,   "sw",   "Swahili"},\r
196         {173,   "sv",   "Swedish"},\r
197         {174,   "ty",   "Tahitian"},\r
198         {175,   "ta",   "Tamil"},\r
199         {176,   "tt",   "Tatar"},\r
200         {177,   "te",   "Telugu"},\r
201         {178,   "tg",   "Tajik"},\r
202         {179,   "tl",   "Tagalog"},\r
203         {180,   "th",   "Thai"},\r
204         {181,   "bo",   "Tibetan"},\r
205         {182,   "ti",   "Tigrinya"},\r
206         {183,   "to",   "Tonga (Tonga Islands)"},\r
207         {184,   "tn",   "Tswana"},\r
208         {185,   "ts",   "Tsonga"},\r
209         {186,   "tk",   "Turkmen"},\r
210         {187,   "tr",   "Turkish"},\r
211         {188,   "tw",   "Twi"},\r
212         {189,   "ug",   "Uighur; Uyghur"},\r
213         {190,   "uk",   "Ukrainian"},\r
214         {191,   "ur",   "Urdu"},\r
215         {192,   "uz",   "Uzbek"},\r
216         {193,   "ve",   "Venda"},\r
217         {194,   "vi",   "Vietnamese"},\r
218         {195,   "vo",   "Volapük"},\r
219         {196,   "cy",   "Welsh"},\r
220         {197,   "wa",   "Walloon"},\r
221         {198,   "wo",   "Wolof"},\r
222         {199,   "xh",   "Xhosa"},\r
223         {200,   "yi",   "Yiddish"},\r
224         {201,   "yo",   "Yoruba"},\r
225         {202,   "za",   "Zhuang; Chuang"},\r
226         {203,   "zh",   "Chinese"},\r
227         {204,   "zu",   "Zulu"}\r
228         };\r
229 /*-----------------------------------------------------------------------------------*/ \r
230 static char CURRENTLANGUAGESTRING[LengthAlpha2code]="en";\r
231 static int  CURRENTLANGUAGECODE=45;\r
232 /*-----------------------------------------------------------------------------------*/ \r
233 static BOOL LanguageIsOK(char *lang);\r
234 static int FindLanguageCode(char *lang);\r
235 static BOOL setlanguagecode(char *lang);\r
236 /*-----------------------------------------------------------------------------------*/ \r
237 BOOL setlanguage(char *lang)\r
238 {\r
239         BOOL bOK=FALSE;\r
240         if (lang)\r
241         {\r
242                 if ( LanguageIsOK(lang) )\r
243                 {\r
244                         strcpy(CURRENTLANGUAGESTRING,lang);\r
245                         setlanguagecode(lang);\r
246                         bOK=TRUE;\r
247                 }\r
248         }\r
249         return bOK;\r
250 }\r
251 /*-----------------------------------------------------------------------------------*/ \r
252 char *getlanguage(void)\r
253 {\r
254         char *RetLanguage=NULL;\r
255 \r
256         RetLanguage=(char*)MALLOC(sizeof(char)*(strlen(CURRENTLANGUAGESTRING)+1));\r
257         strcpy(RetLanguage,CURRENTLANGUAGESTRING);\r
258 \r
259         return RetLanguage;\r
260 }\r
261 /*-----------------------------------------------------------------------------------*/ \r
262 int getcurrentlanguagecode(void)\r
263 {\r
264         return CURRENTLANGUAGECODE;\r
265 }\r
266 /*-----------------------------------------------------------------------------------*/ \r
267 static BOOL LanguageIsOK(char *lang)\r
268 {\r
269         BOOL bOK=FALSE;\r
270         int i=0;\r
271 \r
272         for (i=0;i<NumberLanguages;i++)\r
273         {\r
274                 if (strcmp(lang,TabLanguages[i].alpha2code)==0)\r
275                 {\r
276                         bOK=TRUE;\r
277                         return bOK;\r
278                 }\r
279         }\r
280         return bOK;\r
281 }\r
282 /*-----------------------------------------------------------------------------------*/ \r
283 static int FindLanguageCode(char *lang)\r
284 {\r
285         int Code=-1;\r
286         int i=0;\r
287 \r
288         for (i=0;i<NumberLanguages;i++)\r
289         {\r
290                 if (strcmp(lang,TabLanguages[i].alpha2code)==0)\r
291                 {\r
292                         Code=TabLanguages[i].code;\r
293                         return Code;\r
294                 }\r
295         }\r
296         return Code;\r
297 }\r
298 /*-----------------------------------------------------------------------------------*/ \r
299 static BOOL setlanguagecode(char *lang)\r
300 {\r
301         BOOL bOK=FALSE;\r
302         int tmpCode=FindLanguageCode(lang);\r
303         \r
304         if (tmpCode>0) \r
305         {\r
306                 CURRENTLANGUAGECODE=tmpCode;\r
307                 bOK=TRUE;\r
308         }\r
309         return bOK;\r
310 }\r
311 /*-----------------------------------------------------------------------------------*/ \r