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