LibreOffice Module i18nlangtag (master) 1
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
LanguageTag Class Reference

Wrapper for liblangtag BCP 47 language tags, MS-LangIDs, locales and conversions in between. More...

#include <languagetag.hxx>

Collaboration diagram for LanguageTag:
[legend]

Public Types

enum class  ScriptType {
  UNKNOWN = 0 ,
  WESTERN = 1 ,
  CJK = 2 ,
  CTL = 3 ,
  RTL = 4
}
 ScriptType for a language. More...
 
enum  PrivateUse {
  ALLOW = 0 ,
  DISALLOW ,
  ALLOW_ART_X
}
 Enums to be used with isValidBcp47(). More...
 
typedef std::shared_ptr< LanguageTagImplImplPtr
 

Public Member Functions

 LanguageTag (const OUString &rBcp47LanguageTag, bool bCanonicalize=false)
 Init LanguageTag with existing BCP 47 language tag string. More...
 
 LanguageTag (const css::lang::Locale &rLocale)
 Init LanguageTag with Locale. More...
 
 LanguageTag (LanguageType nLanguage)
 Init LanguageTag with LanguageType MS-LangID. More...
 
 LanguageTag (const OUString &rBcp47, const OUString &rLanguage, std::u16string_view rScript, const OUString &rCountry)
 Init LanguageTag with either BCP 47 language tag (precedence if not empty), or a combination of language, script and country. More...
 
 LanguageTag (const rtl_Locale &rLocale)
 Init LanguageTag with rtl_Locale. More...
 
 ~LanguageTag ()
 
 LanguageTag (LanguageTag const &)=default
 
 LanguageTag (LanguageTag &&)=default
 
LanguageTagoperator= (LanguageTag const &)=default
 
LanguageTagoperator= (LanguageTag &&)=default
 
const OUString & getBcp47 (bool bResolveSystem=true) const
 Obtain BCP 47 language tag. More...
 
OUString getBcp47MS () const
 Obtain BCP 47 language tag, but with MS malformed exceptions. More...
 
const css::lang::Locale & getLocale (bool bResolveSystem=true) const
 Obtain language tag as Locale. More...
 
LanguageType getLanguageType (bool bResolveSystem=true) const
 Obtain mapping to MS-LangID. More...
 
void getIsoLanguageScriptCountry (OUString &rLanguage, OUString &rScript, OUString &rCountry) const
 Obtain ISO strings for language, script and country. More...
 
OUString getLanguage () const
 Get ISO 639 language code, or BCP 47 language. More...
 
OUString getScript () const
 Get ISO 15924 script code, if not the default script according to BCP 47. More...
 
OUString getLanguageAndScript () const
 Get combined language and script code, separated by '-' if non-default script, if default script only language. More...
 
OUString getCountry () const
 Get ISO 3166 country alpha code. More...
 
OUString getVariants () const
 Get BCP 47 variant subtags, of the IANA Language Subtag Registry. More...
 
OUString getGlibcLocaleString (std::u16string_view rEncoding) const
 Get a GLIBC locale string. More...
 
bool hasScript () const
 If language tag has a non-default script specified. More...
 
bool isIsoLocale () const
 If language tag is a locale that can be expressed using only ISO 639 language codes and ISO 3166 country codes, thus is convertible to a conforming Locale struct without using extension mechanisms. More...
 
bool isIsoODF () const
 If language tag is a locale that can be expressed using only ISO 639 language codes and ISO 15924 script codes and ISO 3166 country codes, thus can be stored in an ODF document using only fo:language, fo:script and fo:country attributes. More...
 
bool isValidBcp47 () const
 If this is a valid BCP 47 language tag. More...
 
bool isSystemLocale () const
 If this tag was constructed as an empty tag denoting the system locale. More...
 
ScriptType getScriptType () const
 Returns the script type for this language, UNKNOWN if not set. More...
 
void setScriptType (ScriptType st)
 Sets the script type for this language. More...
 
LanguageTagreset (const OUString &rBcp47LanguageTag)
 Reset with existing BCP 47 language tag string. More...
 
LanguageTagreset (const css::lang::Locale &rLocale)
 Reset with Locale. More...
 
LanguageTagreset (LanguageType nLanguage)
 Reset with LanguageType MS-LangID. More...
 
LanguageTagmakeFallback ()
 Fall back to a known locale. More...
 
::std::vector< OUString > getFallbackStrings (bool bIncludeFullBcp47) const
 Return a vector of fall-back strings. More...
 
bool equals (const LanguageTag &rLanguageTag) const
 Test equality of two LanguageTag, possibly resolving system locale. More...
 
bool operator== (const LanguageTag &rLanguageTag) const
 Test equality of two LanguageTag. More...
 
bool operator!= (const LanguageTag &rLanguageTag) const
 Test inequality of two LanguageTag. More...
 
bool operator< (const LanguageTag &rLanguageTag) const
 Test this LanguageTag less than that LanguageTag. More...
 

Static Public Member Functions

::std::vector< OUString >::const_iterator getFallback (const ::std::vector< OUString > &rList, const OUString &rReference)
 Search for an equal or at least for a similar locale in a list of possible ones. More...
 
::std::vector< css::lang::Locale >::const_iterator getMatchingFallback (const ::std::vector< css::lang::Locale > &rList, const css::lang::Locale &rReference)
 Search for an equal or for a similar locale in a list of possible ones where at least the language matches. More...
 
static css::lang::Locale convertToLocale (LanguageType nLangID, bool bResolveSystem=true)
 Convert MS-LangID to Locale. More...
 
static LanguageType convertToLanguageType (const css::lang::Locale &rLocale, bool bResolveSystem=true)
 Convert Locale to MS-LangID. More...
 
static OUString convertToBcp47 (LanguageType nLangID)
 Convert MS-LangID to BCP 47 string. More...
 
static OUString convertToBcp47 (const css::lang::Locale &rLocale, bool bResolveSystem=true)
 Convert Locale to BCP 47 string. More...
 
static css::lang::Locale convertToLocale (const OUString &rBcp47, bool bResolveSystem=true)
 Convert BCP 47 string to Locale, convenience method. More...
 
static LanguageType convertToLanguageType (const OUString &rBcp47)
 Convert BCP 47 string to MS-LangID, convenience method. More...
 
static LanguageType convertToLanguageTypeWithFallback (const OUString &rBcp47)
 Convert BCP 47 string to MS-LangID with fallback, convenience method. More...
 
static css::lang::Locale convertToLocaleWithFallback (const OUString &rBcp47)
 Convert BCP 47 string to Locale with fallback, convenience method. More...
 
static LanguageType convertToLanguageTypeWithFallback (const css::lang::Locale &rLocale)
 Convert Locale to MS-LangID with fallback. More...
 
static bool isValidBcp47 (const OUString &rString, OUString *o_pCanonicalized, PrivateUse ePrivateUse=PrivateUse::ALLOW)
 If rString represents a valid BCP 47 language tag. More...
 
static bool isOnTheFlyID (LanguageType nLang)
 If nLang is a generated on-the-fly LangID. More...
 
static ScriptType getOnTheFlyScriptType (LanguageType nLang)
 
static void setConfiguredSystemLanguage (LanguageType nLang)
 @ATTENTION: ONLY to be called by the application's configuration! More...
 
static void disable_lt_tag_parse ()
 @ATTENTION: ONLY to be called by fuzzing setup More...
 

Private Member Functions

LanguageTagImplgetImpl ()
 
LanguageTagImpl const * getImpl () const
 
ImplPtr registerImpl () const
 
void syncFromImpl ()
 
void syncVarsFromRawImpl () const
 
void syncVarsFromImpl () const
 
void convertLocaleToLang ()
 
void convertBcp47ToLocale ()
 
void convertBcp47ToLang ()
 
void convertLangToLocale ()
 
void convertFromRtlLocale ()
 
bool synCanonicalize ()
 Canonicalize if not yet done and synchronize initialized conversions. More...
 
void resetVars ()
 

Static Private Member Functions

static bool isIsoLanguage (const OUString &rLanguage)
 
static bool isIsoScript (const OUString &rScript)
 
static bool isIsoCountry (const OUString &rRegion)
 

Private Attributes

css::lang::Locale maLocale
 
OUString maBcp47
 
LanguageType mnLangID
 
ImplPtr mpImpl
 
bool mbSystemLocale: 1
 
bool mbInitializedBcp47: 1
 
bool mbInitializedLocale: 1
 
bool mbInitializedLangID: 1
 
bool mbIsFallback: 1
 

Friends

class LanguageTagImpl
 

Detailed Description

Wrapper for liblangtag BCP 47 language tags, MS-LangIDs, locales and conversions in between.

Note that member variables are mutable and may change their values even in const methods. Getter methods return either the original value or matching converted values.

For standalone conversions if no LanguageTag instance is at hand, static convertTo...() methods exist.

Definition at line 52 of file languagetag.hxx.

Member Typedef Documentation

◆ ImplPtr

typedef std::shared_ptr< LanguageTagImpl > LanguageTag::ImplPtr

Definition at line 557 of file languagetag.hxx.

Member Enumeration Documentation

◆ PrivateUse

Enums to be used with isValidBcp47().

Enumerator
ALLOW 

Allow all private-use and local-use including (!) 'qlt' local-use.

DISALLOW 

Disallow all private-use and 'qlt' local-use, other 'qaa' to 'qtz' local-use are allowed.

ALLOW_ART_X 

Disallow all private-use and 'qlt' local-use, but allow 'art-x-...' private-use for artificial constructed languages (and 'art-Latn-x-...' and other scripts).

Definition at line 519 of file languagetag.hxx.

◆ ScriptType

enum class LanguageTag::ScriptType
strong

ScriptType for a language.

Used only in onTheFly languages as a way of marking key script behaviours for the script of the language without having to store and analyse the script each time. Used primarily from msLangId.

These need to correspond to the ExtraLanguages.ScriptType template property in officecfg/registry/schema/org/openoffice/VCL.xcs

Enumerator
UNKNOWN 
WESTERN 
CJK 
CTL 
RTL 

Definition at line 67 of file languagetag.hxx.

Constructor & Destructor Documentation

◆ LanguageTag() [1/7]

LanguageTag::LanguageTag ( const OUString &  rBcp47LanguageTag,
bool  bCanonicalize = false 
)
explicit

Init LanguageTag with existing BCP 47 language tag string.

Parameters
bCanonicalizeIf TRUE, canonicalize tag and reparse, the resulting tag string may be different. IF FALSE, the tag is simply stored and can be retrieved with getBcp47().

Note that conversions to ISO codes, locales or LanguageType or obtaining language or script will canonicalize the tag string anyway, so specifying bCanonicalize=false is not a guarantee that the tag will stay identical to what was passed.

Definition at line 501 of file languagetag.cxx.

References LanguageTagImpl::canonicalize(), getImpl(), and syncFromImpl().

Referenced by convertToLanguageType(), convertToLanguageTypeWithFallback(), convertToLocale(), convertToLocaleWithFallback(), getFallback(), getFallbackStrings(), getMatchingFallback(), and makeFallback().

◆ LanguageTag() [2/7]

LanguageTag::LanguageTag ( const css::lang::Locale &  rLocale)
explicit

Init LanguageTag with Locale.

Definition at line 522 of file languagetag.cxx.

References handleVendorVariant(), and maLocale.

◆ LanguageTag() [3/7]

LanguageTag::LanguageTag ( LanguageType  nLanguage)
explicit

Init LanguageTag with LanguageType MS-LangID.

Definition at line 536 of file languagetag.cxx.

◆ LanguageTag() [4/7]

LanguageTag::LanguageTag ( const OUString &  rBcp47,
const OUString &  rLanguage,
std::u16string_view  rScript,
const OUString &  rCountry 
)
explicit

Init LanguageTag with either BCP 47 language tag (precedence if not empty), or a combination of language, script and country.

This is a convenience ctor to be used in ODF import where these are distinct attributes.

Definition at line 548 of file languagetag.cxx.

References I18NLANGTAG_QLT, maBcp47, maLocale, mbInitializedBcp47, mbInitializedLocale, and mbSystemLocale.

◆ LanguageTag() [5/7]

LanguageTag::LanguageTag ( const rtl_Locale &  rLocale)
explicit

Init LanguageTag with rtl_Locale.

This is a convenience ctor.

Definition at line 585 of file languagetag.cxx.

References convertFromRtlLocale(), Country, and Variant.

◆ ~LanguageTag()

LanguageTag::~LanguageTag ( )

Definition at line 598 of file languagetag.cxx.

◆ LanguageTag() [6/7]

LanguageTag::LanguageTag ( LanguageTag const &  )
default

◆ LanguageTag() [7/7]

LanguageTag::LanguageTag ( LanguageTag &&  )
default

Member Function Documentation

◆ convertBcp47ToLang()

void LanguageTag::convertBcp47ToLang ( )
private

Definition at line 1493 of file languagetag.cxx.

References LanguageTagImpl::convertBcp47ToLang(), getImpl(), and syncFromImpl().

Referenced by getLanguageType().

◆ convertBcp47ToLocale()

void LanguageTag::convertBcp47ToLocale ( )
private

Definition at line 1470 of file languagetag.cxx.

References LanguageTagImpl::convertBcp47ToLocale(), getImpl(), and syncFromImpl().

Referenced by getLocale().

◆ convertFromRtlLocale()

void LanguageTag::convertFromRtlLocale ( )
private

◆ convertLangToLocale()

void LanguageTag::convertLangToLocale ( )
private

Definition at line 1513 of file languagetag.cxx.

References LanguageTagImpl::convertLangToLocale(), getImpl(), and syncFromImpl().

Referenced by getLocale().

◆ convertLocaleToLang()

void LanguageTag::convertLocaleToLang ( )
private

Definition at line 1444 of file languagetag.cxx.

References LanguageTagImpl::convertLocaleToLang(), getImpl(), and syncFromImpl().

Referenced by getLanguageType().

◆ convertToBcp47() [1/2]

OUString LanguageTag::convertToBcp47 ( const css::lang::Locale &  rLocale,
bool  bResolveSystem = true 
)
static

Convert Locale to BCP 47 string.

Parameters
bResolveSystemIf TRUE, resolve an empty language tag denoting the system locale to the real locale used. If FALSE, return an empty OUString for such a tag.

Definition at line 2859 of file languagetag.cxx.

References LanguageTagImpl::convertToBcp47(), convertToBcp47(), and LANGUAGE_SYSTEM.

◆ convertToBcp47() [2/2]

OUString LanguageTag::convertToBcp47 ( LanguageType  nLangID)
static

Convert MS-LangID to BCP 47 string.

Resolve an empty language tag denoting the system locale to the real locale used.

Definition at line 2877 of file languagetag.cxx.

References LanguageTagImpl::convertToBcp47(), and convertToLocale().

Referenced by LanguageTagImpl::convertLocaleToBcp47(), and convertToBcp47().

◆ convertToLanguageType() [1/2]

LanguageType LanguageTag::convertToLanguageType ( const css::lang::Locale &  rLocale,
bool  bResolveSystem = true 
)
static

Convert Locale to MS-LangID.

Parameters
bResolveSystemIf TRUE, resolve an empty language tag denoting the system locale to the real locale used. If FALSE, return LANGUAGE_SYSTEM for such a tag.

Definition at line 2821 of file languagetag.cxx.

References LANGUAGE_SYSTEM, and LanguageTag().

◆ convertToLanguageType() [2/2]

LanguageType LanguageTag::convertToLanguageType ( const OUString &  rBcp47)
static

Convert BCP 47 string to MS-LangID, convenience method.

NOTE: exists only for consistency with the other convertTo...() methods, internally uses a temporary LanguageTag instance for conversion so does not save anything compared to LanguageTag(rBcp47).getLanguageType(bResolveSystem).

Resolve an empty language tag denoting the system locale to the real locale used.

Definition at line 2900 of file languagetag.cxx.

References LanguageTag().

◆ convertToLanguageTypeWithFallback() [1/2]

LanguageType LanguageTag::convertToLanguageTypeWithFallback ( const css::lang::Locale &  rLocale)
static

Convert Locale to MS-LangID with fallback.

Resolves an empty language tag denoting the system locale to LANGUAGE_SYSTEM and does not fallback.

Definition at line 2921 of file languagetag.cxx.

References LANGUAGE_SYSTEM, and LanguageTag().

◆ convertToLanguageTypeWithFallback() [2/2]

LanguageType LanguageTag::convertToLanguageTypeWithFallback ( const OUString &  rBcp47)
static

Convert BCP 47 string to MS-LangID with fallback, convenience method.

NOTE: exists only for consistency with the other convertTo...() methods, internally uses a temporary LanguageTag instance for conversion so does not save anything compared to LanguageTag(rBcp47).makeFallback().getLanguageType(bResolveSystem).

See also
makeFallback()

Always resolves an empty tag to the system locale.

Definition at line 2907 of file languagetag.cxx.

References LanguageTag().

◆ convertToLocale() [1/2]

css::lang::Locale LanguageTag::convertToLocale ( const OUString &  rBcp47,
bool  bResolveSystem = true 
)
static

Convert BCP 47 string to Locale, convenience method.

NOTE: exists only for consistency with the other convertTo...() methods, internally uses a temporary LanguageTag instance for conversion so does not save anything compared to LanguageTag(rBcp47).getLocale(bResolveSystem).

Parameters
bResolveSystemIf TRUE, resolve an empty language tag denoting the system locale to the real locale used. If FALSE, return an empty Locale for such a tag.

Definition at line 2890 of file languagetag.cxx.

References LanguageTag().

◆ convertToLocale() [2/2]

css::lang::Locale LanguageTag::convertToLocale ( LanguageType  nLangID,
bool  bResolveSystem = true 
)
static

Convert MS-LangID to Locale.

Parameters
bResolveSystemIf TRUE, resolve an empty language tag denoting the system locale to the real locale used. If FALSE, return an empty Locale for such a tag.

Definition at line 2811 of file languagetag.cxx.

References LanguageTag(), and lcl_isSystem().

Referenced by convertToBcp47().

◆ convertToLocaleWithFallback()

css::lang::Locale LanguageTag::convertToLocaleWithFallback ( const OUString &  rBcp47)
static

Convert BCP 47 string to Locale with fallback, convenience method.

NOTE: exists only for consistency with the other convertTo...() methods, internally uses a temporary LanguageTag instance for conversion so does not save anything compared to LanguageTag(rBcp47).makeFallback().getLocale(bResolveSystem).

See also
makeFallback()

Always resolves an empty tag to the system locale.

Definition at line 2914 of file languagetag.cxx.

References LanguageTag().

◆ disable_lt_tag_parse()

void LanguageTag::disable_lt_tag_parse ( )
static

@ATTENTION: ONLY to be called by fuzzing setup

Definition at line 739 of file languagetag.cxx.

References lt_tag_parse_disabled.

◆ equals()

bool LanguageTag::equals ( const LanguageTag rLanguageTag) const

Test equality of two LanguageTag, possibly resolving system locale.

Resolve empty language tags denoting the system locale to the real locale used before comparing.

Definition at line 2405 of file languagetag.cxx.

References getBcp47(), isSystemLocale(), and operator==().

◆ getBcp47()

const OUString & LanguageTag::getBcp47 ( bool  bResolveSystem = true) const

Obtain BCP 47 language tag.

Parameters
bResolveSystemIf TRUE, resolve an empty language tag denoting the system locale to the real locale used. If FALSE, return an empty OUString for such a tag.

Definition at line 1582 of file languagetag.cxx.

References LanguageTagImpl::getBcp47(), getImpl(), maBcp47, mbInitializedBcp47, mbSystemLocale, syncFromImpl(), syncVarsFromImpl(), and u.

Referenced by equals(), getBcp47MS(), getFallbackStrings(), LanguageTagIcu::getIcuLocale(), operator<(), and operator==().

◆ getBcp47MS()

OUString LanguageTag::getBcp47MS ( ) const

Obtain BCP 47 language tag, but with MS malformed exceptions.

To be used only in OOXML filter context. For example, es-ES-u-co-trad is stored as es-ES_tradnl which is not a valid BCP 47 language tag.

Definition at line 2397 of file languagetag.cxx.

References getBcp47(), getLanguageType(), and LANGUAGE_SPANISH_DATED.

◆ getCountry()

OUString LanguageTag::getCountry ( ) const

Get ISO 3166 country alpha code.

Empty if the BCP 47 tags denote a region not expressible as 2 character country code.

Always resolves an empty tag to the system locale.

Definition at line 1917 of file languagetag.cxx.

References LanguageTagImpl::getCountry(), getImpl(), LanguageTagImpl::maCachedCountry, LanguageTagImpl::mbCachedCountry, and syncFromImpl().

Referenced by getFallbackStrings(), getGlibcLocaleString(), LanguageTagIcu::getIcuLocale(), and getIsoLanguageScriptCountry().

◆ getFallback()

std::vector< OUString >::const_iterator LanguageTag::getFallback ( const ::std::vector< OUString > &  rList,
const OUString &  rReference 
)
static

Search for an equal or at least for a similar locale in a list of possible ones.

@descr First search for a locale that is equal to the reference locale. (means: same BCP47 string)

If the reference locale could not be located, check for "similar" locales, in the same order as obtained by getFallbackStrings().

If no similar locale could be located, we search for a locale "en-US" inside the given locale list.

If "en-US" could not be located, we search for a locale "en" inside the given list.

If no "same" nor any "similar" locale could be found, we try "x-default" and "x-no-translate" explicitly. Sometimes variables don't use real localization. For example, in case the localized value is a fix product name.

If no locale matched until then, we use any other locale that exists inside the set of given ones, namely the first encountered!

Parameters
rListthe vector of possible locales as BCP47 strings.
rReferencethe reference locale, BCP47 string.
Returns
An iterator that points to the found element inside the given locale list. If no matching locale could be found it points to the beginning of the list.

Definition at line 2713 of file languagetag.cxx.

References getFallbackStrings(), and LanguageTag().

◆ getFallbackStrings()

std::vector< OUString > LanguageTag::getFallbackStrings ( bool  bIncludeFullBcp47) const

Return a vector of fall-back strings.

In order: full BCP 47 tag, same as getBcp47() lll-Ssss-CC lll-Ssss lll-CC lll

If the tag includes variants the order is: full BCP 47 tag, same as getBcp47() lll-Ssss-CC-vvvvvvvv lll-Ssss-vvvvvvvv lll-Ssss-CC lll-Ssss lll-CC-vvvvvvvv lll-vvvvvvvv lll-CC lll

Only strings that differ from a higher order are included, for example if there is no script the elements will be bcp47, lll-CC, lll; if the bcp47 string is identical to lll-CC then only lll-CC, lll.

Note that lll is only ISO 639-1/2 alpha code and CC is only ISO 3166 alpha code. If the region can not be expressed as ISO 3166 then no -CC tags are included.

Parameters
bIncludeFullBcp47If TRUE, the full BCP 47 tag is included as first element. If FALSE, the full tag is not included; used if the caller obtains the fallbacks only if the full tag did not lead to a match, so subsequent tries need not to include it again.

Definition at line 2176 of file languagetag.cxx.

References getBcp47(), getCountry(), getFallbackStrings(), getLanguage(), getScript(), getVariants(), hasScript(), isIsoLocale(), LanguageTag(), and maBcp47.

Referenced by getFallback(), getFallbackStrings(), getKnowns(), getMatchingFallback(), and makeFallback().

◆ getGlibcLocaleString()

OUString LanguageTag::getGlibcLocaleString ( std::u16string_view  rEncoding) const

Get a GLIBC locale string.

Always resolves an empty tag to the system locale.

Parameters
rEncodingAn encoding to be appended to language_country, for example ".UTF-8" including the dot.
Returns
The resulting GLIBC locale string if it could be constructed, if not an empty string is returned.

Definition at line 1978 of file languagetag.cxx.

References getCountry(), LanguageTagImpl::getGlibcLocaleString(), getImpl(), getLanguage(), and isIsoLocale().

◆ getImpl() [1/2]

LanguageTagImpl * LanguageTag::getImpl ( )
private

◆ getImpl() [2/2]

LanguageTagImpl const * LanguageTag::getImpl ( ) const
private

Definition at line 1020 of file languagetag.cxx.

References mpImpl, registerImpl(), and syncVarsFromRawImpl().

◆ getIsoLanguageScriptCountry()

void LanguageTag::getIsoLanguageScriptCountry ( OUString &  rLanguage,
OUString &  rScript,
OUString &  rCountry 
) const

Obtain ISO strings for language, script and country.

This is a convenience method for ODF export places only. Avoid use in other code.

ATTENTION! May return empty strings if the language tag is not expressible in valid ISO codes!

See also
isIsoODF()

