1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_I18NLANGTAG_MSLANGID_HXX
21 #define INCLUDED_I18NLANGTAG_MSLANGID_HXX
23 #include <sal/config.h>
25 #include <i18nlangtag/i18nlangtagdllapi.h>
26 #include <i18nlangtag/lang.h>
27 #include <com/sun/star/lang/Locale.hpp>
30 struct IsoLanguageCountryEntry
;
31 struct IsoLanguageScriptCountryEntry
;
32 struct Bcp47CountryEntry
;
34 /** Methods related to Microsoft language IDs. For details about MS-LANGIDs
36 class SAL_WARN_UNUSED I18NLANGTAG_DLLPUBLIC MsLangId
40 /// Create a LangID from a primary and a sublanguage.
41 static LanguageType
makeLangID( LanguageType nSubLangId
, LanguageType nPriLangId
)
43 return LanguageType((sal_uInt16(nSubLangId
) << 10) | sal_uInt16(nPriLangId
));
46 /// Get the primary language of a LangID.
47 static LanguageType
getPrimaryLanguage( LanguageType nLangID
)
49 return LanguageType(sal_uInt16(nLangID
) & LANGUAGE_MASK_PRIMARY
);
52 /// Get the sublanguage of a LangID.
53 static LanguageType
getSubLanguage( LanguageType nLangID
)
55 return LanguageType((sal_uInt16(nLangID
) & ~LANGUAGE_MASK_PRIMARY
) >> 10);
58 /** Language/locale of category LC_CTYPE (on Unix, else the system
60 Evaluation order: LC_ALL, LC_CTYPE, LANG */
61 static LanguageType
getSystemLanguage();
63 /** Language/locale of category LC_MESSAGES (on Unix, else same as
65 Evaluation order: LANGUAGE, LC_ALL, LC_MESSAGES, LANG */
66 static LanguageType
getSystemUILanguage();
69 /** @short: A proper language/locale if the nLang parameter designates some
72 @descr: NOTE: The "system" values may be overridden by the
73 application's configuration.
76 case LANGUAGE_PROCESS_OR_USER_DEFAULT : configured or system language
77 case LANGUAGE_SYSTEM_DEFAULT : configured or system language
78 case LANGUAGE_SYSTEM : configured or system language
79 case LANGUAGE_HID_HUMAN_INTERFACE_DEVICE : configured or system UI language
80 case LANGUAGE_DONTKNOW : LANGUAGE_ENGLISH_US
83 In case the configured language is LANGUAGE_SYSTEM, which is also
84 the initial default, the system language is obtained. In case the
85 configured or resulting system language is LANGUAGE_DONTKNOW,
86 LANGUAGE_ENGLISH_US is returned instead.
88 static LanguageType
getRealLanguage( LanguageType nLang
);
91 // TODO: refactor to LanguageTag? Used only in
92 // i18npool/source/localedata/localedata.cxx
94 /** Get fall-back Locale for Locale with handling of an empty language name
95 designating the SYSTEM language. Returns the same Locale if an exact
98 static css::lang::Locale
getFallbackLocale( const css::lang::Locale
& rLocale
);
101 // TODO: refactor to LanguageTag, used only in
102 // i18npool/source/isolang/inunx.cxx to convert Unix locale string
104 static LanguageType
convertUnxByteStringToLanguage( const OString
& rString
);
107 static LanguageType
resolveSystemLanguageByScriptType( LanguageType nLang
, sal_Int16 nType
);
110 /** Whether locale has a Right-To-Left orientation for text. */
111 static bool isRightToLeft( LanguageType nLang
);
113 /** Whether locale has a Right-To-Left orientation for math. */
114 static bool isRightToLeftMath( LanguageType nLang
);
116 /** Whether locale is a CJK locale */
117 static bool isCJK( LanguageType nLang
);
119 /** Whether locale is a chinese locale */
120 static bool isChinese( LanguageType nLang
);
122 /** Whether locale is a simplified chinese locale */
123 static bool isSimplifiedChinese( LanguageType nLang
);
125 /** Whether locale is a traditional chinese locale */
126 static bool isTraditionalChinese( LanguageType nLang
);
128 /** Whether locale is a korean locale */
129 static bool isKorean( LanguageType nLang
);
131 /** Whether locale is a simplified chinese locale */
132 static bool isSimplifiedChinese( const css::lang::Locale
& rLocale
);
134 /** Whether locale is a traditional chinese locale */
135 static bool isTraditionalChinese( const css::lang::Locale
& rLocale
);
137 /** Whether locale is one where family name comes first, e.g. Japan, Hungary, Samoa */
138 static bool isFamilyNameFirst( LanguageType nLang
);
140 /** Whether there are "forbidden characters at start or end of line" in
141 this locale. CJK locales.
143 @see offapi/com/sun/star/i18n/ForbiddenCharacters.idl
145 static bool hasForbiddenCharacters( LanguageType nLang
);
148 /** Whether locale needs input sequence checking. CTL locales. */
149 static bool needsSequenceChecking( LanguageType nLang
);
152 /** Get css::i18n::ScriptType of locale. */
153 static sal_Int16
getScriptType( LanguageType nLang
);
155 /** Whether locale is "Western" but not Latin script, e.g. Cyrillic or Greek. */
156 static bool isNonLatinWestern( LanguageType nLang
);
159 /** Map an obsolete user defined LANGID (see lang.h
160 LANGUAGE_OBSOLETE_USER_...) to the new value defined by MS in the
163 Also used to map UI localizations using reserved ISO codes to something
164 "official" but not identical in order to not pollute documents with
167 static LanguageType
getReplacementForObsoleteLanguage( LanguageType nLang
);
169 /** Whether locale is legacy, i.e. country or confederation doesn't exist anymore. */
170 static bool isLegacy( LanguageType nLang
);
173 /** @ATTENTION: these are _ONLY_ to be called by the application's
175 static void setConfiguredSystemUILanguage( LanguageType nLang
);
176 static void setConfiguredWesternFallback( LanguageType nLang
);
177 static void setConfiguredComplexFallback( LanguageType nLang
);
178 static void setConfiguredAsianFallback( LanguageType nLang
);
181 /** Encapsulated methods that shall only be accessed through
184 class LanguageTagAccess
188 friend class LanguageTag
;
190 /** Configured system locale needs always be synchronized with
191 LanguageTag's system locale.
193 I18NLANGTAG_DLLPRIVATE
static void setConfiguredSystemLanguage( LanguageType nLang
);
197 struct LanguagetagMapping
202 LanguagetagMapping( const OUString
& rBcp47
, LanguageType nLang
) : maBcp47(rBcp47
), mnLang(nLang
) {}
205 /** @internal - Obtain a list of known locales (i.e. those that have a
206 defined mapping between MS-LangID and ISO codes or tags) as BCP 47
207 language tag strings.
209 static ::std::vector
< LanguagetagMapping
> getDefinedLanguagetags();
212 /** Encapsulated conversion methods used by LanguageTag and conversions,
213 not to be used by anything else.
219 friend class LanguageTag
;
220 friend class LanguageTagImpl
;
222 friend css::lang::Locale
MsLangId::getFallbackLocale(
223 const css::lang::Locale
& rLocale
);
225 friend LanguageType
MsLangId::convertUnxByteStringToLanguage(
226 const OString
& rString
);
229 /** Convert a Locale to a LanguageType with handling of an empty
230 language name designating LANGUAGE_SYSTEM.
232 I18NLANGTAG_DLLPRIVATE
static LanguageType
convertLocaleToLanguage(
233 const css::lang::Locale
& rLocale
);
235 /** Used by convertLocaleToLanguage(Locale) */
236 I18NLANGTAG_DLLPRIVATE
static LanguageType
convertLocaleToLanguageImpl(
237 const css::lang::Locale
& rLocale
);
239 /** Convert x-... privateuse, used by convertLocaleToLanguageImpl(Locale) */
240 I18NLANGTAG_DLLPRIVATE
static LanguageType
convertPrivateUseToLanguage(
241 const OUString
& rPriv
);
243 /** Used by LanguageTag::canonicalize() */
244 I18NLANGTAG_DLLPRIVATE
static css::lang::Locale
getOverride(
245 const css::lang::Locale
& rLocale
);
247 /** Used by convertLocaleToLanguageImpl(Locale) and LanguageTagImpl::convertLocaleToLang() */
248 I18NLANGTAG_DLLPRIVATE
static LanguageType
convertIsoNamesToLanguage(
249 const OUString
& rLang
, const OUString
& rCountry
, bool bSkipIsoTable
);
252 /** Used by convertUnxByteStringToLanguage(OString) */
253 I18NLANGTAG_DLLPRIVATE
static LanguageType
convertIsoNamesToLanguage(
254 const OString
& rLang
, const OString
& rCountry
);
257 /** Used by lookupFallbackLocale(Locale) */
258 I18NLANGTAG_DLLPRIVATE
static css::lang::Locale
getLocale(
259 const IsoLanguageCountryEntry
* pEntry
);
261 /** Used by lookupFallbackLocale(Locale) */
262 I18NLANGTAG_DLLPRIVATE
static css::lang::Locale
getLocale(
263 const IsoLanguageScriptCountryEntry
* pEntry
);
265 /** Used by lookupFallbackLocale(Locale) */
266 I18NLANGTAG_DLLPRIVATE
static css::lang::Locale
getLocale(
267 const Bcp47CountryEntry
* pEntry
);
270 /** Convert a LanguageType to a Locale. */
271 I18NLANGTAG_DLLPRIVATE
static css::lang::Locale
convertLanguageToLocale(
272 LanguageType nLang
);
274 /** Used by convertLanguageToLocale(LanguageType,bool) and
275 getLocale(IsoLanguageCountryEntry*) and
276 getLocale(IsoLanguageScriptCountryEntry)
278 @param bIgnoreOverride
279 If bIgnoreOverride==true, a matching entry is used even if
280 mnOverride is set, for conversion to an even outdated tag.
281 If bIgnoreOverride==false, a matching entry is skipped if
282 mnOverride is set and instead the override is followed.
284 @return rLocale set to mapped values, unchanged if no mapping was
285 found. E.g. pass empty Locale to obtain empty SYSTEM locale
288 I18NLANGTAG_DLLPRIVATE
static void convertLanguageToLocaleImpl(
289 LanguageType nLang
, css::lang::Locale
& rLocale
, bool bIgnoreOverride
);
292 I18NLANGTAG_DLLPRIVATE
static css::lang::Locale
lookupFallbackLocale(
293 const css::lang::Locale
& rLocale
);
298 static LanguageType nConfiguredSystemLanguage
;
299 static LanguageType nConfiguredSystemUILanguage
;
301 static LanguageType nConfiguredWesternFallback
;
302 static LanguageType nConfiguredAsianFallback
;
303 static LanguageType nConfiguredComplexFallback
;
305 static LanguageType
getPlatformSystemLanguage();
306 static LanguageType
getPlatformSystemUILanguage();
308 // Substitute LANGUAGE_SYSTEM for LANGUAGE_SYSTEM_DEFAULT and
309 // LANGUAGE_PROCESS_OR_USER_DEFAULT, other values aren't touched.
310 I18NLANGTAG_DLLPRIVATE
static inline LanguageType
simplifySystemLanguages( LanguageType nLang
);
315 inline LanguageType
MsLangId::getSystemLanguage()
317 return getPlatformSystemLanguage();
322 inline LanguageType
MsLangId::getSystemUILanguage()
324 return getPlatformSystemUILanguage();
327 #endif // INCLUDED_I18NLANGTAG_MSLANGID_HXX
329 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */