xref: /aoo42x/main/i18npool/inc/i18npool/mslangid.hxx (revision f7bd9df4)
1*f7bd9df4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f7bd9df4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f7bd9df4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f7bd9df4SAndrew Rist  * distributed with this work for additional information
6*f7bd9df4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f7bd9df4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f7bd9df4SAndrew Rist  * "License"); you may not use this file except in compliance
9*f7bd9df4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f7bd9df4SAndrew Rist  *
11*f7bd9df4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f7bd9df4SAndrew Rist  *
13*f7bd9df4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f7bd9df4SAndrew Rist  * software distributed under the License is distributed on an
15*f7bd9df4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f7bd9df4SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f7bd9df4SAndrew Rist  * specific language governing permissions and limitations
18*f7bd9df4SAndrew Rist  * under the License.
19*f7bd9df4SAndrew Rist  *
20*f7bd9df4SAndrew Rist  *************************************************************/
21*f7bd9df4SAndrew Rist 
22*f7bd9df4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef INCLUDED_I18NPOOL_MSLANGID_HXX
25cdf0e10cSrcweir #define INCLUDED_I18NPOOL_MSLANGID_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <sal/config.h>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #ifndef INCLUDED_I18NPOOL_DLLAPI_H
30cdf0e10cSrcweir #include "i18npool/i18npooldllapi.h"
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #include "i18npool/lang.h"
33cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 
36cdf0e10cSrcweir /** Methods related to Microsoft language IDs. For details about MS-LANGIDs
37cdf0e10cSrcweir     please see lang.h */
38cdf0e10cSrcweir class I18NPOOL_DLLPUBLIC MsLangId
39cdf0e10cSrcweir {
40cdf0e10cSrcweir public:
41cdf0e10cSrcweir 
42cdf0e10cSrcweir     /// Create a LangID from a primary and a sublanguage.
makeLangID(LanguageType nSubLangId,LanguageType nPriLangId)43cdf0e10cSrcweir     static inline LanguageType makeLangID( LanguageType nSubLangId, LanguageType nPriLangId)
44cdf0e10cSrcweir     {
45cdf0e10cSrcweir         return (nSubLangId << 10) | nPriLangId;
46cdf0e10cSrcweir     }
47cdf0e10cSrcweir 
48cdf0e10cSrcweir     /// Get the primary language of a LangID.
getPrimaryLanguage(LanguageType nLangID)49cdf0e10cSrcweir     static inline LanguageType getPrimaryLanguage( LanguageType nLangID)
50cdf0e10cSrcweir     {
51cdf0e10cSrcweir         return nLangID & LANGUAGE_MASK_PRIMARY;
52cdf0e10cSrcweir     }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir     /// Get the sublanguage of a LangID.
getSubLanguage(LanguageType nLangID)55cdf0e10cSrcweir     static inline LanguageType getSubLanguage( LanguageType nLangID)
56cdf0e10cSrcweir     {
57cdf0e10cSrcweir         return (nLangID & ~LANGUAGE_MASK_PRIMARY) >> 10;
58cdf0e10cSrcweir     }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     /** Language/locale of category LC_CTYPE (on Unix, else the system
61cdf0e10cSrcweir         language).
62cdf0e10cSrcweir         Evaluation order: LC_ALL, LC_CTYPE, LANG */
63cdf0e10cSrcweir     static LanguageType getSystemLanguage();
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     /** Language/locale of category LC_MESSAGES (on Unix, else same as
66cdf0e10cSrcweir         GetSystemLanguage()).
67cdf0e10cSrcweir         Evaluation order: LANGUAGE, LC_ALL, LC_MESSAGES, LANG */
68cdf0e10cSrcweir     static LanguageType getSystemUILanguage();
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     /** @short: A proper language/locale if the nLang parameter designates some
72cdf0e10cSrcweir                 special value.
73cdf0e10cSrcweir 
74cdf0e10cSrcweir         @descr: NOTE: The "system" values may be overridden by the
75cdf0e10cSrcweir                 application's configuration. If you need to access the system
76cdf0e10cSrcweir                 values use <method>getRealLanguageWithoutConfig()</method>
77cdf0e10cSrcweir                 instead.
78cdf0e10cSrcweir 
79cdf0e10cSrcweir         @returns
80cdf0e10cSrcweir             case LANGUAGE_PROCESS_OR_USER_DEFAULT : configured or system language
81cdf0e10cSrcweir             case LANGUAGE_SYSTEM_DEFAULT :          configured or system language
82cdf0e10cSrcweir             case LANGUAGE_SYSTEM :                  configured or system language
83cdf0e10cSrcweir             case LANGUAGE_NONE :                    configured or system UI language
84cdf0e10cSrcweir             case LANGUAGE_DONTKNOW :                LANGUAGE_ENGLISH_US
85cdf0e10cSrcweir             else: nLang
86cdf0e10cSrcweir 
87cdf0e10cSrcweir             In case the configured language is LANGUAGE_SYSTEM, which is also
88cdf0e10cSrcweir             the initial default, the system language is obtained. In case the
89cdf0e10cSrcweir             configured or resulting system language is LANGUAGE_DONTKNOW,
90cdf0e10cSrcweir             LANGUAGE_ENGLISH_US is returned instead.
91cdf0e10cSrcweir       */
92cdf0e10cSrcweir     static LanguageType getRealLanguage( LanguageType nLang );
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     /** @short: Convert a LanguageType to a Locale, resolving LANGUAGE_SYSTEM.
96cdf0e10cSrcweir 
97cdf0e10cSrcweir         @ATTENTION: A round trip convertLanguageToLocale(
98cdf0e10cSrcweir                 convertLocaleToLanguage( ...)) is NOT possible because this
99cdf0e10cSrcweir                 method substitutes LANGUAGE_SYSTEM and the like. If round-trip
100cdf0e10cSrcweir                 is desired, you MUST use convertLanguageToLocale( ..., false)
101cdf0e10cSrcweir                 instead.
102cdf0e10cSrcweir      */
103cdf0e10cSrcweir     static void convertLanguageToLocale( LanguageType nLang,
104cdf0e10cSrcweir             ::com::sun::star::lang::Locale & rLocale );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     /** @short: Convert a LanguageType to a Locale with handling of
108cdf0e10cSrcweir                 getRealLanguage().
109cdf0e10cSrcweir 
110cdf0e10cSrcweir         @descr: If bResolveSystem==true don't use to convert a Language to a
111cdf0e10cSrcweir                 Locale for file storage because it substitutes LANGUAGE_SYSTEM
112cdf0e10cSrcweir                 and LANGUAGE_NONE and similar, use only at runtime! If
113cdf0e10cSrcweir                 bResolveSystem==false a LANGUAGE_SYSTEM results in an empty
114cdf0e10cSrcweir                 Locale.
115cdf0e10cSrcweir 
116cdf0e10cSrcweir         @ATTENTION: A round trip convertLanguageToLocale(
117cdf0e10cSrcweir                 convertLocaleToLanguage( ...)) using the default parameter is
118cdf0e10cSrcweir                 NOT possible because this method
119cdf0e10cSrcweir                 substitutes LANGUAGE_SYSTEM and the like. If round-trip is
120cdf0e10cSrcweir                 desired, you MUST use convertLanguageToLocale( ..., false)
121cdf0e10cSrcweir                 instead.
122cdf0e10cSrcweir       */
123cdf0e10cSrcweir     static ::com::sun::star::lang::Locale convertLanguageToLocale(
124cdf0e10cSrcweir             LanguageType nLang, bool bResolveSystem = true );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     /** Convert a Locale to a LanguageType with handling of an empty language
128cdf0e10cSrcweir         name designating the SYSTEM language.
129cdf0e10cSrcweir       */
130cdf0e10cSrcweir     static LanguageType convertLocaleToLanguage( const ::com::sun::star::lang::Locale & rLocale );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     /** Convert a LanguageType to a Locale, resolving LANGUAGE_SYSTEM, falling
134cdf0e10cSrcweir         back to a default locale if no exact match was found.
135cdf0e10cSrcweir      */
136cdf0e10cSrcweir     static ::com::sun::star::lang::Locale convertLanguageToLocaleWithFallback( LanguageType nLang );
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     /** Convert a Locale to a LanguageType with handling of an empty language
140cdf0e10cSrcweir         name designating the SYSTEM language, falling back to a default locale
141cdf0e10cSrcweir         if no exact match was found.
142cdf0e10cSrcweir       */
143cdf0e10cSrcweir     static LanguageType convertLocaleToLanguageWithFallback(
144cdf0e10cSrcweir             const ::com::sun::star::lang::Locale & rLocale );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     /** Get fall-back Locale for Locale with handling of an empty language name
148cdf0e10cSrcweir         designating the SYSTEM language. Returns the same Locale if an exact
149cdf0e10cSrcweir         match was found.
150cdf0e10cSrcweir       */
151cdf0e10cSrcweir     static ::com::sun::star::lang::Locale getFallbackLocale(
152cdf0e10cSrcweir             const ::com::sun::star::lang::Locale & rLocale );
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     /** Get fall-back LanguageType for LanguageType, resolving LANGUAGE_SYSTEM.
156cdf0e10cSrcweir         Returns the same LanguageType if an exact match was found.
157cdf0e10cSrcweir       */
158cdf0e10cSrcweir     static LanguageType getFallbackLanguage( LanguageType nLang );
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     // -----------------------------
162cdf0e10cSrcweir     // - ConvertLanguageToIsoNames -
163cdf0e10cSrcweir     // -----------------------------
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     static void convertLanguageToIsoNames( LanguageType nLang,
166cdf0e10cSrcweir             rtl::OUString& rLangStr, rtl::OUString& rCountry );
167cdf0e10cSrcweir     static void convertLanguageToIsoNames( LanguageType nLang,
168cdf0e10cSrcweir             rtl::OString& rLangStr, rtl::OString& rCountry );
169cdf0e10cSrcweir     static rtl::OUString convertLanguageToIsoString( LanguageType nLang,
170cdf0e10cSrcweir             sal_Unicode cSep = '-' );
171cdf0e10cSrcweir     static rtl::OString convertLanguageToIsoByteString( LanguageType nLang,
172cdf0e10cSrcweir             sal_Char cSep = '-' );
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     // -----------------------------
175cdf0e10cSrcweir     // - ConvertIsoNamesToLanguage -
176cdf0e10cSrcweir     // -----------------------------
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     static LanguageType convertIsoNamesToLanguage( const rtl::OUString& rLang,
179cdf0e10cSrcweir             const rtl::OUString& rCountry );
180cdf0e10cSrcweir     static LanguageType convertIsoNamesToLanguage( const rtl::OString& rLang,
181cdf0e10cSrcweir             const rtl::OString& rCountry );
182cdf0e10cSrcweir     static LanguageType convertIsoStringToLanguage(
183cdf0e10cSrcweir             const rtl::OUString& rString, sal_Unicode cSep = '-' );
184cdf0e10cSrcweir     static LanguageType convertIsoByteStringToLanguage(
185cdf0e10cSrcweir             const rtl::OString& rString, sal_Char cSep = '-' );
186cdf0e10cSrcweir     static LanguageType convertUnxByteStringToLanguage(
187cdf0e10cSrcweir             const rtl::OString& rString );
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 
190cdf0e10cSrcweir     /** @short: A real language/locale if the nLang parameter designates some
191cdf0e10cSrcweir                 special value.
192cdf0e10cSrcweir 
193cdf0e10cSrcweir         @descr: NOTE: This is a raw interface to the system and does not take
194cdf0e10cSrcweir                 any application configuration into account. If that is wanted,
195cdf0e10cSrcweir                 which is most likely, use <method>getRealLanguage()</method>
196cdf0e10cSrcweir                 instead.
197cdf0e10cSrcweir 
198cdf0e10cSrcweir         @returns
199cdf0e10cSrcweir             case LANGUAGE_PROCESS_OR_USER_DEFAULT : getSystemLanguage()
200cdf0e10cSrcweir             case LANGUAGE_SYSTEM_DEFAULT :          getSystemLanguage()
201cdf0e10cSrcweir             case LANGUAGE_SYSTEM :                  getSystemLanguage()
202cdf0e10cSrcweir             case LANGUAGE_NONE :                    getSystemUILanguage()
203cdf0e10cSrcweir             case LANGUAGE_DONTKNOW :                LANGUAGE_ENGLISH_US
204cdf0e10cSrcweir             else: nLang
205cdf0e10cSrcweir 
206cdf0e10cSrcweir             In case getSystemLanguage() or getSystemUILanguage() returned
207cdf0e10cSrcweir             LANGUAGE_DONTKNOW, LANGUAGE_ENGLISH_US is returned instead.
208cdf0e10cSrcweir       */
209cdf0e10cSrcweir     static LanguageType getRealLanguageWithoutConfig( LanguageType nLang );
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     static LanguageType resolveSystemLanguageByScriptType( LanguageType nLang, sal_Int16 nType );
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 
215cdf0e10cSrcweir     /** Whether locale has a Right-To-Left orientation. */
216cdf0e10cSrcweir     static bool isRightToLeft( LanguageType nLang );
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 
219cdf0e10cSrcweir     /** Whether there are "forbidden characters at start or end of line" in
220cdf0e10cSrcweir         this locale. CJK locales.
221cdf0e10cSrcweir 
222cdf0e10cSrcweir         @see offapi/com/sun/star/i18n/ForbiddenCharacters.idl
223cdf0e10cSrcweir       */
224cdf0e10cSrcweir     static bool hasForbiddenCharacters( LanguageType nLang );
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     /** Whether locale needs input sequence checking. CTL locales. */
228cdf0e10cSrcweir     static bool needsSequenceChecking( LanguageType nLang );
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     /** Get ::com::sun::star::i18n::ScriptType of locale. */
232cdf0e10cSrcweir     static sal_Int16 getScriptType( LanguageType nLang );
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 
235cdf0e10cSrcweir     /** Map an obsolete user defined LANGID (see lang.h
236cdf0e10cSrcweir         LANGUAGE_OBSOLETE_USER_...) to the new value defined by MS in the
237cdf0e10cSrcweir         meantime. */
238cdf0e10cSrcweir     static LanguageType getReplacementForObsoleteLanguage( LanguageType nLang );
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 
241cdf0e10cSrcweir     /** @ATTENTION: these are _ONLY_ to be called by the application's
242cdf0e10cSrcweir         configuration! */
243cdf0e10cSrcweir     static void setConfiguredSystemLanguage( LanguageType nLang );
244cdf0e10cSrcweir     static void setConfiguredSystemUILanguage( LanguageType nLang );
245cdf0e10cSrcweir     static void setConfiguredWesternFallback( LanguageType nLang );
246cdf0e10cSrcweir     static void setConfiguredComplexFallback( LanguageType nLang );
247cdf0e10cSrcweir     static void setConfiguredAsianFallback( LanguageType nLang );
248cdf0e10cSrcweir 
249cdf0e10cSrcweir // ---------------------------------------------------------------------------
250cdf0e10cSrcweir 
251cdf0e10cSrcweir     /** @internal - Access to fields of an element of the simple conversion table.
252cdf0e10cSrcweir         For resource compiler build environment usage only! */
253cdf0e10cSrcweir     struct IsoLangEntry
254cdf0e10cSrcweir     {
255cdf0e10cSrcweir         LanguageType  mnLang;
256cdf0e10cSrcweir         sal_Char      maLangStr[4];
257cdf0e10cSrcweir         sal_Char      maCountry[3];
258cdf0e10cSrcweir     };
259cdf0e10cSrcweir 
260cdf0e10cSrcweir     /** @internal - Return a pointer to the IsoLangEntry of the underlying table,
261cdf0e10cSrcweir         matching the offset passed by nIndex. Only meaningful for the resource
262cdf0e10cSrcweir         compiler to build a list of known languages.
263cdf0e10cSrcweir 
264cdf0e10cSrcweir         @returns address of IsoLangEntry, or NULL pointer if nIndex exceeds the
265cdf0e10cSrcweir         table elements' count.
266cdf0e10cSrcweir      */
267cdf0e10cSrcweir     static const IsoLangEntry* getIsoLangEntry( size_t nIndex );
268cdf0e10cSrcweir 
269cdf0e10cSrcweir // ---------------------------------------------------------------------------
270cdf0e10cSrcweir 
271cdf0e10cSrcweir private:
272cdf0e10cSrcweir 
273cdf0e10cSrcweir     static LanguageType         nConfiguredSystemLanguage;
274cdf0e10cSrcweir     static LanguageType         nConfiguredSystemUILanguage;
275cdf0e10cSrcweir 
276cdf0e10cSrcweir     static LanguageType         nConfiguredWesternFallback;
277cdf0e10cSrcweir     static LanguageType         nConfiguredAsianFallback;
278cdf0e10cSrcweir     static LanguageType         nConfiguredComplexFallback;
279cdf0e10cSrcweir 
280cdf0e10cSrcweir     static LanguageType getPlatformSystemLanguage();
281cdf0e10cSrcweir     static LanguageType getPlatformSystemUILanguage();
282cdf0e10cSrcweir 
283cdf0e10cSrcweir     // Substitute LANGUAGE_SYSTEM for LANGUAGE_SYSTEM_DEFAULT and
284cdf0e10cSrcweir     // LANGUAGE_PROCESS_OR_USER_DEFAULT, other values aren't touched.
285cdf0e10cSrcweir     I18NPOOL_DLLPRIVATE static inline LanguageType simplifySystemLanguages( LanguageType nLang );
286cdf0e10cSrcweir 
287cdf0e10cSrcweir     // Several locale lookups with fall-back
288cdf0e10cSrcweir     I18NPOOL_DLLPRIVATE static LanguageType lookupFallbackLanguage( LanguageType nLang );
289cdf0e10cSrcweir     I18NPOOL_DLLPRIVATE static LanguageType lookupFallbackLanguage(
290cdf0e10cSrcweir             const ::com::sun::star::lang::Locale & rLocale );
291cdf0e10cSrcweir     I18NPOOL_DLLPRIVATE static ::com::sun::star::lang::Locale lookupFallbackLocale( LanguageType nLang );
292cdf0e10cSrcweir     I18NPOOL_DLLPRIVATE static ::com::sun::star::lang::Locale lookupFallbackLocale(
293cdf0e10cSrcweir             const ::com::sun::star::lang::Locale & rLocale );
294cdf0e10cSrcweir };
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 
297cdf0e10cSrcweir // static
getSystemLanguage()298cdf0e10cSrcweir inline LanguageType MsLangId::getSystemLanguage()
299cdf0e10cSrcweir {
300cdf0e10cSrcweir     return getPlatformSystemLanguage();
301cdf0e10cSrcweir }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir 
304cdf0e10cSrcweir // static
getSystemUILanguage()305cdf0e10cSrcweir inline LanguageType MsLangId::getSystemUILanguage()
306cdf0e10cSrcweir {
307cdf0e10cSrcweir     return getPlatformSystemUILanguage();
308cdf0e10cSrcweir }
309cdf0e10cSrcweir 
310cdf0e10cSrcweir #endif // INCLUDED_I18NPOOL_MSLANGID_HXX
311