Always resolves an empty tag to the system locale.

Definition at line 1766 of file languagetag.cxx.

References getCountry(), getLanguage(), getScript(), isIsoCountry(), isIsoLanguage(), isIsoODF(), and isIsoScript().

◆ getLanguage()

OUString LanguageTag::getLanguage ( ) const

Get ISO 639 language code, or BCP 47 language.

Always resolves an empty tag to the system locale.

Definition at line 1859 of file languagetag.cxx.

References getImpl(), LanguageTagImpl::getLanguage(), LanguageTagImpl::maCachedLanguage, LanguageTagImpl::mbCachedLanguage, and syncFromImpl().

Referenced by getFallbackStrings(), getGlibcLocaleString(), LanguageTagIcu::getIcuLocale(), getIsoLanguageScriptCountry(), and getLanguageAndScript().

◆ getLanguageAndScript()

OUString LanguageTag::getLanguageAndScript ( ) const

Get combined language and script code, separated by '-' if non-default script, if default script only language.

See also
hasScript()

Always resolves an empty tag to the system locale.

Definition at line 1892 of file languagetag.cxx.

References getLanguage(), and getScript().

◆ getLanguageType()

LanguageType LanguageTag::getLanguageType ( bool  bResolveSystem = true) const

Obtain mapping to MS-LangID.

Parameters
bResolveSystemIf TRUE, resolve an empty language tag denoting the system locale to the real locale used. If FALSE, return LANGUAGE_SYSTEM for such a tag.

Definition at line 1740 of file languagetag.cxx.

References convertBcp47ToLang(), convertLocaleToLang(), LANGUAGE_DONTKNOW, LANGUAGE_SYSTEM, mbInitializedBcp47, mbInitializedLangID, mbSystemLocale, mnLangID, synCanonicalize(), and syncVarsFromImpl().

Referenced by MsLangId::Conversion::convertIsoNamesToLanguage(), getBcp47MS(), and getPlatformSystemLanguageImpl().

◆ getLocale()

const css::lang::Locale & LanguageTag::getLocale ( bool  bResolveSystem = true) const

Obtain language tag as Locale.

As a convention, language tags that can not be expressed as "pure" css::lang::Locale content using Language and Country fields store "qlt" (ISO 639 reserved for local use) in the Language field and the entire BCP 47 language tag in the Variant field. The Country field contains the corresponding ISO 3166 country code if there is one, or otherwise is empty.

Parameters
bResolveSystemIf TRUE, resolve an empty language tag denoting the system locale to the real locale used. If FALSE, return an empty Locale for such a tag.

Definition at line 1720 of file languagetag.cxx.

References convertBcp47ToLocale(), convertLangToLocale(), maLocale, mbInitializedBcp47, mbInitializedLocale, mbSystemLocale, and syncVarsFromImpl().

Referenced by LanguageTagIcu::getIcuLocale(), and makeFallback().

◆ getMatchingFallback()

std::vector< css::lang::Locale >::const_iterator LanguageTag::getMatchingFallback ( const ::std::vector< css::lang::Locale > &  rList,
const css::lang::Locale &  rReference 
)
static

Search for an equal or for a similar locale in a list of possible ones where at least the language matches.

@descr First search for a locale that is equal to the reference locale.

If the reference locale could not be located, check for "similar" locales, in the same order as obtained by getFallbackStrings().

If no locale matches, rList.end() is returned.

Parameters
rListthe vector of possible locales.
rReferencethe reference locale.
Returns
An iterator that points to the found element inside the given locale list. If no matching locale could be found it points to the end of the list.

Definition at line 2755 of file languagetag.cxx.

References getFallbackStrings(), i, and LanguageTag().

◆ getOnTheFlyScriptType()

LanguageTag::ScriptType LanguageTag::getOnTheFlyScriptType ( LanguageType  nLang)
static

Definition at line 706 of file languagetag.cxx.

References UNKNOWN.

Referenced by MsLangId::getScriptType(), MsLangId::isCJK(), and MsLangId::isRightToLeft().

◆ getScript()

OUString LanguageTag::getScript ( ) const

Get ISO 15924 script code, if not the default script according to BCP 47.

For default script an empty string is returned.

See also
hasScript()

Always resolves an empty tag to the system locale.

Definition at line 1881 of file languagetag.cxx.

References getImpl(), LanguageTagImpl::getScript(), LanguageTagImpl::maCachedScript, LanguageTagImpl::mbCachedScript, and syncFromImpl().

Referenced by getFallbackStrings(), getIsoLanguageScriptCountry(), getLanguageAndScript(), and MsLangId::isNonLatinWestern().

◆ getScriptType()

LanguageTag::ScriptType LanguageTag::getScriptType ( ) const

Returns the script type for this language, UNKNOWN if not set.

Definition at line 2023 of file languagetag.cxx.

References getImpl(), and LanguageTagImpl::getScriptType().

◆ getVariants()

OUString LanguageTag::getVariants ( ) const

Get BCP 47 variant subtags, of the IANA Language Subtag Registry.

If there are multiple variant subtags they are separated by '-'.

This is NOT related to Locale.Variant!

Always resolves an empty tag to the system locale.

Definition at line 1945 of file languagetag.cxx.

References getImpl(), LanguageTagImpl::getVariants(), LanguageTagImpl::maCachedVariants, LanguageTagImpl::mbCachedVariants, and syncFromImpl().

Referenced by getFallbackStrings().

◆ hasScript()

bool LanguageTag::hasScript ( ) const

If language tag has a non-default script specified.

Definition at line 2009 of file languagetag.cxx.

References getImpl(), LanguageTagImpl::hasScript(), and syncFromImpl().

Referenced by getFallbackStrings(), and MsLangId::isNonLatinWestern().

◆ isIsoCountry()

bool LanguageTag::isIsoCountry ( const OUString &  rRegion)
staticprivate

◆ isIsoLanguage()

bool LanguageTag::isIsoLanguage ( const OUString &  rLanguage)
staticprivate

◆ isIsoLocale()

bool LanguageTag::isIsoLocale ( ) const

If language tag is a locale that can be expressed using only ISO 639 language codes and ISO 3166 country codes, thus is convertible to a conforming Locale struct without using extension mechanisms.

Note that an empty language tag or empty Locale::Language field or LanguageType LANGUAGE_SYSTEM could be treated as a valid ISO locale in some context, but here is not. If you want that ask for aTag.isSystemLocale() || aTag.isIsoLocale()

Always resolves an empty tag to the system locale.

Definition at line 2074 of file languagetag.cxx.

References getImpl(), LanguageTagImpl::isIsoLocale(), and syncFromImpl().

Referenced by getFallbackStrings(), getGlibcLocaleString(), and LanguageTagIcu::getIcuLocale().

◆ isIsoODF()

bool LanguageTag::isIsoODF ( ) const

If language tag is a locale that can be expressed using only ISO 639 language codes and ISO 15924 script codes and ISO 3166 country codes, thus can be stored in an ODF document using only fo:language, fo:script and fo:country attributes.

If this is FALSE, the locale must be stored as a <*:rfc-language-tag> element.

Always resolves an empty tag to the system locale.

Definition at line 2109 of file languagetag.cxx.

References getImpl(), LanguageTagImpl::isIsoODF(), and syncFromImpl().

Referenced by getIsoLanguageScriptCountry().

◆ isIsoScript()

bool LanguageTag::isIsoScript ( const OUString &  rScript)
staticprivate

Definition at line 1832 of file languagetag.cxx.

References SAL_WARN_IF.

Referenced by getIsoLanguageScriptCountry(), and LanguageTagImpl::isIsoODF().

◆ isOnTheFlyID()

bool LanguageTag::isOnTheFlyID ( LanguageType  nLang)
static

◆ isSystemLocale()

bool LanguageTag::isSystemLocale ( ) const
inline

If this tag was constructed as an empty tag denoting the system locale.

Definition at line 267 of file languagetag.hxx.

References LanguageTagImpl::mbSystemLocale.

Referenced by equals(), and operator==().

◆ isValidBcp47() [1/2]

bool LanguageTag::isValidBcp47 ( ) const

If this is a valid BCP 47 language tag.

Always resolves an empty tag to the system locale.

@seealso static bool isValidBcp47(const OUString&)

Definition at line 2129 of file languagetag.cxx.

References getImpl(), LanguageTagImpl::isValidBcp47(), and syncFromImpl().

◆ isValidBcp47() [2/2]

bool LanguageTag::isValidBcp47 ( const OUString &  rString,
OUString *  o_pCanonicalized,
LanguageTag::PrivateUse  ePrivateUse = PrivateUse::ALLOW 
)
static

If rString represents a valid BCP 47 language tag.

Never resolves an empty tag to the system locale, in fact an empty string is invalid here. Does not create an instance to be registered with a conversion to Locale or LanguageType.

Parameters
o_pCanonicalizedIf given and rString is a valid BCP 47 language tag, the canonicalized form is assigned, which may differ from the original string even if that was a valid tag. If rString is not a valid tag, nothing is assigned.
ePrivateUseIf PrivateUse::DISALLOW, valid tags according to BCP 47 but reserved for private use, like 'x-...', are not allowed and FALSE is returned in this case.

Definition at line 2931 of file languagetag.cxx.

References I18NLANGTAG_QLT_ASCII, lt_tag_parse_disabled, OUStringToOString(), SAL_INFO, and SAL_WARN_IF.

◆ makeFallback()

LanguageTag & LanguageTag::makeFallback ( )

Fall back to a known locale.

If the current tag does not represent a known (by us) locale, fall back to the most likely locale possible known. If the current tag is known, no change occurs.

Definition at line 2137 of file languagetag.cxx.

References getFallbackStrings(), getLocale(), LanguageTag(), MsLangId::Conversion::lookupFallbackLocale(), mbIsFallback, reset(), and SAL_INFO.

Referenced by getPlatformSystemLanguageImpl().

◆ operator!=()

bool LanguageTag::operator!= ( const LanguageTag rLanguageTag) const

Test inequality of two LanguageTag.

