[Libreoffice-commits] core.git: i18nlangtag/source include/i18nlangtag
Eike Rathke (via logerrit)
logerrit at kemper.freedesktop.org
Fri Aug 20 22:12:26 UTC 2021
i18nlangtag/source/languagetag/languagetagicu.cxx | 22 ++++++++++++++++++++++
include/i18nlangtag/languagetagicu.hxx | 17 +++++++++++++++++
2 files changed, 39 insertions(+)
New commits:
commit c482aefe08e4486aa35ba87edea1a341c97b8610
Author: Eike Rathke <erack at redhat.com>
AuthorDate: Fri Aug 20 22:47:08 2021 +0200
Commit: Eike Rathke <erack at redhat.com>
CommitDate: Sat Aug 21 00:11:47 2021 +0200
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 at redhat.com>
Tested-by: Jenkins
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: */
diff --git a/include/i18nlangtag/languagetagicu.hxx b/include/i18nlangtag/languagetagicu.hxx
index 755d8eb12c76..430c483f344d 100644
--- a/include/i18nlangtag/languagetagicu.hxx
+++ b/include/i18nlangtag/languagetagicu.hxx
@@ -15,6 +15,7 @@
#include <string_view>
#include <i18nlangtag/i18nlangtagdllapi.h>
+#include <rtl/ustring.hxx>
#include <unicode/locid.h>
class LanguageTag;
@@ -49,6 +50,22 @@ public:
Always resolves an empty tag to the system locale.
*/
static icu::Locale getIcuLocale( const LanguageTag & rLanguageTag, std::u16string_view rVariant, std::u16string_view rKeywords);
+
+ /** Obtain the display name for a language tag.
+
+ Gets a localized name from icu::Locale::getDisplayName(). Meant to be
+ used only with language tags that do not have a language list entry in
+ svtools/inc/langtab.hrc STR_ARR_SVT_LANGUAGE_TABLE, thus used by
+ SvtLanguageTable::GetLanguageString()
+
+ @param rLanguageTag
+ The language tag for which the name is to be displayed.
+
+ @param rDisplayLanguage
+ The language in which the name is to be displayed.
+ Usually Application::GetSettings().GetUILanguageTag().
+ */
+ static OUString getDisplayName( const LanguageTag & rLanguageTag, const LanguageTag & rDisplayLanguage );
};
#endif // INCLUDED_I18NLANGTAG_LANGUAGETAGICU_HXX
More information about the Libreoffice-commits
mailing list