Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_I18NLANGTAG_MSLANGID_HXX
21 : #define INCLUDED_I18NLANGTAG_MSLANGID_HXX
22 :
23 : #include <sal/config.h>
24 :
25 : #include "i18nlangtag/i18nlangtagdllapi.h"
26 : #include "i18nlangtag/lang.h"
27 : #include <com/sun/star/lang/Locale.hpp>
28 :
29 : /** Methods related to Microsoft language IDs. For details about MS-LANGIDs
30 : please see lang.h */
31 : class I18NLANGTAG_DLLPUBLIC MsLangId
32 : {
33 : public:
34 :
35 : /// Create a LangID from a primary and a sublanguage.
36 : static inline LanguageType makeLangID( LanguageType nSubLangId, LanguageType nPriLangId)
37 : {
38 : return (nSubLangId << 10) | nPriLangId;
39 : }
40 :
41 : /// Get the primary language of a LangID.
42 20041 : static inline LanguageType getPrimaryLanguage( LanguageType nLangID)
43 : {
44 20041 : return nLangID & LANGUAGE_MASK_PRIMARY;
45 : }
46 :
47 : /// Get the sublanguage of a LangID.
48 0 : static inline LanguageType getSubLanguage( LanguageType nLangID)
49 : {
50 0 : return (nLangID & ~LANGUAGE_MASK_PRIMARY) >> 10;
51 : }
52 :
53 : /** Language/locale of category LC_CTYPE (on Unix, else the system
54 : language).
55 : Evaluation order: LC_ALL, LC_CTYPE, LANG */
56 : static LanguageType getSystemLanguage();
57 :
58 : /** Language/locale of category LC_MESSAGES (on Unix, else same as
59 : GetSystemLanguage()).
60 : Evaluation order: LANGUAGE, LC_ALL, LC_MESSAGES, LANG */
61 : static LanguageType getSystemUILanguage();
62 :
63 :
64 : /** @short: A proper language/locale if the nLang parameter designates some
65 : special value.
66 :
67 : @descr: NOTE: The "system" values may be overridden by the
68 : application's configuration.
69 :
70 : @returns
71 : case LANGUAGE_PROCESS_OR_USER_DEFAULT : configured or system language
72 : case LANGUAGE_SYSTEM_DEFAULT : configured or system language
73 : case LANGUAGE_SYSTEM : configured or system language
74 : case LANGUAGE_HID_HUMAN_INTERFACE_DEVICE : configured or system UI language
75 : case LANGUAGE_DONTKNOW : LANGUAGE_ENGLISH_US
76 : else: nLang
77 :
78 : In case the configured language is LANGUAGE_SYSTEM, which is also
79 : the initial default, the system language is obtained. In case the
80 : configured or resulting system language is LANGUAGE_DONTKNOW,
81 : LANGUAGE_ENGLISH_US is returned instead.
82 : */
83 : static LanguageType getRealLanguage( LanguageType nLang );
84 :
85 :
86 : // TODO: refactor to LanguageTag? Used only in
87 : // i18npool/source/localedata/localedata.cxx
88 :
89 : /** Get fall-back Locale for Locale with handling of an empty language name
90 : designating the SYSTEM language. Returns the same Locale if an exact
91 : match was found.
92 : */
93 : static ::com::sun::star::lang::Locale getFallbackLocale(
94 : const ::com::sun::star::lang::Locale & rLocale );
95 :
96 :
97 : // TODO: refactor to LanguageTag, used only in
98 : // i18npool/source/isolang/inunx.cxx to convert Unix locale string
99 :
100 : static LanguageType convertUnxByteStringToLanguage( const OString& rString );
101 :
102 :
103 : static LanguageType resolveSystemLanguageByScriptType( LanguageType nLang, sal_Int16 nType );
104 :
105 :
106 : /** Whether locale has a Right-To-Left orientation. */
107 : static bool isRightToLeft( LanguageType nLang );
108 :
109 : /** Whether locale is a CJK locale */
110 : static bool isCJK( LanguageType nLang );
111 :
112 : /** Whether locale is a chinese locale */
113 : static bool isChinese( LanguageType nLang );
114 :
115 : /** Whether locale is a simplified chinese locale */
116 : static bool isSimplifiedChinese( LanguageType nLang );
117 :
118 : /** Whether locale is a traditional chinese locale */
119 : static bool isTraditionalChinese( LanguageType nLang );
120 :
121 : /** Whether locale is a korean locale */
122 : static bool isKorean( LanguageType nLang );
123 :
124 : /** Whether locale is a simplified chinese locale */
125 : static bool isSimplifiedChinese( const ::com::sun::star::lang::Locale & rLocale );
126 :
127 : /** Whether locale is a traditional chinese locale */
128 : static bool isTraditionalChinese( const ::com::sun::star::lang::Locale & rLocale );
129 :
130 : /** Whether locale is one where family name comes first, e.g. Japan, Hungary, Samoa */
131 : static bool isFamilyNameFirst( LanguageType nLang );
132 :
133 : /** Whether there are "forbidden characters at start or end of line" in
134 : this locale. CJK locales.
135 :
136 : @see offapi/com/sun/star/i18n/ForbiddenCharacters.idl
137 : */
138 : static bool hasForbiddenCharacters( LanguageType nLang );
139 :
140 :
141 : /** Whether locale needs input sequence checking. CTL locales. */
142 : static bool needsSequenceChecking( LanguageType nLang );
143 :
144 :
145 : /** Get ::com::sun::star::i18n::ScriptType of locale. */
146 : static sal_Int16 getScriptType( LanguageType nLang );
147 :
148 :
149 : /** Map an obsolete user defined LANGID (see lang.h
150 : LANGUAGE_OBSOLETE_USER_...) to the new value defined by MS in the
151 : meantime.
152 :
153 : Also used to map UI localizations using reserved ISO codes to something
154 : "official" but not identical in order to not pollute documents with
155 : invalid ISO codes.
156 :
157 : @param bUserInterfaceSelection
158 : If TRUE, don't replace such UI-only locale. Only use for
159 : Tools->Options->LanguageSettings->UserInterface listbox.
160 : If FALSE, do replace.
161 : */
162 : static LanguageType getReplacementForObsoleteLanguage( LanguageType nLang,
163 : bool bUserInterfaceSelection = false );
164 :
165 :
166 : /** @ATTENTION: these are _ONLY_ to be called by the application's
167 : configuration! */
168 : static void setConfiguredSystemLanguage( LanguageType nLang );
169 : static void setConfiguredSystemUILanguage( LanguageType nLang );
170 : static void setConfiguredWesternFallback( LanguageType nLang );
171 : static void setConfiguredComplexFallback( LanguageType nLang );
172 : static void setConfiguredAsianFallback( LanguageType nLang );
173 :
174 : // ---------------------------------------------------------------------------
175 :
176 : /** @internal - Access to fields of an element of the simple conversion table.
177 : For resource compiler build environment usage only! */
178 : struct IsoLangEntry
179 : {
180 : LanguageType mnLang;
181 : sal_Char maLangStr[4];
182 : sal_Char maCountry[3];
183 :
184 : /** Obtain a language tag string with '-' separator. */
185 : I18NLANGTAG_DLLPUBLIC OUString getTagString() const;
186 : };
187 :
188 : /** @internal - Return a pointer to the IsoLangEntry of the underlying table,
189 : matching the offset passed by nIndex. Only meaningful for the resource
190 : compiler to build a list of known languages.
191 :
192 : @returns address of IsoLangEntry, or NULL pointer if nIndex exceeds the
193 : table elements' count.
194 : */
195 : static const IsoLangEntry* getIsoLangEntry( size_t nIndex );
196 :
197 : // ---------------------------------------------------------------------------
198 :
199 : /** Encapsulated conversion methods used by LanguageTag and conversions,
200 : not to be used by anything else.
201 : */
202 : class Conversion
203 : {
204 : private:
205 :
206 : friend class LanguageTag;
207 :
208 : friend ::com::sun::star::lang::Locale MsLangId::getFallbackLocale(
209 : const ::com::sun::star::lang::Locale & rLocale );
210 :
211 : friend LanguageType MsLangId::convertUnxByteStringToLanguage(
212 : const OString& rString );
213 :
214 :
215 : /** Convert a Locale to a LanguageType with handling of an empty
216 : language name designating LANGUAGE_SYSTEM.
217 : */
218 : I18NLANGTAG_DLLPRIVATE static LanguageType convertLocaleToLanguage(
219 : const ::com::sun::star::lang::Locale & rLocale );
220 :
221 : /** Convert x-... privateuse, used by convertLocaleToLanguage(Locale) */
222 : I18NLANGTAG_DLLPRIVATE static LanguageType convertPrivateUseToLanguage(
223 : const OUString& rPriv );
224 :
225 : /** Used by convertLocaleToLanguage(Locale) */
226 : I18NLANGTAG_DLLPRIVATE static LanguageType convertIsoNamesToLanguage(
227 : const OUString& rLang, const OUString& rCountry );
228 :
229 :
230 : /** Used by convertUnxByteStringToLanguage(OString) */
231 : I18NLANGTAG_DLLPRIVATE static LanguageType convertIsoNamesToLanguage(
232 : const OString& rLang, const OString& rCountry );
233 :
234 :
235 : /** Convert a LanguageType to a Locale.
236 :
237 : @param bResolveSystem
238 : If bResolveSystem==true, a LANGUAGE_SYSTEM is resolved.
239 : If bResolveSystem==false, a LANGUAGE_SYSTEM results in an
240 : empty Locale.
241 : */
242 : I18NLANGTAG_DLLPRIVATE static ::com::sun::star::lang::Locale convertLanguageToLocale(
243 : LanguageType nLang, bool bResolveSystem );
244 :
245 : /** Convert a LanguageType to a Locale, resolving LANGUAGE_SYSTEM.
246 :
247 : Used by convertLanguageToLocale(LanguageType,bool)
248 : */
249 : I18NLANGTAG_DLLPRIVATE static void convertLanguageToLocale(
250 : LanguageType nLang, ::com::sun::star::lang::Locale & rLocale );
251 :
252 : /** Used by convertLanguageToLocale(LanguageType,Locale) */
253 : I18NLANGTAG_DLLPRIVATE static void convertLanguageToIsoNames(
254 : LanguageType nLang, OUString& rLangStr, OUString& rCountry );
255 :
256 :
257 : I18NLANGTAG_DLLPRIVATE static LanguageType lookupFallbackLanguage( LanguageType nLang );
258 :
259 : I18NLANGTAG_DLLPRIVATE static ::com::sun::star::lang::Locale lookupFallbackLocale(
260 : const ::com::sun::star::lang::Locale & rLocale );
261 :
262 :
263 : /** Convert a LanguageType to a Locale, resolving LANGUAGE_SYSTEM,
264 : falling back to a default locale if no exact match was found.
265 :
266 : Used by getFallbackLocale(Locale)
267 : */
268 : I18NLANGTAG_DLLPRIVATE static ::com::sun::star::lang::Locale convertLanguageToLocaleWithFallback(
269 : LanguageType nLang );
270 :
271 : /** Used by convertLanguageToLocaleWithFallback(LanguageType) */
272 : I18NLANGTAG_DLLPRIVATE static ::com::sun::star::lang::Locale lookupFallbackLocale(
273 : LanguageType nLang );
274 : };
275 :
276 : private:
277 :
278 : static LanguageType nConfiguredSystemLanguage;
279 : static LanguageType nConfiguredSystemUILanguage;
280 :
281 : static LanguageType nConfiguredWesternFallback;
282 : static LanguageType nConfiguredAsianFallback;
283 : static LanguageType nConfiguredComplexFallback;
284 :
285 : static LanguageType getPlatformSystemLanguage();
286 : static LanguageType getPlatformSystemUILanguage();
287 :
288 : // Substitute LANGUAGE_SYSTEM for LANGUAGE_SYSTEM_DEFAULT and
289 : // LANGUAGE_PROCESS_OR_USER_DEFAULT, other values aren't touched.
290 : I18NLANGTAG_DLLPRIVATE static inline LanguageType simplifySystemLanguages( LanguageType nLang );
291 : };
292 :
293 :
294 : // static
295 16268 : inline LanguageType MsLangId::getSystemLanguage()
296 : {
297 16268 : return getPlatformSystemLanguage();
298 : }
299 :
300 :
301 : // static
302 220 : inline LanguageType MsLangId::getSystemUILanguage()
303 : {
304 220 : return getPlatformSystemUILanguage();
305 : }
306 :
307 : #endif // INCLUDED_I18NLANGTAG_MSLANGID_HXX
308 :
309 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|