Does NOT resolve system, i.e. if the system locale is en-US LanguageTag("")!=LanguageTag("en-US") returns true! Use !equals(,..) instead if system locales shall be resolved.

Definition at line 2434 of file languagetag.cxx.

References operator==().

◆ operator<()

bool LanguageTag::operator< ( const LanguageTag rLanguageTag) const

Test this LanguageTag less than that LanguageTag.

For sorted containers. Does NOT resolve system.

Definition at line 2440 of file languagetag.cxx.

References getBcp47().

◆ operator=() [1/2]

LanguageTag & LanguageTag::operator= ( LanguageTag &&  )
default

References getLocale().

◆ operator=() [2/2]

LanguageTag & LanguageTag::operator= ( LanguageTag const &  )
default

◆ operator==()

bool LanguageTag::operator== ( const LanguageTag rLanguageTag) const

Test equality of two LanguageTag.

Does NOT resolve system, i.e. if the system locale is en-US LanguageTag("")==LanguageTag("en-US") returns false! Use equals(...) instead if system locales shall be resolved.

Definition at line 2417 of file languagetag.cxx.

References getBcp47(), isSystemLocale(), mbInitializedLangID, and mnLangID.

Referenced by equals(), and operator!=().

◆ registerImpl()

LanguageTag::ImplPtr LanguageTag::registerImpl ( ) const
private

◆ reset() [1/3]

LanguageTag & LanguageTag::reset ( const css::lang::Locale &  rLocale)

Reset with Locale.

Definition at line 1065 of file languagetag.cxx.

References handleVendorVariant(), maLocale, mbInitializedLocale, mbSystemLocale, and resetVars().

◆ reset() [2/3]

LanguageTag & LanguageTag::reset ( const OUString &  rBcp47LanguageTag)

Reset with existing BCP 47 language tag string.

See ctor.

Definition at line 1054 of file languagetag.cxx.

References maBcp47, mbInitializedBcp47, mbSystemLocale, and resetVars().

Referenced by makeFallback().

◆ reset() [3/3]

LanguageTag & LanguageTag::reset ( LanguageType  nLanguage)

Reset with LanguageType MS-LangID.

Definition at line 1076 of file languagetag.cxx.

References LANGUAGE_SYSTEM, mbInitializedLangID, mbSystemLocale, mnLangID, and resetVars().

◆ resetVars()

void LanguageTag::resetVars ( )
private

◆ setConfiguredSystemLanguage()

void LanguageTag::setConfiguredSystemLanguage ( LanguageType  nLang)
static

@ATTENTION: ONLY to be called by the application's configuration!

Definition at line 718 of file languagetag.cxx.

References LANGUAGE_DONTKNOW, LANGUAGE_SYSTEM, registerImpl(), SAL_INFO, SAL_WARN, and MsLangId::LanguageTagAccess::setConfiguredSystemLanguage().

◆ setScriptType()

void LanguageTag::setScriptType ( LanguageTag::ScriptType  st)

Sets the script type for this language.

Definition at line 2036 of file languagetag.cxx.

References getImpl(), and LanguageTagImpl::setScriptType().

◆ synCanonicalize()

bool LanguageTag::synCanonicalize ( )
private

Canonicalize if not yet done and synchronize initialized conversions.

Returns
whether BCP 47 language tag string was changed.

Definition at line 1344 of file languagetag.cxx.

References getImpl(), LanguageTagImpl::synCanonicalize(), and syncFromImpl().

Referenced by getLanguageType().

◆ syncFromImpl()

void LanguageTag::syncFromImpl ( )
private

◆ syncVarsFromImpl()

void LanguageTag::syncVarsFromImpl ( ) const
private

Definition at line 1318 of file languagetag.cxx.

References getImpl(), mpImpl, and syncVarsFromRawImpl().

Referenced by getBcp47(), getLanguageType(), and getLocale().

◆ syncVarsFromRawImpl()

void LanguageTag::syncVarsFromRawImpl ( ) const
private

Friends And Related Function Documentation

◆ LanguageTagImpl

friend class LanguageTagImpl
friend

Definition at line 54 of file languagetag.hxx.

Member Data Documentation

◆ maBcp47

OUString LanguageTag::maBcp47
mutableprivate

◆ maLocale

css::lang::Locale LanguageTag::maLocale
mutableprivate

◆ mbInitializedBcp47

bool LanguageTag::mbInitializedBcp47
mutableprivate

◆ mbInitializedLangID

bool LanguageTag::mbInitializedLangID
mutableprivate

◆ mbInitializedLocale

bool LanguageTag::mbInitializedLocale
mutableprivate

◆ mbIsFallback

bool LanguageTag::mbIsFallback
private

Definition at line 569 of file languagetag.hxx.

Referenced by makeFallback(), and resetVars().

◆ mbSystemLocale

bool LanguageTag::mbSystemLocale
private

◆ mnLangID

LanguageType LanguageTag::mnLangID
mutableprivate

◆ mpImpl

ImplPtr LanguageTag::mpImpl
mutableprivate

The documentation for this class was generated from the following files: