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_I18NISOLANG_MSLANGID_HXX
21 : #define INCLUDED_I18NISOLANG_MSLANGID_HXX
22 :
23 : #include <sal/config.h>
24 :
25 : #include "i18npool/i18npooldllapi.h"
26 : #include "i18npool/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 I18NISOLANG_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 1 : static inline LanguageType getPrimaryLanguage( LanguageType nLangID)
43 : {
44 1 : 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 rtl::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 :
185 : /** @internal - Return a pointer to the IsoLangEntry of the underlying table,
186 : matching the offset passed by nIndex. Only meaningful for the resource
187 : compiler to build a list of known languages.
188 :
189 : @returns address of IsoLangEntry, or NULL pointer if nIndex exceeds the
190 : table elements' count.
191 : */
192 : static const IsoLangEntry* getIsoLangEntry( size_t nIndex );
193 :
194 : // ---------------------------------------------------------------------------
195 :
196 : /** Encapsulated conversion methods used by LanguageTag and conversions,
197 : not to be used by anything else.
198 : */
199 : class Conversion
200 : {
201 : private:
202 :
203 : friend class LanguageTag;
204 :
205 : friend ::com::sun::star::lang::Locale MsLangId::getFallbackLocale(
206 : const ::com::sun::star::lang::Locale & rLocale );
207 :
208 : friend LanguageType MsLangId::convertUnxByteStringToLanguage(
209 : const rtl::OString& rString );
210 :
211 :
212 : /** Convert a Locale to a LanguageType with handling of an empty
213 : language name designating LANGUAGE_SYSTEM.
214 : */
215 : I18NISOLANG_DLLPRIVATE static LanguageType convertLocaleToLanguage(
216 : const ::com::sun::star::lang::Locale & rLocale );
217 :
218 : /** Used by convertLocaleToLanguage(Locale) */
219 : I18NISOLANG_DLLPRIVATE static LanguageType convertIsoNamesToLanguage(
220 : const rtl::OUString& rLang, const rtl::OUString& rCountry );
221 :
222 :
223 : /** Used by convertUnxByteStringToLanguage(OString) */
224 : I18NISOLANG_DLLPRIVATE static LanguageType convertIsoNamesToLanguage(
225 : const rtl::OString& rLang, const rtl::OString& rCountry );
226 :
227 :
228 : /** Convert a LanguageType to a Locale.
229 :
230 : @param bResolveSystem
231 : If bResolveSystem==true, a LANGUAGE_SYSTEM is resolved.
232 : If bResolveSystem==false, a LANGUAGE_SYSTEM results in an
233 : empty Locale.
234 : */
235 : I18NISOLANG_DLLPRIVATE static ::com::sun::star::lang::Locale convertLanguageToLocale(
236 : LanguageType nLang, bool bResolveSystem );
237 :
238 : /** Convert a LanguageType to a Locale, resolving LANGUAGE_SYSTEM.
239 :
240 : Used by convertLanguageToLocale(LanguageType,bool)
241 : */
242 : I18NISOLANG_DLLPRIVATE static void convertLanguageToLocale(
243 : LanguageType nLang, ::com::sun::star::lang::Locale & rLocale );
244 :
245 : /** Used by convertLanguageToLocale(LanguageType,Locale) */
246 : I18NISOLANG_DLLPRIVATE static void convertLanguageToIsoNames(
247 : LanguageType nLang, rtl::OUString& rLangStr, rtl::OUString& rCountry );
248 :
249 :
250 : I18NISOLANG_DLLPRIVATE static LanguageType lookupFallbackLanguage( LanguageType nLang );
251 :
252 : I18NISOLANG_DLLPRIVATE static ::com::sun::star::lang::Locale lookupFallbackLocale(
253 : const ::com::sun::star::lang::Locale & rLocale );
254 :
255 :
256 : /** Convert a LanguageType to a Locale, resolving LANGUAGE_SYSTEM,
257 : falling back to a default locale if no exact match was found.
258 :
259 : Used by getFallbackLocale(Locale)
260 : */
261 : I18NISOLANG_DLLPRIVATE static ::com::sun::star::lang::Locale convertLanguageToLocaleWithFallback(
262 : LanguageType nLang );
263 :
264 : /** Used by convertLanguageToLocaleWithFallback(LanguageType) */
265 : I18NISOLANG_DLLPRIVATE static ::com::sun::star::lang::Locale lookupFallbackLocale(
266 : LanguageType nLang );
267 : };
268 :
269 : private:
270 :
271 : static LanguageType nConfiguredSystemLanguage;
272 : static LanguageType nConfiguredSystemUILanguage;
273 :
274 : static LanguageType nConfiguredWesternFallback;
275 : static LanguageType nConfiguredAsianFallback;
276 : static LanguageType nConfiguredComplexFallback;
277 :
278 : static LanguageType getPlatformSystemLanguage();
279 : static LanguageType getPlatformSystemUILanguage();
280 :
281 : // Substitute LANGUAGE_SYSTEM for LANGUAGE_SYSTEM_DEFAULT and
282 : // LANGUAGE_PROCESS_OR_USER_DEFAULT, other values aren't touched.
283 : I18NISOLANG_DLLPRIVATE static inline LanguageType simplifySystemLanguages( LanguageType nLang );
284 : };
285 :
286 :
287 : // static
288 190 : inline LanguageType MsLangId::getSystemLanguage()
289 : {
290 190 : return getPlatformSystemLanguage();
291 : }
292 :
293 :
294 : // static
295 64 : inline LanguageType MsLangId::getSystemUILanguage()
296 : {
297 64 : return getPlatformSystemUILanguage();
298 : }
299 :
300 : #endif // INCLUDED_I18NISOLANG_MSLANGID_HXX
301 :
302 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|