summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2013-07-11 17:41:59 +0200
committerEike Rathke <erack@redhat.com>2013-07-11 17:48:14 +0200
commit38522416bd6a85f206b8c294726dd2e3d6a63567 (patch)
tree58279bb8d56882acce9192516f2ace83df1860f4 /scripting
parent00de85cc75e3501a5597c2f293407b1b76fef429 (diff)
use LanguageTag::getMatchingFallback()
Change-Id: Ib6fd9581728bdd7c32ccec9ce538d9b4c5658b04
Diffstat (limited to 'scripting')
-rw-r--r--scripting/Library_stringresource.mk1
-rw-r--r--scripting/source/stringresource/stringresource.cxx31
2 files changed, 11 insertions, 21 deletions
diff --git a/scripting/Library_stringresource.mk b/scripting/Library_stringresource.mk
index bd59637365be..daa63868d629 100644
--- a/scripting/Library_stringresource.mk
+++ b/scripting/Library_stringresource.mk
@@ -25,6 +25,7 @@ $(eval $(call gb_Library_use_libraries,stringresource,\
cppuhelper \
sal \
tl \
+ i18nlangtag \
$(gb_UWINAPI) \
))
diff --git a/scripting/source/stringresource/stringresource.cxx b/scripting/source/stringresource/stringresource.cxx
index c5c8b91f9b7f..7a80699bcb3b 100644
--- a/scripting/source/stringresource/stringresource.cxx
+++ b/scripting/source/stringresource/stringresource.cxx
@@ -36,6 +36,7 @@
#include <rtl/ustrbuf.hxx>
#include <rtl/strbuf.hxx>
#include <tools/urlobj.hxx>
+#include <i18nlangtag/languagetag.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::lang;
@@ -679,33 +680,21 @@ LocaleItem* StringResourceImpl::getItemForLocale
return pRetItem;
}
-// Returns the LocalItem for a given locale, if it exists, otherwise NULL
-// This method performes a closest match search, at least the language must match
+// Returns the LocaleItem for a given locale, if it exists, otherwise NULL.
+// This method performs a closest match search, at least the language must match.
LocaleItem* StringResourceImpl::getClosestMatchItemForLocale( const Locale& locale )
{
LocaleItem* pRetItem = NULL;
- // Search for locale
- for( sal_Int32 iPass = 0 ; iPass <= 2 ; ++iPass )
+ ::std::vector< Locale > aLocales( m_aLocaleItemVector.size());
+ for( LocaleItemVectorConstIt it = m_aLocaleItemVector.begin(); it != m_aLocaleItemVector.end(); ++it )
{
- for( LocaleItemVectorConstIt it = m_aLocaleItemVector.begin(); it != m_aLocaleItemVector.end(); ++it )
- {
- LocaleItem* pLocaleItem = *it;
- if( pLocaleItem )
- {
- Locale& cmp_locale = pLocaleItem->m_locale;
- if( cmp_locale.Language == locale.Language &&
- (iPass > 1 || cmp_locale.Country == locale.Country) &&
- (iPass > 0 || cmp_locale.Variant == locale.Variant) )
- {
- pRetItem = pLocaleItem;
- break;
- }
- }
- }
- if( pRetItem )
- break;
+ LocaleItem* pLocaleItem = *it;
+ aLocales.push_back( pLocaleItem ? pLocaleItem->m_locale : Locale());
}
+ ::std::vector< Locale >::const_iterator iFound( LanguageTag::getMatchingFallback( aLocales, locale));
+ if (iFound != aLocales.end())
+ pRetItem = *(m_aLocaleItemVector.begin() + (iFound - aLocales.begin()));
return pRetItem;
}