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
;
46 void MsLangId::setConfiguredSystemLanguage( LanguageType nLang
)
48 nConfiguredSystemLanguage
= nLang
;
53 void MsLangId::setConfiguredSystemUILanguage( LanguageType nLang
)
55 nConfiguredSystemUILanguage
= nLang
;
60 inline LanguageType
MsLangId::simplifySystemLanguages( LanguageType nLang
)
64 case LANGUAGE_PROCESS_OR_USER_DEFAULT
:
65 case LANGUAGE_SYSTEM_DEFAULT
:
66 case LANGUAGE_SYSTEM
:
67 nLang
= LANGUAGE_SYSTEM
;
77 LanguageType
MsLangId::getRealLanguageWithoutConfig( LanguageType nLang
)
79 switch (simplifySystemLanguages( nLang
))
81 case LANGUAGE_SYSTEM
:
82 nLang
= getSystemLanguage();
85 nLang
= getSystemUILanguage();
90 if (nLang
== LANGUAGE_DONTKNOW
)
91 nLang
= LANGUAGE_ENGLISH_US
;
97 LanguageType
MsLangId::getRealLanguage( LanguageType nLang
)
99 switch (simplifySystemLanguages( nLang
))
101 case LANGUAGE_SYSTEM
:
102 if (nConfiguredSystemLanguage
== LANGUAGE_SYSTEM
)
103 nLang
= getSystemLanguage();
105 nLang
= nConfiguredSystemLanguage
;
108 if (nConfiguredSystemUILanguage
== LANGUAGE_SYSTEM
)
109 nLang
= getSystemUILanguage();
111 nLang
= nConfiguredSystemUILanguage
;
116 if (nLang
== LANGUAGE_DONTKNOW
)
117 nLang
= LANGUAGE_ENGLISH_US
;
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
);
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
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
);
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
,
161 if (nRet
== LANGUAGE_DONTKNOW
)
162 nRet
= LANGUAGE_SYSTEM
;
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
);
181 ::com::sun::star::lang::Locale
MsLangId::convertLanguageToLocaleWithFallback(
184 return lookupFallbackLocale( MsLangId::getRealLanguage( nLang
));
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
);
201 LanguageType
MsLangId::getFallbackLanguage( LanguageType nLang
)
203 return lookupFallbackLanguage( MsLangId::getRealLanguage( nLang
));
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
:
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
:
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
:
261 sal_Int16
MsLangId::getScriptType( LanguageType nLang
)
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
;
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
:
283 case LANGUAGE_HEBREW
:
284 case LANGUAGE_MARATHI
:
285 case LANGUAGE_PUNJABI
:
286 case LANGUAGE_GUJARATI
:
288 case LANGUAGE_KANNADA
:
289 case LANGUAGE_KASHMIRI
:
290 case LANGUAGE_KASHMIRI_INDIA
:
293 case LANGUAGE_MALAYALAM
:
294 case LANGUAGE_MANIPURI
:
295 case LANGUAGE_MONGOLIAN_MONGOLIAN
:
296 case LANGUAGE_NEPALI
:
297 case LANGUAGE_NEPALI_INDIA
:
299 case LANGUAGE_SANSKRIT
:
300 case LANGUAGE_SINDHI
:
301 case LANGUAGE_SINDHI_PAKISTAN
:
302 case LANGUAGE_SINHALESE_SRI_LANKA
:
303 case LANGUAGE_SYRIAC
:
305 case LANGUAGE_TELUGU
:
307 case LANGUAGE_TIBETAN
:
308 case LANGUAGE_DZONGKHA
:
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
;
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
332 switch ( nLang
& LANGUAGE_MASK_PRIMARY
)
335 case LANGUAGE_CHINESE
& LANGUAGE_MASK_PRIMARY
:
336 nScript
= ::com::sun::star::i18n::ScriptType::ASIAN
;
339 case LANGUAGE_ARABIC_SAUDI_ARABIA
& LANGUAGE_MASK_PRIMARY
:
340 nScript
= ::com::sun::star::i18n::ScriptType::COMPLEX
;
342 // Western (actually not necessarily Latin but also Cyrillic, for example)
344 nScript
= ::com::sun::star::i18n::ScriptType::LATIN
;
353 LanguageType
MsLangId::getReplacementForObsoleteLanguage( LanguageType nLang
)
359 case LANGUAGE_OBSOLETE_USER_LATIN
:
360 nLang
= LANGUAGE_LATIN
;
362 case LANGUAGE_OBSOLETE_USER_MAORI
:
363 nLang
= LANGUAGE_MAORI_NEW_ZEALAND
;
365 case LANGUAGE_OBSOLETE_USER_KINYARWANDA
:
366 nLang
= LANGUAGE_KINYARWANDA_RWANDA
;
368 case LANGUAGE_OBSOLETE_USER_UPPER_SORBIAN
:
369 nLang
= LANGUAGE_UPPER_SORBIAN_GERMANY
;
371 case LANGUAGE_OBSOLETE_USER_LOWER_SORBIAN
:
372 nLang
= LANGUAGE_LOWER_SORBIAN_GERMANY
;
374 case LANGUAGE_OBSOLETE_USER_OCCITAN
:
375 nLang
= LANGUAGE_OCCITAN_FRANCE
;
377 case LANGUAGE_OBSOLETE_USER_BRETON
:
378 nLang
= LANGUAGE_BRETON_FRANCE
;
380 case LANGUAGE_OBSOLETE_USER_KALAALLISUT
:
381 nLang
= LANGUAGE_KALAALLISUT_GREENLAND
;
383 case LANGUAGE_OBSOLETE_USER_LUXEMBOURGISH
:
384 nLang
= LANGUAGE_LUXEMBOURGISH_LUXEMBOURG
;
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
;
395 // #i94435# A Spanish variant that differs only in collation details we
397 case LANGUAGE_SPANISH_DATED
:
398 nLang
= LANGUAGE_SPANISH_MODERN
;