summaryrefslogtreecommitdiff
path: root/i18nlangtag
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2021-08-20 22:47:08 +0200
committerEike Rathke <erack@redhat.com>2021-08-21 00:11:47 +0200
commitc482aefe08e4486aa35ba87edea1a341c97b8610 (patch)
treeabff2197f2e20e1be88be483c6e984157bdd1d0d /i18nlangtag
parentf4b80f4e060a68aa35a7ec678d18af989e82f055 (diff)
Introduce LanguageTagIcu::getDisplayName()
To be used in generating display names for on-the-fly language tags in the language listbox. Change-Id: Ibb36fe312e550f77f1e2d3acc2dbff9e83c15f7b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120797 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins
Diffstat (limited to 'i18nlangtag')
-rw-r--r--i18nlangtag/source/languagetag/languagetagicu.cxx22
1 files changed, 22 insertions, 0 deletions
diff --git a/i18nlangtag/source/languagetag/languagetagicu.cxx b/i18nlangtag/source/languagetag/languagetagicu.cxx
index c35e7a85ef8b..fd1c9bc75670 100644
--- a/i18nlangtag/source/languagetag/languagetagicu.cxx
+++ b/i18nlangtag/source/languagetag/languagetagicu.cxx
@@ -46,4 +46,26 @@ icu::Locale LanguageTagIcu::getIcuLocale( const LanguageTag & rLanguageTag, std:
);
}
+// static
+OUString LanguageTagIcu::getDisplayName( const LanguageTag & rLanguageTag, const LanguageTag & rDisplayLanguage )
+{
+ // This will be initialized by the first call; as the UI language doesn't
+ // change the tag mostly stays the same, unless someone overrides it for a
+ // call here, and thus obtaining the UI icu::Locale has to be done only
+ // once.
+ static thread_local LanguageTag aUITag( LANGUAGE_SYSTEM);
+ static thread_local icu::Locale aUILocale;
+
+ if (aUITag != rDisplayLanguage)
+ {
+ aUITag = rDisplayLanguage;
+ aUILocale = getIcuLocale( rDisplayLanguage);
+ }
+
+ icu::Locale aLocale( getIcuLocale( rLanguageTag));
+ icu::UnicodeString aResult;
+ aLocale.getDisplayName( aUILocale, aResult);
+ return OUString( reinterpret_cast<const sal_Unicode*>(aResult.getBuffer()), aResult.length());
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */