summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2013-02-16 02:29:18 +0100
committerEike Rathke <erack@redhat.com>2013-02-18 17:51:20 +0100
commit8d23b47454043122b61b2e1dc08d84ee09e1a081 (patch)
treed68c29c7cecad732c1f1f37501934a8ea3a6d4a0 /i18npool
parentca04dec8b9670d936395771da43818f00e670482 (diff)
added LanguageTag::getFallbackStrings()
Change-Id: Ia597cb184e0402e776cde50967541f008e22d4c9
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/inc/i18npool/languagetag.hxx21
-rw-r--r--i18npool/source/languagetag/languagetag.cxx40
2 files changed, 61 insertions, 0 deletions
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 <i18npool/i18npooldllapi.h>
#include <i18npool/lang.h>
+#include <vector>
+
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.