added LanguageTag::getFallbackStrings()
Change-Id: Ia597cb184e0402e776cde50967541f008e22d4c9
This commit is contained in:
parent
ca04dec8b9
commit
8d23b47454
2 changed files with 61 additions and 0 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue