LCOV - code coverage report
Current view: top level - include/i18nlangtag - mslangid.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 12 12 100.0 %
Date: 2015-06-13 12:38:46 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

          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             : #include <vector>
      29             : 
      30             : struct IsoLanguageCountryEntry;
      31             : struct IsoLanguageScriptCountryEntry;
      32             : 
      33             : /** Methods related to Microsoft language IDs. For details about MS-LANGIDs
      34             :     please see lang.h */
      35             : class I18NLANGTAG_DLLPUBLIC MsLangId
      36             : {
      37             : public:
      38             : 
      39             :     /// Create a LangID from a primary and a sublanguage.
      40          13 :     static inline LanguageType makeLangID( LanguageType nSubLangId, LanguageType nPriLangId)
      41             :     {
      42          13 :         return (nSubLangId << 10) | nPriLangId;
      43             :     }
      44             : 
      45             :     /// Get the primary language of a LangID.
      46      525713 :     static inline LanguageType getPrimaryLanguage( LanguageType nLangID)
      47             :     {
      48      525713 :         return nLangID & LANGUAGE_MASK_PRIMARY;
      49             :     }
      50             : 
      51             :     /// Get the sublanguage of a LangID.
      52      203577 :     static inline LanguageType getSubLanguage( LanguageType nLangID)
      53             :     {
      54      203577 :         return (nLangID & ~LANGUAGE_MASK_PRIMARY) >> 10;
      55             :     }
      56             : 
      57             :     /** Language/locale of category LC_CTYPE (on Unix, else the system
      58             :         language).
      59             :         Evaluation order: LC_ALL, LC_CTYPE, LANG */
      60             :     static LanguageType getSystemLanguage();
      61             : 
      62             :     /** Language/locale of category LC_MESSAGES (on Unix, else same as
      63             :         GetSystemLanguage()).
      64             :         Evaluation order: LANGUAGE, LC_ALL, LC_MESSAGES, LANG */
      65             :     static LanguageType getSystemUILanguage();
      66             : 
      67             : 
      68             :     /** @short: A proper language/locale if the nLang parameter designates some
      69             :                 special value.
      70             : 
      71             :         @descr: NOTE: The "system" values may be overridden by the
      72             :                 application's configuration.
      73             : 
      74             :         @returns
      75             :             case LANGUAGE_PROCESS_OR_USER_DEFAULT :     configured or system language
      76             :             case LANGUAGE_SYSTEM_DEFAULT :              configured or system language
      77             :             case LANGUAGE_SYSTEM :                      configured or system language
      78             :             case LANGUAGE_HID_HUMAN_INTERFACE_DEVICE :  configured or system UI language
      79             :             case LANGUAGE_DONTKNOW :                    LANGUAGE_ENGLISH_US
      80             :             else: nLang
      81             : 
      82             :             In case the configured language is LANGUAGE_SYSTEM, which is also
      83             :             the initial default, the system language is obtained. In case the
      84             :             configured or resulting system language is LANGUAGE_DONTKNOW,
      85             :             LANGUAGE_ENGLISH_US is returned instead.
      86             :       */
      87             :     static LanguageType getRealLanguage( LanguageType nLang );
      88             : 
      89             : 
      90             :     // TODO: refactor to LanguageTag? Used only in
      91             :     // i18npool/source/localedata/localedata.cxx
      92             : 
      93             :     /** Get fall-back Locale for Locale with handling of an empty language name
      94             :         designating the SYSTEM language. Returns the same Locale if an exact
      95             :         match was found.
      96             :       */
      97             :     static ::com::sun::star::lang::Locale getFallbackLocale(
      98             :             const ::com::sun::star::lang::Locale & rLocale );
      99             : 
     100             : 
     101             :     // TODO: refactor to LanguageTag, used only in
     102             :     // i18npool/source/isolang/inunx.cxx to convert Unix locale string
     103             : 
     104             :     static LanguageType convertUnxByteStringToLanguage( const OString& rString );
     105             : 
     106             : 
     107             :     static LanguageType resolveSystemLanguageByScriptType( LanguageType nLang, sal_Int16 nType );
     108             : 
     109             : 
     110             :     /** Whether locale has a Right-To-Left orientation for text. */
     111             :     static bool isRightToLeft( LanguageType nLang );
     112             : 
     113             :     /** Whether locale has a Right-To-Left orientation for math. */
     114             :     static bool isRightToLeftMath( LanguageType nLang );
     115             : 
     116             :     /** Whether locale is a CJK locale */
     117             :     static bool isCJK( LanguageType nLang );
     118             : 
     119             :     /** Whether locale is a chinese locale */
     120             :     static bool isChinese( LanguageType nLang );
     121             : 
     122             :     /** Whether locale is a simplified chinese locale */
     123             :     static bool isSimplifiedChinese( LanguageType nLang );
     124             : 
     125             :     /** Whether locale is a traditional chinese locale */
     126             :     static bool isTraditionalChinese( LanguageType nLang );
     127             : 
     128             :     /** Whether locale is a korean locale */
     129             :     static bool isKorean( LanguageType nLang );
     130             : 
     131             :     /** Whether locale is a simplified chinese locale */
     132             :     static bool isSimplifiedChinese( const ::com::sun::star::lang::Locale & rLocale );
     133             : 
     134             :     /** Whether locale is a traditional chinese locale */
     135             :     static bool isTraditionalChinese( const ::com::sun::star::lang::Locale & rLocale );
     136             : 
     137             :     /** Whether locale is one where family name comes first, e.g. Japan, Hungary, Samoa */
     138             :     static bool isFamilyNameFirst( LanguageType nLang );
     139             : 
     140             :     /** Whether there are "forbidden characters at start or end of line" in
     141             :         this locale. CJK locales.
     142             : 
     143             :         @see offapi/com/sun/star/i18n/ForbiddenCharacters.idl
     144             :       */
     145             :     static bool hasForbiddenCharacters( LanguageType nLang );
     146             : 
     147             : 
     148             :     /** Whether locale needs input sequence checking. CTL locales. */
     149             :     static bool needsSequenceChecking( LanguageType nLang );
     150             : 
     151             : 
     152             :     /** Get ::com::sun::star::i18n::ScriptType of locale. */
     153             :     static sal_Int16 getScriptType( LanguageType nLang );
     154             : 
     155             :     /** Whether locale is "Western" but not Latin script, e.g. Cyrillic or Greek. */
     156             :     static bool isNonLatinWestern( LanguageType nLang );
     157             : 
     158             : 
     159             :     /** Map an obsolete user defined LANGID (see lang.h
     160             :         LANGUAGE_OBSOLETE_USER_...) to the new value defined by MS in the
     161             :         meantime.
     162             : 
     163             :         Also used to map UI localizations using reserved ISO codes to something
     164             :         "official" but not identical in order to not pollute documents with
     165             :         invalid ISO codes.
     166             : 
     167             :         @param bUserInterfaceSelection
     168             :             If TRUE, don't replace such UI-only locale. Only use for
     169             :                      Tools->Options->LanguageSettings->UserInterface listbox.
     170             :             If FALSE, do replace.
     171             :      */
     172             :     static LanguageType getReplacementForObsoleteLanguage( LanguageType nLang,
     173             :             bool bUserInterfaceSelection = false );
     174             : 
     175             :     /** Whether locale is legacy, i.e. country ot confederation doesn't exist anymore. */
     176             :     static bool isLegacy( LanguageType nLang );
     177             : 
     178             : 
     179             :     /** @ATTENTION: these are _ONLY_ to be called by the application's
     180             :         configuration! */
     181             :     static void setConfiguredSystemUILanguage( LanguageType nLang );
     182             :     static void setConfiguredWesternFallback( LanguageType nLang );
     183             :     static void setConfiguredComplexFallback( LanguageType nLang );
     184             :     static void setConfiguredAsianFallback( LanguageType nLang );
     185             : 
     186             : 
     187             : 
     188             :     /** Encapsulated methods that shall only be accessed through
     189             :         class LanguageTag.
     190             :      */
     191             :     class LanguageTagAccess
     192             :     {
     193             :     private:
     194             : 
     195             :         friend class LanguageTag;
     196             : 
     197             :         /** Configured system locale needs always be synchronized with
     198             :             LanguageTag's system locale.
     199             :          */
     200             :         I18NLANGTAG_DLLPRIVATE static void setConfiguredSystemLanguage( LanguageType nLang );
     201             :     };
     202             : 
     203             : 
     204             : 
     205     2393595 :     struct LanguagetagMapping
     206             :     {
     207             :         OUString        maBcp47;
     208             :         LanguageType    mnLang;
     209             : 
     210      357975 :         LanguagetagMapping( const OUString & rBcp47, LanguageType nLang ) : maBcp47(rBcp47), mnLang(nLang) {}
     211             :     };
     212             : 
     213             :     /** @internal - Obtain a list of known locales (i.e. those that have a
     214             :         defined mapping between MS-LangID and ISO codes or tags) as BCP 47
     215             :         language tag strings.
     216             :      */
     217             :     static ::std::vector< LanguagetagMapping > getDefinedLanguagetags();
     218             : 
     219             : 
     220             : 
     221             :     /** Encapsulated conversion methods used by LanguageTag and conversions,
     222             :         not to be used by anything else.
     223             :      */
     224             :     class Conversion
     225             :     {
     226             :     private:
     227             : 
     228             :         friend class LanguageTag;
     229             :         friend class LanguageTagImpl;
     230             : 
     231             :         friend ::com::sun::star::lang::Locale MsLangId::getFallbackLocale(
     232             :                 const ::com::sun::star::lang::Locale & rLocale );
     233             : 
     234             :         friend LanguageType MsLangId::convertUnxByteStringToLanguage(
     235             :                 const OString& rString );
     236             : 
     237             : 
     238             :         /** Convert a Locale to a LanguageType with handling of an empty
     239             :             language name designating LANGUAGE_SYSTEM.
     240             :           */
     241             :         I18NLANGTAG_DLLPRIVATE static LanguageType convertLocaleToLanguage(
     242             :                 const ::com::sun::star::lang::Locale & rLocale );
     243             : 
     244             :         /** Used by convertLocaleToLanguage(Locale) */
     245             :         I18NLANGTAG_DLLPRIVATE static LanguageType convertLocaleToLanguageImpl(
     246             :                 const ::com::sun::star::lang::Locale & rLocale );
     247             : 
     248             :         /** Convert x-... privateuse, used by convertLocaleToLanguageImpl(Locale) */
     249             :         I18NLANGTAG_DLLPRIVATE static LanguageType convertPrivateUseToLanguage(
     250             :                 const OUString& rPriv );
     251             : 
     252             :         /** Used by LanguageTag::canonicalize() */
     253             :         I18NLANGTAG_DLLPRIVATE static ::com::sun::star::lang::Locale getOverride(
     254             :                 const ::com::sun::star::lang::Locale & rLocale );
     255             : 
     256             :         /** Used by convertLocaleToLanguage(Locale) */
     257             :         I18NLANGTAG_DLLPRIVATE static LanguageType convertIsoNamesToLanguage(
     258             :                 const OUString& rLang, const OUString& rCountry );
     259             : 
     260             : 
     261             :         /** Used by convertUnxByteStringToLanguage(OString) */
     262             :         I18NLANGTAG_DLLPRIVATE static LanguageType convertIsoNamesToLanguage(
     263             :                 const OString& rLang, const OString& rCountry );
     264             : 
     265             : 
     266             :         /** Used by lookupFallbackLocale(Locale) */
     267             :         I18NLANGTAG_DLLPRIVATE static com::sun::star::lang::Locale getLocale(
     268             :                 const IsoLanguageCountryEntry * pEntry );
     269             : 
     270             :         /** Used by lookupFallbackLocale(Locale) */
     271             :         I18NLANGTAG_DLLPRIVATE static com::sun::star::lang::Locale getLocale(
     272             :                 const IsoLanguageScriptCountryEntry * pEntry );
     273             : 
     274             : 
     275             :         /** Convert a LanguageType to a Locale.
     276             : 
     277             :             @param bResolveSystem
     278             :                    If bResolveSystem==true, a LANGUAGE_SYSTEM is resolved.
     279             :                    If bResolveSystem==false, a LANGUAGE_SYSTEM results in an
     280             :                    empty Locale.
     281             :           */
     282             :         I18NLANGTAG_DLLPRIVATE static ::com::sun::star::lang::Locale convertLanguageToLocale(
     283             :                 LanguageType nLang, bool bResolveSystem );
     284             : 
     285             :         /** Used by convertLanguageToLocale(LanguageType,bool) and
     286             :             getLocale(IsoLanguageCountryEntry*) and
     287             :             getLocale(IsoLanguageScriptCountryEntry)
     288             : 
     289             :             @param  bIgnoreOverride
     290             :                     If bIgnoreOverride==true, a matching entry is used even if
     291             :                     mnOverride is set, for conversion to an even outdated tag.
     292             :                     If bIgnoreOverride==false, a matching entry is skipped if
     293             :                     mnOverride is set and instead the override is followed.
     294             : 
     295             :             @return rLocale set to mapped values, unchanged if no mapping was
     296             :                     found. E.g. pass empty Locale to obtain empty SYSTEM locale
     297             :                     for that case.
     298             :          */
     299             :         I18NLANGTAG_DLLPRIVATE static void convertLanguageToLocaleImpl(
     300             :                 LanguageType nLang, ::com::sun::star::lang::Locale & rLocale, bool bIgnoreOverride );
     301             : 
     302             : 
     303             :         I18NLANGTAG_DLLPRIVATE static ::com::sun::star::lang::Locale lookupFallbackLocale(
     304             :                 const ::com::sun::star::lang::Locale & rLocale );
     305             :     };
     306             : 
     307             : private:
     308             : 
     309             :     static LanguageType         nConfiguredSystemLanguage;
     310             :     static LanguageType         nConfiguredSystemUILanguage;
     311             : 
     312             :     static LanguageType         nConfiguredWesternFallback;
     313             :     static LanguageType         nConfiguredAsianFallback;
     314             :     static LanguageType         nConfiguredComplexFallback;
     315             : 
     316             :     static LanguageType getPlatformSystemLanguage();
     317             :     static LanguageType getPlatformSystemUILanguage();
     318             : 
     319             :     // Substitute LANGUAGE_SYSTEM for LANGUAGE_SYSTEM_DEFAULT and
     320             :     // LANGUAGE_PROCESS_OR_USER_DEFAULT, other values aren't touched.
     321             :     I18NLANGTAG_DLLPRIVATE static inline LanguageType simplifySystemLanguages( LanguageType nLang );
     322             : };
     323             : 
     324             : 
     325             : // static
     326         425 : inline LanguageType MsLangId::getSystemLanguage()
     327             : {
     328         425 :     return getPlatformSystemLanguage();
     329             : }
     330             : 
     331             : 
     332             : // static
     333         259 : inline LanguageType MsLangId::getSystemUILanguage()
     334             : {
     335         259 :     return getPlatformSystemUILanguage();
     336             : }
     337             : 
     338             : #endif // INCLUDED_I18NLANGTAG_MSLANGID_HXX
     339             : 
     340             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11