diff options
author | Eike Rathke <erack@redhat.com> | 2013-02-19 00:45:07 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2013-02-19 00:45:26 +0100 |
commit | 555d88d003b8f0708fb5a1c1f3b3f7a8110dddf7 (patch) | |
tree | 0f980dfeb2c20e93f838bd504737282b8bfc8fed /i18npool | |
parent | 2c36a832b85eeff6b4a2f6c6aab599e4b10b8886 (diff) |
added reset(rtl_Locale)
Change-Id: I1bc83dd4e5286f7102513d8a4c7d5624952eb830
Diffstat (limited to 'i18npool')
-rw-r--r-- | i18npool/inc/i18npool/languagetag.hxx | 5 | ||||
-rw-r--r-- | i18npool/source/languagetag/languagetag.cxx | 83 |
2 files changed, 53 insertions, 35 deletions
diff --git a/i18npool/inc/i18npool/languagetag.hxx b/i18npool/inc/i18npool/languagetag.hxx index 324fcd3da165..ff8266d2de79 100644 --- a/i18npool/inc/i18npool/languagetag.hxx +++ b/i18npool/inc/i18npool/languagetag.hxx @@ -205,6 +205,9 @@ public: /** Reset with LanguageType MS-LangID. */ void reset( LanguageType nLanguage ); + /** Reset with rtl_Locale. */ + void reset( const rtl_Locale & rLocale ); + /** Fall back to a known locale. @@ -275,6 +278,8 @@ private: void convertLangToLocale(); void convertLangToBcp47(); + void convertFromRtlLocale(); + bool canonicalize(); rtl::OUString getLanguageFromLangtag(); diff --git a/i18npool/source/languagetag/languagetag.cxx b/i18npool/source/languagetag/languagetag.cxx index 2117771fdb67..c51096255a32 100644 --- a/i18npool/source/languagetag/languagetag.cxx +++ b/i18npool/source/languagetag/languagetag.cxx @@ -248,41 +248,7 @@ LanguageTag::LanguageTag( const rtl_Locale & rLocale ) mbCachedCountry( false), mbIsFallback( false) { - // The rtl_Locale follows the Open Group Base Specification, - // 8.2 Internationalization Variables - // language[_territory][.codeset][@modifier] - // On GNU/Linux systems usually being glibc locales. - // sal/osl/unx/nlsupport.c _parse_locale() parses them into - // Language: language 2 or 3 alpha code - // Country: [territory] 2 alpha code - // Variant: [.codeset][@modifier] - // Variant effectively contains anything that follows the territory, not - // looking for '.' dot delimiter or '@' modifier content. - if (!maLocale.Variant.isEmpty()) - { - OString aStr = OUStringToOString( maLocale.Language + "_" + maLocale.Country + maLocale.Variant, - RTL_TEXTENCODING_UTF8); - /* FIXME: let liblangtag parse this entirely with - * lt_tag_convert_from_locale() but that needs a patch to pass the - * string. */ -#if 0 - myLtError aError; - theDataRef::get().incRef(); - mpImplLangtag = lt_tag_convert_from_locale( aStr.getStr(), &aError.p); - maBcp47 = OStringToOUString( lt_tag_get_string( MPLANGTAG), RTL_TEXTENCODING_UTF8); - mbInitializedBcp47 = true; -#else - mnLangID = MsLangId::convertUnxByteStringToLanguage( aStr); - if (mnLangID == LANGUAGE_DONTKNOW) - { - SAL_WARN( "i18npool.langtag", "LanguageTag(rtl_Locale) - unknown: " << aStr); - mnLangID = LANGUAGE_ENGLISH_US; // we need _something_ here - } - mbInitializedLangID = true; -#endif - maLocale = lang::Locale(); - mbInitializedLocale = false; - } + convertFromRtlLocale(); } @@ -417,6 +383,13 @@ void LanguageTag::reset( LanguageType nLanguage ) } +void LanguageTag::reset( const rtl_Locale & rLocale ) +{ + reset( lang::Locale( rLocale.Language, rLocale.Country, rLocale.Variant)); + convertFromRtlLocale(); +} + + bool LanguageTag::canonicalize() { #ifdef erDEBUG @@ -671,6 +644,46 @@ void LanguageTag::convertLangToBcp47() } +void LanguageTag::convertFromRtlLocale() +{ + // The rtl_Locale follows the Open Group Base Specification, + // 8.2 Internationalization Variables + // language[_territory][.codeset][@modifier] + // On GNU/Linux systems usually being glibc locales. + // sal/osl/unx/nlsupport.c _parse_locale() parses them into + // Language: language 2 or 3 alpha code + // Country: [territory] 2 alpha code + // Variant: [.codeset][@modifier] + // Variant effectively contains anything that follows the territory, not + // looking for '.' dot delimiter or '@' modifier content. + if (!maLocale.Variant.isEmpty()) + { + OString aStr = OUStringToOString( maLocale.Language + "_" + maLocale.Country + maLocale.Variant, + RTL_TEXTENCODING_UTF8); + /* FIXME: let liblangtag parse this entirely with + * lt_tag_convert_from_locale() but that needs a patch to pass the + * string. */ +#if 0 + myLtError aError; + theDataRef::get().incRef(); + mpImplLangtag = lt_tag_convert_from_locale( aStr.getStr(), &aError.p); + maBcp47 = OStringToOUString( lt_tag_get_string( MPLANGTAG), RTL_TEXTENCODING_UTF8); + mbInitializedBcp47 = true; +#else + mnLangID = MsLangId::convertUnxByteStringToLanguage( aStr); + if (mnLangID == LANGUAGE_DONTKNOW) + { + SAL_WARN( "i18npool.langtag", "LanguageTag(rtl_Locale) - unknown: " << aStr); + mnLangID = LANGUAGE_ENGLISH_US; // we need _something_ here + } + mbInitializedLangID = true; +#endif + maLocale = lang::Locale(); + mbInitializedLocale = false; + } +} + + const rtl::OUString & LanguageTag::getBcp47( bool bResolveSystem ) const { if (!bResolveSystem && mbSystemLocale) |