1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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
;
44 LanguageType
MsLangId::nConfiguredWesternFallback
= LANGUAGE_SYSTEM
;
45 LanguageType
MsLangId::nConfiguredAsianFallback
= LANGUAGE_SYSTEM
;
46 LanguageType
MsLangId::nConfiguredComplexFallback
= LANGUAGE_SYSTEM
;
49 void MsLangId::setConfiguredSystemLanguage( LanguageType nLang
)
51 nConfiguredSystemLanguage
= nLang
;
56 void MsLangId::setConfiguredSystemUILanguage( LanguageType nLang
)
58 nConfiguredSystemUILanguage
= nLang
;
62 void MsLangId::setConfiguredWesternFallback( LanguageType nLang
)
64 nConfiguredWesternFallback
= nLang
;
68 void MsLangId::setConfiguredAsianFallback( LanguageType nLang
)
70 nConfiguredAsianFallback
= nLang
;
74 void MsLangId::setConfiguredComplexFallback( LanguageType nLang
)
76 nConfiguredComplexFallback
= nLang
;
80 inline LanguageType
MsLangId::simplifySystemLanguages( LanguageType nLang
)
84 case LANGUAGE_PROCESS_OR_USER_DEFAULT
:
85 case LANGUAGE_SYSTEM_DEFAULT
:
86 case LANGUAGE_SYSTEM
:
87 nLang
= LANGUAGE_SYSTEM
;
97 LanguageType
MsLangId::getRealLanguageWithoutConfig( LanguageType nLang
)
99 switch (simplifySystemLanguages( nLang
))
101 case LANGUAGE_SYSTEM
:
102 nLang
= getSystemLanguage();
105 nLang
= getSystemUILanguage();
110 if (nLang
== LANGUAGE_DONTKNOW
)
111 nLang
= LANGUAGE_ENGLISH_US
;
117 LanguageType
MsLangId::getRealLanguage( LanguageType nLang
)
119 switch (simplifySystemLanguages( nLang
))
121 case LANGUAGE_SYSTEM
:
122 if (nConfiguredSystemLanguage
== LANGUAGE_SYSTEM
)
123 nLang
= getSystemLanguage();
125 nLang
= nConfiguredSystemLanguage
;
128 if (nConfiguredSystemUILanguage
== LANGUAGE_SYSTEM
)
129 nLang
= getSystemUILanguage();
131 nLang
= nConfiguredSystemUILanguage
;
136 if (nLang
== LANGUAGE_DONTKNOW
)
137 nLang
= LANGUAGE_ENGLISH_US
;
143 LanguageType
MsLangId::resolveSystemLanguageByScriptType( LanguageType nLang
, sal_Int16 nType
)
145 if (nLang
== LANGUAGE_NONE
)
148 nLang
= getRealLanguage(nLang
);
149 if (nType
!= ::com::sun::star::i18n::ScriptType::WEAK
&& getScriptType(nLang
) != nType
)
153 case ::com::sun::star::i18n::ScriptType::ASIAN
:
154 if (nConfiguredAsianFallback
== LANGUAGE_SYSTEM
)
155 nLang
= LANGUAGE_CHINESE_SIMPLIFIED
;
157 nLang
= nConfiguredComplexFallback
;
159 case ::com::sun::star::i18n::ScriptType::COMPLEX
:
160 if (nConfiguredComplexFallback
== LANGUAGE_SYSTEM
)
161 nLang
= LANGUAGE_HINDI
;
163 nLang
= nConfiguredComplexFallback
;
166 if (nConfiguredWesternFallback
== LANGUAGE_SYSTEM
)
167 nLang
= LANGUAGE_ENGLISH_US
;
169 nLang
= nConfiguredWesternFallback
;
177 void MsLangId::convertLanguageToLocale( LanguageType nLang
,
178 ::com::sun::star::lang::Locale
& rLocale
)
180 if (rLocale
.Variant
.getLength())
181 rLocale
.Variant
= rtl::OUString();
182 convertLanguageToIsoNames( nLang
, rLocale
.Language
, rLocale
.Country
);
187 ::com::sun::star::lang::Locale
MsLangId::convertLanguageToLocale(
188 LanguageType nLang
, bool bResolveSystem
)
190 ::com::sun::star::lang::Locale aLocale
;
191 if (!bResolveSystem
&& simplifySystemLanguages( nLang
) == LANGUAGE_SYSTEM
)
192 ; // nothing => empty locale
195 // Still resolve LANGUAGE_DONTKNOW if resolving is not requested,
196 // but not LANGUAGE_NONE or others.
197 if (bResolveSystem
|| nLang
== LANGUAGE_DONTKNOW
)
198 nLang
= MsLangId::getRealLanguage( nLang
);
199 convertLanguageToLocale( nLang
, aLocale
);
206 LanguageType
MsLangId::convertLocaleToLanguage(
207 const ::com::sun::star::lang::Locale
& rLocale
)
209 // empty language => LANGUAGE_SYSTEM
210 if (rLocale
.Language
.getLength() == 0)
211 return LANGUAGE_SYSTEM
;
213 LanguageType nRet
= convertIsoNamesToLanguage( rLocale
.Language
,
215 if (nRet
== LANGUAGE_DONTKNOW
)
216 nRet
= LANGUAGE_SYSTEM
;
223 LanguageType
MsLangId::convertLocaleToLanguageWithFallback(
224 const ::com::sun::star::lang::Locale
& rLocale
)
226 // empty language => LANGUAGE_SYSTEM
227 if (rLocale
.Language
.getLength() == 0)
228 return lookupFallbackLanguage( LANGUAGE_SYSTEM
);
230 return lookupFallbackLanguage( rLocale
);
235 ::com::sun::star::lang::Locale
MsLangId::convertLanguageToLocaleWithFallback(
238 return lookupFallbackLocale( MsLangId::getRealLanguage( nLang
));
243 ::com::sun::star::lang::Locale
MsLangId::getFallbackLocale(
244 const ::com::sun::star::lang::Locale
& rLocale
)
246 // empty language => LANGUAGE_SYSTEM
247 if (rLocale
.Language
.getLength() == 0)
248 return convertLanguageToLocaleWithFallback( LANGUAGE_SYSTEM
);
250 return lookupFallbackLocale( rLocale
);
255 LanguageType
MsLangId::getFallbackLanguage( LanguageType nLang
)
257 return lookupFallbackLanguage( MsLangId::getRealLanguage( nLang
));
262 bool MsLangId::isRightToLeft( LanguageType nLang
)
264 switch( nLang
& LANGUAGE_MASK_PRIMARY
)
266 case LANGUAGE_ARABIC_SAUDI_ARABIA
& LANGUAGE_MASK_PRIMARY
:
267 case LANGUAGE_HEBREW
& LANGUAGE_MASK_PRIMARY
:
268 case LANGUAGE_YIDDISH
& LANGUAGE_MASK_PRIMARY
:
269 case LANGUAGE_URDU
& LANGUAGE_MASK_PRIMARY
:
270 case LANGUAGE_FARSI
& LANGUAGE_MASK_PRIMARY
:
271 case LANGUAGE_KASHMIRI
& LANGUAGE_MASK_PRIMARY
:
272 case LANGUAGE_SINDHI
& LANGUAGE_MASK_PRIMARY
:
273 case LANGUAGE_UIGHUR_CHINA
& LANGUAGE_MASK_PRIMARY
:
284 bool MsLangId::hasForbiddenCharacters( LanguageType nLang
)
286 switch (nLang
& LANGUAGE_MASK_PRIMARY
)
288 case LANGUAGE_CHINESE
& LANGUAGE_MASK_PRIMARY
:
289 case LANGUAGE_JAPANESE
& LANGUAGE_MASK_PRIMARY
:
290 case LANGUAGE_KOREAN
& LANGUAGE_MASK_PRIMARY
:
300 bool MsLangId::needsSequenceChecking( LanguageType nLang
)
302 switch (nLang
& LANGUAGE_MASK_PRIMARY
)
304 case LANGUAGE_BURMESE
& LANGUAGE_MASK_PRIMARY
:
305 case LANGUAGE_KHMER
& LANGUAGE_MASK_PRIMARY
:
306 case LANGUAGE_LAO
& LANGUAGE_MASK_PRIMARY
:
307 case LANGUAGE_THAI
& LANGUAGE_MASK_PRIMARY
:
317 sal_Int16
MsLangId::getScriptType( LanguageType nLang
)
323 // all LANGUAGE_CHINESE_... are caught below
324 case LANGUAGE_JAPANESE
:
325 case LANGUAGE_KOREAN
:
326 case LANGUAGE_KOREAN_JOHAB
:
327 case LANGUAGE_USER_KOREAN_NORTH
:
328 nScript
= ::com::sun::star::i18n::ScriptType::ASIAN
;
332 // all LANGUAGE_ARABIC_... are caught below
333 case LANGUAGE_AMHARIC_ETHIOPIA
:
334 case LANGUAGE_ASSAMESE
:
335 case LANGUAGE_BENGALI
:
336 case LANGUAGE_BENGALI_BANGLADESH
:
337 case LANGUAGE_BURMESE
:
339 case LANGUAGE_HEBREW
:
340 case LANGUAGE_YIDDISH
:
341 case LANGUAGE_MARATHI
:
342 case LANGUAGE_PUNJABI
:
343 case LANGUAGE_GUJARATI
:
345 case LANGUAGE_KANNADA
:
346 case LANGUAGE_KASHMIRI
:
347 case LANGUAGE_KASHMIRI_INDIA
:
350 case LANGUAGE_MALAYALAM
:
351 case LANGUAGE_MANIPURI
:
352 case LANGUAGE_MONGOLIAN_MONGOLIAN
:
353 case LANGUAGE_NEPALI
:
354 case LANGUAGE_NEPALI_INDIA
:
356 case LANGUAGE_SANSKRIT
:
357 case LANGUAGE_SINDHI
:
358 case LANGUAGE_SINDHI_PAKISTAN
:
359 case LANGUAGE_SINHALESE_SRI_LANKA
:
360 case LANGUAGE_SYRIAC
:
362 case LANGUAGE_TELUGU
:
364 case LANGUAGE_TIBETAN
:
365 case LANGUAGE_DZONGKHA
:
367 case LANGUAGE_URDU_PAKISTAN
:
368 case LANGUAGE_URDU_INDIA
:
369 case LANGUAGE_USER_KURDISH_IRAQ
:
370 case LANGUAGE_USER_KURDISH_IRAN
:
371 case LANGUAGE_DHIVEHI
:
372 case LANGUAGE_USER_BODO_INDIA
:
373 case LANGUAGE_USER_DOGRI_INDIA
:
374 case LANGUAGE_USER_MAITHILI_INDIA
:
375 nScript
= ::com::sun::star::i18n::ScriptType::COMPLEX
;
378 // currently not knowing scripttype - defaulted to LATIN:
380 #define LANGUAGE_ARMENIAN 0x042B
381 #define LANGUAGE_INDONESIAN 0x0421
382 #define LANGUAGE_KAZAK 0x043F
383 #define LANGUAGE_KONKANI 0x0457
384 #define LANGUAGE_MACEDONIAN 0x042F
385 #define LANGUAGE_TATAR 0x0444
389 switch ( nLang
& LANGUAGE_MASK_PRIMARY
)
392 case LANGUAGE_CHINESE
& LANGUAGE_MASK_PRIMARY
:
393 nScript
= ::com::sun::star::i18n::ScriptType::ASIAN
;
396 case LANGUAGE_ARABIC_SAUDI_ARABIA
& LANGUAGE_MASK_PRIMARY
:
397 nScript
= ::com::sun::star::i18n::ScriptType::COMPLEX
;
399 // Western (actually not necessarily Latin but also Cyrillic, for example)
401 nScript
= ::com::sun::star::i18n::ScriptType::LATIN
;
410 LanguageType
MsLangId::getReplacementForObsoleteLanguage( LanguageType nLang
)
416 case LANGUAGE_OBSOLETE_USER_LATIN
:
417 nLang
= LANGUAGE_LATIN
;
419 case LANGUAGE_OBSOLETE_USER_MAORI
:
420 nLang
= LANGUAGE_MAORI_NEW_ZEALAND
;
422 case LANGUAGE_OBSOLETE_USER_KINYARWANDA
:
423 nLang
= LANGUAGE_KINYARWANDA_RWANDA
;
425 case LANGUAGE_OBSOLETE_USER_UPPER_SORBIAN
:
426 nLang
= LANGUAGE_UPPER_SORBIAN_GERMANY
;
428 case LANGUAGE_OBSOLETE_USER_LOWER_SORBIAN
:
429 nLang
= LANGUAGE_LOWER_SORBIAN_GERMANY
;
431 case LANGUAGE_OBSOLETE_USER_OCCITAN
:
432 nLang
= LANGUAGE_OCCITAN_FRANCE
;
434 case LANGUAGE_OBSOLETE_USER_BRETON
:
435 nLang
= LANGUAGE_BRETON_FRANCE
;
437 case LANGUAGE_OBSOLETE_USER_KALAALLISUT
:
438 nLang
= LANGUAGE_KALAALLISUT_GREENLAND
;
440 case LANGUAGE_OBSOLETE_USER_LUXEMBOURGISH
:
441 nLang
= LANGUAGE_LUXEMBOURGISH_LUXEMBOURG
;
444 // The following are not strictly obsolete but should be mapped to a
445 // replacement locale when encountered.
447 // no_NO is an alias for nb_NO
448 case LANGUAGE_NORWEGIAN
:
449 nLang
= LANGUAGE_NORWEGIAN_BOKMAL
;
452 // #i94435# A Spanish variant that differs only in collation details we
454 case LANGUAGE_SPANISH_DATED
:
455 nLang
= LANGUAGE_SPANISH_MODERN
;