diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx index c2716e4a6a9f..8ea944bf8f85 100644 --- a/i18nlangtag/source/languagetag/languagetag.cxx +++ b/i18nlangtag/source/languagetag/languagetag.cxx @@ -842,6 +842,31 @@ OUString LanguageTag::getRegionFromLangtag() } +OUString LanguageTag::getVariantsFromLangtag() +{ + OUString aVariants; + synCanonicalize(); + if (maBcp47.isEmpty()) + return aVariants; + if (mpImplLangtag) + { + const lt_list_t* pVariantsT = lt_tag_get_variants( MPLANGTAG); + for (const lt_list_t* pE = pVariantsT; pE; pE = lt_list_next( pE)) + { + const lt_pointer_t pV = lt_list_value( pE); + if (pV) + { + if (aVariants.isEmpty()) + aVariants = OUString::createFromAscii( static_cast(pV)); + else + aVariants += "-" + OUString::createFromAscii( static_cast(pV)); + } + } + } + return aVariants; +} + + const com::sun::star::lang::Locale & LanguageTag::getLocale( bool bResolveSystem ) const { if (!bResolveSystem && mbSystemLocale) @@ -1016,6 +1041,12 @@ OUString LanguageTag::getRegion() const } +OUString LanguageTag::getVariants() const +{ + return const_cast(this)->getVariantsFromLangtag(); +} + + OUString LanguageTag::getGlibcLocaleString( const OUString & rEncoding ) const { OUString aRet; diff --git a/include/i18nlangtag/languagetag.hxx b/include/i18nlangtag/languagetag.hxx index 1a1d69deaae6..3843493e9282 100644 --- a/include/i18nlangtag/languagetag.hxx +++ b/include/i18nlangtag/languagetag.hxx @@ -184,6 +184,16 @@ public: */ OUString getRegion() 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. + */ + OUString getVariants() const; + /** Get a GLIBC locale string. Always resolves an empty tag to the system locale. @@ -483,6 +493,7 @@ private: OUString getLanguageFromLangtag(); OUString getScriptFromLangtag(); OUString getRegionFromLangtag(); + OUString getVariantsFromLangtag(); void resetVars();