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