Commit c91abaff c91abaff7b2059c829d788f4ef5b8c1494f5d10d by Sergey Poznyakoff

New file. Contains locale-dependent functions.

1 parent f104514b
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2003 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <stdlib.h>
23 #include <string.h>
24
25 struct langtab
26 {
27 char *lang; /* Language code */
28 char *terr; /* Territory code */
29 char *charset; /* Corresponding charset */
30 };
31
32 /* The list of language codes defined in ISO 639 with the corresponding
33 default character sets.
34
35 NOTES:
36
37 1) The list must be ordered by:
38 a) lang field in ascending order
39 b) terr field in descending order.
40 NULL fields are considered less than non-null ones.
41 2) Many entries have NULL charset fields. Please help fill them!
42 3) The "default" character set for a given language is a matter
43 of preference. Possibly the table should contain a *list* of
44 possible character sets.
45 4) LC_ALL "modifier" field is not taken into account */
46
47 static struct langtab langtab[] = {
48 { "C", NULL, "ASCII"},
49 { "POSIX", NULL, "ASCII" },
50 { "aa", NULL, NULL}, /* Afar */
51 { "ab", NULL, NULL}, /* Abkhazian */
52 { "ae", NULL, NULL}, /* Avestan */
53 { "af", NULL, "iso-8859-1"}, /* Afrikaans */
54 { "am", NULL, "UTF-8"}, /* Amharic */
55 { "ar", NULL, "iso-8859-6"}, /* Arabic */
56 { "as", NULL, NULL}, /* Assamese */
57 { "ay", NULL, "iso-8859-1"}, /* Aymara */
58 { "az", NULL, NULL}, /* Azerbaijani */
59 { "ba", NULL, NULL}, /* Bashkir */
60 { "be", NULL, "UTF-8"}, /* Byelorussian; Belarusian */
61 { "bg", NULL, "iso-8859-5"}, /* Bulgarian */
62 { "bh", NULL, NULL}, /* Bihari */
63 { "bi", NULL, NULL}, /* Bislama */
64 { "bn", NULL, NULL}, /* Bengali; Bangla */
65 { "bo", NULL, NULL}, /* Tibetan */
66 { "br", NULL, "iso-8859-1"}, /* Breton: 1,5,8,9 */
67 { "bs", NULL, NULL}, /* Bosnian */
68 { "ca", NULL, "iso-8859-1"}, /* Catalan: 1,5,8,9 */
69 { "ce", NULL, NULL}, /* Chechen */
70 { "ch", NULL, NULL}, /* Chamorro */
71 { "co", NULL, "iso-8859-1"}, /* Corsican */
72 { "cs", NULL, "iso-8859-2"}, /* Czech */
73 { "cu", NULL, NULL }, /* Church Slavic */
74 { "cv", NULL, NULL}, /* Chuvash */
75 { "cy", NULL, "iso-8859-1"}, /* Welsh */
76 { "da", NULL, "iso-8859-1"}, /* Danish: 4-9 */
77 { "de", NULL, "iso-8859-1"}, /* German */
78 { "dz", NULL, NULL }, /* Dzongkha; Bhutani */
79 { "el", NULL, "iso-8859-7"}, /* Greek */
80 { "en", NULL, "iso-8859-1"}, /* English */
81 { "eo", NULL, "iso-8859-3"}, /* Esperanto */
82 { "es", NULL, "iso-8859-1"}, /* Spanish */
83 { "et", NULL, "iso-8859-15"}, /* Estonian: 6,7,9 */
84 { "eu", NULL, "iso-8859-1"}, /* Basque: 5,8,9 */
85 { "fa", NULL, "UTF-8"}, /* Persian */
86 { "fi", NULL, "iso-8859-15"}, /* Finnish */
87 { "fj", NULL, NULL }, /* Fijian; Fiji */
88 { "fo", NULL, "iso-8859-1"}, /* Faroese: 6,9 */
89 { "fr", NULL, "iso-8859-1"}, /* French */
90 { "fy", NULL, "iso-8859-1"}, /* Frisian */
91 { "ga", NULL, "iso-8859-14"}, /* Irish */
92 { "gd", NULL, "iso-8859-14" }, /* Scots; Gaelic */
93 { "gl", NULL, NULL }, /* Gallegan; Galician */
94 { "gn", NULL, NULL}, /* Guarani */
95 { "gu", NULL, NULL}, /* Gujarati */
96 { "gv", NULL, "iso-8859-14"}, /* Manx */
97 { "ha", NULL, NULL }, /* Hausa (?) */
98 { "he", NULL, "iso-8859-8" }, /* Hebrew */
99 { "hi", NULL, NULL}, /* Hindi */
100 { "ho", NULL, NULL}, /* Hiri Motu */
101 { "hr", NULL, "iso-8859-2"}, /* Croatian: 10 */
102 { "hu", NULL, "iso-8859-2"}, /* Hungarian */
103 { "hy", NULL, NULL}, /* Armenian */
104 { "hz", NULL, NULL}, /* Herero */
105 { "id", NULL, "iso-8859-1"}, /* Indonesian (formerly in) */
106 { "ia", NULL, NULL}, /* Interlingua */
107 { "ie", NULL, NULL}, /* Interlingue */
108 { "ik", NULL, NULL}, /* Inupiak */
109 { "io", NULL, NULL}, /* Ido */
110 { "is", NULL, "iso-8859-1"}, /* Icelandic */
111 { "it", NULL, "iso-8859-1"}, /* Italian */
112 { "iu", NULL, NULL}, /* Inuktitut */
113 { "ja", NULL, "EUC-JP"}, /* Japanese */
114 { "jv", NULL, NULL}, /* Javanese */
115 { "ka", NULL, NULL}, /* Georgian */
116 { "ki", NULL, NULL}, /* Kikuyu */
117 { "kj", NULL, NULL}, /* Kuanyama */
118 { "kk", NULL, NULL}, /* Kazakh */
119 { "kl", NULL, "iso-8859-1"}, /* Kalaallisut; Greenlandic */
120 { "km", NULL, NULL}, /* Khmer; Cambodian */
121 { "kn", NULL, NULL}, /* Kannada */
122 { "ko", NULL, "EUC-KR"}, /* Korean */
123 { "ks", NULL, NULL}, /* Kashmiri */
124 { "ku", NULL, NULL}, /* Kurdish */
125 { "kv", NULL, NULL}, /* Komi */
126 { "kw", NULL, "iso-8859-14"}, /* Cornish: 1,5,8 */
127 { "ky", NULL, NULL}, /* Kirghiz */
128 { "la", NULL, "iso-8859-1"}, /* Latin */
129 { "lb", NULL, "iso-8859-1"}, /* Letzeburgesch */
130 { "ln", NULL, NULL}, /* Lingala */
131 { "lo", NULL, NULL}, /* Lao; Laotian */
132 { "lt", NULL, "iso-8859-4"}, /* Lithuanian */
133 { "lv", NULL, "iso-8859-4"}, /* Latvian; Lettish */
134 { "mg", NULL, NULL}, /* Malagasy */
135 { "mh", NULL, NULL}, /* Marshall */
136 { "mi", NULL, NULL}, /* Maori */
137 { "mk", NULL, NULL}, /* Macedonian */
138 { "ml", NULL, NULL}, /* Malayalam */
139 { "mn", NULL, NULL}, /* Mongolian */
140 { "mo", NULL, "iso-8859-2"}, /* Moldavian */
141 { "mr", NULL, NULL}, /* Marathi */
142 { "ms", NULL, NULL}, /* Malay */
143 { "mt", NULL, "iso-8859-3"}, /* Maltese */
144 { "my", NULL, NULL}, /* Burmese */
145 { "na", NULL, NULL}, /* Nauru */
146 { "nb", NULL, "iso-8859-1"}, /* Norwegian Bokml; Bokm@aa{}l */
147 { "nd", NULL, NULL}, /* Ndebele, North */
148 { "ne", NULL, NULL}, /* Nepali */
149 { "ng", NULL, NULL}, /* Ndonga */
150 { "nl", NULL, "iso-8859-1"}, /* Dutch: 5,9 */
151 { "nn", NULL, "iso-8859-1"}, /* Norwegian Nynorsk */
152 { "no", NULL, "iso-8859-1"}, /* Norwegian */
153 { "nr", NULL, NULL}, /* Ndebele, South */
154 { "nv", NULL, NULL}, /* Navajo */
155 { "ny", NULL, NULL}, /* Chichewa; Nyanja */
156 { "oc", NULL, NULL}, /* Occitan; Provenal; Proven@,{c}al */
157 { "om", NULL, NULL}, /* (Afan) Oromo */
158 { "or", NULL, NULL}, /* Oriya */
159 { "os", NULL, NULL}, /* Ossetian; Ossetic */
160 { "pa", NULL, NULL}, /* Panjabi; Punjabi */
161 { "pi", NULL, NULL}, /* Pali */
162 { "pl", NULL, "iso-8859-2"}, /* Polish */
163 { "ps", NULL, NULL}, /* Pashto, Pushto */
164 { "pt", NULL, "iso-8859-1"}, /* Portuguese */
165 { "qu", NULL, "iso-8859-1"}, /* Quechua */
166 { "rm", NULL, "iso-8859-1"}, /* Rhaeto-Romance */
167 { "rn", NULL, NULL }, /* Rundi; Kirundi */
168 { "ro", NULL, "iso-8859-2"}, /* Romanian */
169 { "ru", NULL, "koi8-r"}, /* Russian */
170 { "rw", NULL, NULL}, /* Kinyarwanda */
171 { "sa", NULL, NULL}, /* Sanskrit */
172 { "sc", NULL, "iso-8859-1"}, /* Sardinian */
173 { "sd", NULL, NULL}, /* Sindhi */
174 { "se", NULL, "iso-8859-10"}, /* Northern Sami */
175 { "sg", NULL, NULL}, /* Sango; Sangro */
176 { "si", NULL, NULL}, /* Sinhalese */
177 { "sk", NULL, "iso-8859-2"}, /* Slovak */
178 { "sl", NULL, "iso-8859-1"}, /* Slovenian */
179 { "sm", NULL, NULL}, /* Samoan */
180 { "sn", NULL, NULL}, /* Shona */
181 { "so", NULL, NULL}, /* Somali */
182 { "sq", NULL, "iso-8859-1"}, /* Albanian: 2,5,8,9,10 */
183 { "sr", NULL, "iso-8859-2"}, /* Serbian */
184 { "ss", NULL, NULL}, /* Swati; Siswati */
185 { "st", NULL, NULL}, /* Sesotho; Sotho, Southern */
186 { "su", NULL, NULL}, /* Sundanese */
187 { "sv", NULL, "iso-8859-1"}, /* Swedish */
188 { "sw", NULL, NULL}, /* Swahili */
189 { "ta", NULL, NULL}, /* Tamil */
190 { "te", NULL, NULL}, /* Telugu */
191 { "tg", NULL, NULL}, /* Tajik */
192 { "th", NULL, "iso-8859-11"}, /* Thai */
193 { "ti", NULL, NULL}, /* Tigrinya */
194 { "tk", NULL, NULL}, /* Turkmen */
195 { "tl", NULL, "iso-8859-1"}, /* Tagalog */
196 { "tn", NULL, NULL}, /* Tswana; Setswana */
197 { "to", NULL, NULL}, /* Tonga (?) */
198 { "tr", NULL, "iso-8859-9"}, /* Turkish */
199 { "ts", NULL, NULL}, /* Tsonga */
200 { "tt", NULL, NULL}, /* Tatar */
201 { "tw", NULL, NULL}, /* Twi */
202 { "ty", NULL, NULL}, /* Tahitian */
203 { "ug", NULL, NULL}, /* Uighur */
204 { "uk", NULL, "koi8-u"}, /* Ukrainian */
205 { "ur", NULL, NULL}, /* Urdu */
206 { "uz", NULL, NULL}, /* Uzbek */
207 { "vi", NULL, NULL}, /* Vietnamese */
208 { "vo", NULL, NULL}, /* Volapk; Volap@"{u}k; Volapuk */
209 { "wa", NULL, "iso-8859-1"}, /* Walloon */
210 { "wo", NULL, NULL}, /* Wolof */
211 { "xh", NULL, NULL}, /* Xhosa */
212 { "yi", NULL, "iso-8859-8"}, /* Yiddish (formerly ji) */
213 { "yo", NULL, NULL}, /* Yoruba */
214 { "za", NULL, NULL}, /* Zhuang */
215 { "zh", "TW", "big5"}, /* Chinese */
216 { "zh", NULL, "gb2312"}, /* Chinese */
217 { "zu", NULL, NULL}, /* Zulu */
218 { NULL }
219 };
220
221 /* Given the language and (optionally) territory code, return the
222 default character set for that language. See notes above. */
223
224 const char *
225 mu_charset_lookup (char *lang, char *terr)
226 {
227 static struct langtab *p;
228
229 if (!lang)
230 return NULL;
231 for (p = langtab; p->lang; p++)
232 if (strcasecmp (p->lang, lang) == 0
233 && (terr == NULL
234 || !p->terr == NULL
235 || !strcasecmp (p->terr, terr) == 0))
236 return p->charset;
237 return NULL;
238 }
239