From 8d23b47454043122b61b2e1dc08d84ee09e1a081 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Sat, 16 Feb 2013 02:29:18 +0100 Subject: added LanguageTag::getFallbackStrings() Change-Id: Ia597cb184e0402e776cde50967541f008e22d4c9 --- i18npool/inc/i18npool/languagetag.hxx | 21 +++++++++++++++ i18npool/source/languagetag/languagetag.cxx | 40 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) (limited to 'i18npool') diff --git a/i18npool/inc/i18npool/languagetag.hxx b/i18npool/inc/i18npool/languagetag.hxx index 3394c1b99fa8..324fcd3da165 100644 --- a/i18npool/inc/i18npool/languagetag.hxx +++ b/i18npool/inc/i18npool/languagetag.hxx @@ -16,6 +16,8 @@ #include #include +#include + typedef struct _rtl_Locale rtl_Locale; // as in rtl/locale.h @@ -212,6 +214,25 @@ public: */ LanguageTag & makeFallback(); + /** Return a vector of fall-back strings. + + In order: + full BCP 47 tag, same as getBcp47() + lll-Ssss-CC + lll-Ssss + 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. + */ + ::std::vector< OUString > getFallbackStrings() const; + /* Test equality of two LangageTag. */ bool operator==( const LanguageTag & rLanguageTag ) const; diff --git a/i18npool/source/languagetag/languagetag.cxx b/i18npool/source/languagetag/languagetag.cxx index 31b1ae0875e3..33b2c57e398f 100644 --- a/i18npool/source/languagetag/languagetag.cxx +++ b/i18npool/source/languagetag/languagetag.cxx @@ -1003,6 +1003,46 @@ LanguageTag & LanguageTag::makeFallback() } +::std::vector< OUString > LanguageTag::getFallbackStrings() const +{ + ::std::vector< OUString > aVec; + OUString aLanguage( getLanguage()); + OUString aCountry( getCountry()); + if (isIsoLocale()) + { + if (!aCountry.isEmpty()) + aVec.push_back( aLanguage + "-" + aCountry); + aVec.push_back( aLanguage); + return aVec; + } + aVec.push_back( getBcp47()); + OUString aTmp; + if (hasScript()) + { + OUString aScript( getScript()); + if (!aCountry.isEmpty()) + { + aTmp = aLanguage + "-" + aScript + "-" + aCountry; + if (aTmp != aVec[0]) + aVec.push_back( aTmp); + } + aTmp = aLanguage + "-" + aScript; + if (aTmp != aVec[0]) + aVec.push_back( aTmp); + } + if (!aCountry.isEmpty()) + { + aTmp = aLanguage + "-" + aCountry; + if (aTmp != aVec[0]) + aVec.push_back( aTmp); + } + aTmp = aLanguage; + if (aTmp != aVec[0]) + aVec.push_back( aTmp); + return aVec; +} + + bool LanguageTag::operator==( const LanguageTag & rLanguageTag ) const { // Compare full language tag strings but SYSTEM unresolved. -- cgit