diff options
author | Eike Rathke <erack@redhat.com> | 2013-03-27 22:18:32 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2013-03-27 22:20:05 +0100 |
commit | a1554c121f5f810c77b70ece3d11522a48091d0f (patch) | |
tree | c60728d36740c89d539752f0ae386afea96494a9 /i18npool/source | |
parent | 97257aeef6c402b34e316eeccd9b022940a805cd (diff) |
added LanguageTag::getFallback()
Similar to comphelper::Locale::getFallback() but implemented
differently. comphelper::Locale is to be removed later.
Change-Id: I99dc7b51029df102705f2608245c91d81dc96788
Diffstat (limited to 'i18npool/source')
-rw-r--r-- | i18npool/source/languagetag/languagetag.cxx | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/i18npool/source/languagetag/languagetag.cxx b/i18npool/source/languagetag/languagetag.cxx index 7b284b5a4a8c..be6e228f6ecf 100644 --- a/i18npool/source/languagetag/languagetag.cxx +++ b/i18npool/source/languagetag/languagetag.cxx @@ -1159,4 +1159,51 @@ LanguageTag::Extraction LanguageTag::simpleExtract( const OUString& rBcp47, } +// static +::std::vector< OUString >::const_iterator LanguageTag::getFallback( + const ::std::vector< OUString > & rList, const OUString & rReference ) +{ + if (rList.empty()) + return rList.end(); + + ::std::vector< OUString >::const_iterator it; + + // Try the simple case first without constructing fallbacks. + for (it = rList.begin(); it != rList.end(); ++it) + { + if (*it == rReference) + return it; // exact match + } + + ::std::vector< OUString > aFallbacks( LanguageTag( rReference).getFallbackStrings()); + aFallbacks.erase( aFallbacks.begin()); // first is full BCP47, we already checked that + if (rReference != "en-US") + aFallbacks.push_back( "en-US"); + if (rReference != "en") + aFallbacks.push_back( "en"); + if (rReference != "x-default") + aFallbacks.push_back( "x-default"); + if (rReference != "x-no-translate") + aFallbacks.push_back( "x-no-translate"); + /* TODO: the original comphelper::Locale::getFallback() code had + * "x-notranslate" instead of "x-no-translate", but all .xcu files use + * "x-no-translate" and "x-notranslate" apparently was never used anywhere. + * Did that ever work? Was it supposed to work at all like this? */ + + for (::std::vector< OUString >::const_iterator fb = aFallbacks.begin(); fb != aFallbacks.end(); ++fb) + { + for (it = rList.begin(); it != rList.end(); ++it) + { + if (*it == *fb) + return it; // fallback found + } + } + + // Did not find anything so return something of the list, the first value + // will do as well as any other as none did match any of the possible + // fallbacks. + return rList.begin(); +} + + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |