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