update dev300-m58
[ooovba.git] / i18npool / source / isolang / mslangid.cxx
blobe8e661e5929885f397df8b255463900b8b1d1937
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mslangid.cxx,v $
10 * $Revision: 1.10.24.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_i18npool.hxx"
33 #include <sal/config.h>
34 #include <rtl/ustring.hxx>
35 #include <rtl/string.hxx>
36 #include <com/sun/star/i18n/ScriptType.hpp>
38 #include "i18npool/mslangid.hxx"
41 LanguageType MsLangId::nConfiguredSystemLanguage = LANGUAGE_SYSTEM;
42 LanguageType MsLangId::nConfiguredSystemUILanguage = LANGUAGE_SYSTEM;
45 // static
46 void MsLangId::setConfiguredSystemLanguage( LanguageType nLang )
48 nConfiguredSystemLanguage = nLang;
52 // static
53 void MsLangId::setConfiguredSystemUILanguage( LanguageType nLang )
55 nConfiguredSystemUILanguage = nLang;
59 // static
60 inline LanguageType MsLangId::simplifySystemLanguages( LanguageType nLang )
62 switch (nLang)
64 case LANGUAGE_PROCESS_OR_USER_DEFAULT :
65 case LANGUAGE_SYSTEM_DEFAULT :
66 case LANGUAGE_SYSTEM :
67 nLang = LANGUAGE_SYSTEM;
68 break;
69 default:
70 ; // nothing
72 return nLang;
76 // static
77 LanguageType MsLangId::getRealLanguageWithoutConfig( LanguageType nLang )
79 switch (simplifySystemLanguages( nLang))
81 case LANGUAGE_SYSTEM :
82 nLang = getSystemLanguage();
83 break;
84 case LANGUAGE_NONE :
85 nLang = getSystemUILanguage();
86 break;
87 default:
88 ; // nothing
90 if (nLang == LANGUAGE_DONTKNOW)
91 nLang = LANGUAGE_ENGLISH_US;
92 return nLang;
96 // static
97 LanguageType MsLangId::getRealLanguage( LanguageType nLang )
99 switch (simplifySystemLanguages( nLang))
101 case LANGUAGE_SYSTEM :
102 if (nConfiguredSystemLanguage == LANGUAGE_SYSTEM)
103 nLang = getSystemLanguage();
104 else
105 nLang = nConfiguredSystemLanguage;
106 break;
107 case LANGUAGE_NONE :
108 if (nConfiguredSystemUILanguage == LANGUAGE_SYSTEM)
109 nLang = getSystemUILanguage();
110 else
111 nLang = nConfiguredSystemUILanguage;
112 break;
113 default:
114 ; // nothing
116 if (nLang == LANGUAGE_DONTKNOW)
117 nLang = LANGUAGE_ENGLISH_US;
118 return nLang;
122 // static
123 void MsLangId::convertLanguageToLocale( LanguageType nLang,
124 ::com::sun::star::lang::Locale & rLocale )
126 if (rLocale.Variant.getLength())
127 rLocale.Variant = rtl::OUString();
128 convertLanguageToIsoNames( nLang, rLocale.Language, rLocale.Country);
132 // static
133 ::com::sun::star::lang::Locale MsLangId::convertLanguageToLocale(
134 LanguageType nLang, bool bResolveSystem )
136 ::com::sun::star::lang::Locale aLocale;
137 if (!bResolveSystem && simplifySystemLanguages( nLang) == LANGUAGE_SYSTEM)
138 ; // nothing => empty locale
139 else
141 // Still resolve LANGUAGE_DONTKNOW if resolving is not requested,
142 // but not LANGUAGE_NONE or others.
143 if (bResolveSystem || nLang == LANGUAGE_DONTKNOW)
144 nLang = MsLangId::getRealLanguage( nLang);
145 convertLanguageToLocale( nLang, aLocale);
147 return aLocale;
151 // static
152 LanguageType MsLangId::convertLocaleToLanguage(
153 const ::com::sun::star::lang::Locale& rLocale )
155 // empty language => LANGUAGE_SYSTEM
156 if (rLocale.Language.getLength() == 0)
157 return LANGUAGE_SYSTEM;
159 LanguageType nRet = convertIsoNamesToLanguage( rLocale.Language,
160 rLocale.Country);
161 if (nRet == LANGUAGE_DONTKNOW)
162 nRet = LANGUAGE_SYSTEM;
164 return nRet;
168 // static
169 LanguageType MsLangId::convertLocaleToLanguageWithFallback(
170 const ::com::sun::star::lang::Locale & rLocale )
172 // empty language => LANGUAGE_SYSTEM
173 if (rLocale.Language.getLength() == 0)
174 return lookupFallbackLanguage( LANGUAGE_SYSTEM);
176 return lookupFallbackLanguage( rLocale);
180 // static
181 ::com::sun::star::lang::Locale MsLangId::convertLanguageToLocaleWithFallback(
182 LanguageType nLang )
184 return lookupFallbackLocale( MsLangId::getRealLanguage( nLang));
188 // static
189 ::com::sun::star::lang::Locale MsLangId::getFallbackLocale(
190 const ::com::sun::star::lang::Locale & rLocale )
192 // empty language => LANGUAGE_SYSTEM
193 if (rLocale.Language.getLength() == 0)
194 return convertLanguageToLocaleWithFallback( LANGUAGE_SYSTEM);
196 return lookupFallbackLocale( rLocale);
200 // static
201 LanguageType MsLangId::getFallbackLanguage( LanguageType nLang )
203 return lookupFallbackLanguage( MsLangId::getRealLanguage( nLang));
207 // static
208 bool MsLangId::isRightToLeft( LanguageType nLang )
210 switch( nLang & LANGUAGE_MASK_PRIMARY )
212 case LANGUAGE_ARABIC_SAUDI_ARABIA & LANGUAGE_MASK_PRIMARY :
213 case LANGUAGE_HEBREW & LANGUAGE_MASK_PRIMARY :
214 case LANGUAGE_URDU & LANGUAGE_MASK_PRIMARY :
215 case LANGUAGE_FARSI & LANGUAGE_MASK_PRIMARY :
216 case LANGUAGE_KASHMIRI & LANGUAGE_MASK_PRIMARY :
217 case LANGUAGE_SINDHI & LANGUAGE_MASK_PRIMARY :
218 return true;
220 default:
221 break;
223 return false;
227 // static
228 bool MsLangId::hasForbiddenCharacters( LanguageType nLang )
230 switch (nLang & LANGUAGE_MASK_PRIMARY)
232 case LANGUAGE_CHINESE & LANGUAGE_MASK_PRIMARY:
233 case LANGUAGE_JAPANESE & LANGUAGE_MASK_PRIMARY:
234 case LANGUAGE_KOREAN & LANGUAGE_MASK_PRIMARY:
235 return true;
236 default:
237 break;
239 return false;
243 // static
244 bool MsLangId::needsSequenceChecking( LanguageType nLang )
246 switch (nLang & LANGUAGE_MASK_PRIMARY)
248 case LANGUAGE_BURMESE & LANGUAGE_MASK_PRIMARY:
249 case LANGUAGE_KHMER & LANGUAGE_MASK_PRIMARY:
250 case LANGUAGE_LAO & LANGUAGE_MASK_PRIMARY:
251 case LANGUAGE_THAI & LANGUAGE_MASK_PRIMARY:
252 return true;
253 default:
254 break;
256 return false;
260 // static
261 sal_Int16 MsLangId::getScriptType( LanguageType nLang )
263 sal_Int16 nScript;
264 switch( nLang )
266 // CJK
267 // all LANGUAGE_CHINESE_... are caught below
268 case LANGUAGE_JAPANESE:
269 case LANGUAGE_KOREAN:
270 case LANGUAGE_KOREAN_JOHAB:
271 case LANGUAGE_USER_KOREAN_NORTH:
272 nScript = ::com::sun::star::i18n::ScriptType::ASIAN;
273 break;
275 // CTL
276 // all LANGUAGE_ARABIC_... are caught below
277 case LANGUAGE_AMHARIC_ETHIOPIA:
278 case LANGUAGE_ASSAMESE:
279 case LANGUAGE_BENGALI:
280 case LANGUAGE_BENGALI_BANGLADESH:
281 case LANGUAGE_BURMESE:
282 case LANGUAGE_FARSI:
283 case LANGUAGE_HEBREW:
284 case LANGUAGE_MARATHI:
285 case LANGUAGE_PUNJABI:
286 case LANGUAGE_GUJARATI:
287 case LANGUAGE_HINDI:
288 case LANGUAGE_KANNADA:
289 case LANGUAGE_KASHMIRI:
290 case LANGUAGE_KASHMIRI_INDIA:
291 case LANGUAGE_KHMER:
292 case LANGUAGE_LAO:
293 case LANGUAGE_MALAYALAM:
294 case LANGUAGE_MANIPURI:
295 case LANGUAGE_MONGOLIAN_MONGOLIAN:
296 case LANGUAGE_NEPALI:
297 case LANGUAGE_NEPALI_INDIA:
298 case LANGUAGE_ORIYA:
299 case LANGUAGE_SANSKRIT:
300 case LANGUAGE_SINDHI:
301 case LANGUAGE_SINDHI_PAKISTAN:
302 case LANGUAGE_SINHALESE_SRI_LANKA:
303 case LANGUAGE_SYRIAC:
304 case LANGUAGE_TAMIL:
305 case LANGUAGE_TELUGU:
306 case LANGUAGE_THAI:
307 case LANGUAGE_TIBETAN:
308 case LANGUAGE_DZONGKHA:
309 case LANGUAGE_URDU:
310 case LANGUAGE_URDU_PAKISTAN:
311 case LANGUAGE_URDU_INDIA:
312 case LANGUAGE_USER_KURDISH_IRAQ:
313 case LANGUAGE_USER_KURDISH_IRAN:
314 case LANGUAGE_DHIVEHI:
315 case LANGUAGE_USER_BODO_INDIA:
316 case LANGUAGE_USER_DOGRI_INDIA:
317 case LANGUAGE_USER_MAITHILI_INDIA:
318 nScript = ::com::sun::star::i18n::ScriptType::COMPLEX;
319 break;
321 // currently not knowing scripttype - defaulted to LATIN:
323 #define LANGUAGE_ARMENIAN 0x042B
324 #define LANGUAGE_INDONESIAN 0x0421
325 #define LANGUAGE_KAZAK 0x043F
326 #define LANGUAGE_KONKANI 0x0457
327 #define LANGUAGE_MACEDONIAN 0x042F
328 #define LANGUAGE_TATAR 0x0444
331 default:
332 switch ( nLang & LANGUAGE_MASK_PRIMARY )
334 // CJK catcher
335 case LANGUAGE_CHINESE & LANGUAGE_MASK_PRIMARY:
336 nScript = ::com::sun::star::i18n::ScriptType::ASIAN;
337 break;
338 // CTL catcher
339 case LANGUAGE_ARABIC_SAUDI_ARABIA & LANGUAGE_MASK_PRIMARY:
340 nScript = ::com::sun::star::i18n::ScriptType::COMPLEX;
341 break;
342 // Western (actually not necessarily Latin but also Cyrillic, for example)
343 default:
344 nScript = ::com::sun::star::i18n::ScriptType::LATIN;
346 break;
348 return nScript;
352 // static
353 LanguageType MsLangId::getReplacementForObsoleteLanguage( LanguageType nLang )
355 switch (nLang)
357 default:
358 break; // nothing
359 case LANGUAGE_OBSOLETE_USER_LATIN:
360 nLang = LANGUAGE_LATIN;
361 break;
362 case LANGUAGE_OBSOLETE_USER_MAORI:
363 nLang = LANGUAGE_MAORI_NEW_ZEALAND;
364 break;
365 case LANGUAGE_OBSOLETE_USER_KINYARWANDA:
366 nLang = LANGUAGE_KINYARWANDA_RWANDA;
367 break;
368 case LANGUAGE_OBSOLETE_USER_UPPER_SORBIAN:
369 nLang = LANGUAGE_UPPER_SORBIAN_GERMANY;
370 break;
371 case LANGUAGE_OBSOLETE_USER_LOWER_SORBIAN:
372 nLang = LANGUAGE_LOWER_SORBIAN_GERMANY;
373 break;
374 case LANGUAGE_OBSOLETE_USER_OCCITAN:
375 nLang = LANGUAGE_OCCITAN_FRANCE;
376 break;
377 case LANGUAGE_OBSOLETE_USER_BRETON:
378 nLang = LANGUAGE_BRETON_FRANCE;
379 break;
380 case LANGUAGE_OBSOLETE_USER_KALAALLISUT:
381 nLang = LANGUAGE_KALAALLISUT_GREENLAND;
382 break;
383 case LANGUAGE_OBSOLETE_USER_LUXEMBOURGISH:
384 nLang = LANGUAGE_LUXEMBOURGISH_LUXEMBOURG;
385 break;
387 // The following are not strictly obsolete but should be mapped to a
388 // replacement locale when encountered.
390 // no_NO is an alias for nb_NO
391 case LANGUAGE_NORWEGIAN:
392 nLang = LANGUAGE_NORWEGIAN_BOKMAL;
393 break;
395 // #i94435# A Spanish variant that differs only in collation details we
396 // do not support.
397 case LANGUAGE_SPANISH_DATED:
398 nLang = LANGUAGE_SPANISH_MODERN;
399 break;
401 return nLang;