diff options
author | Eike Rathke <erack@redhat.com> | 2021-10-25 11:41:09 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2021-10-25 13:07:50 +0200 |
commit | a6baab25b53d0a87686a5fcdabf86747e9678021 (patch) | |
tree | 35da354bc3ed797302cd13760320992218f3cb0d | |
parent | 98eb119fed253b0af7a3b5c9a28905d29118167f (diff) |
Introduce LanguageTag::convertToLanguageTypeWithFallback(Locale)
... with keeping LANGUAGE_SYSTEM not resolved or falling back.
Change-Id: I10211c2b2140a9822f1403dc00af3ee9ded08f69
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124140
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
-rw-r--r-- | i18nlangtag/source/languagetag/languagetag.cxx | 10 | ||||
-rw-r--r-- | include/i18nlangtag/languagetag.hxx | 10 |
2 files changed, 20 insertions, 0 deletions
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx index ebad94022615..6f6a766e861f 100644 --- a/i18nlangtag/source/languagetag/languagetag.cxx +++ b/i18nlangtag/source/languagetag/languagetag.cxx @@ -2813,6 +2813,16 @@ css::lang::Locale LanguageTag::convertToLocaleWithFallback( const OUString& rBcp // static +LanguageType LanguageTag::convertToLanguageTypeWithFallback( const css::lang::Locale& rLocale, bool bResolveSystem ) +{ + if (rLocale.Language.isEmpty() && !bResolveSystem) + return LANGUAGE_SYSTEM; + + return LanguageTag( rLocale).makeFallback().getLanguageType(); +} + + +// static bool LanguageTag::isValidBcp47( const OUString& rString, OUString* o_pCanonicalized, bool bDisallowPrivate ) { bool bValid = false; diff --git a/include/i18nlangtag/languagetag.hxx b/include/i18nlangtag/languagetag.hxx index 62957f1f7f70..4fbb6d0c2e11 100644 --- a/include/i18nlangtag/languagetag.hxx +++ b/include/i18nlangtag/languagetag.hxx @@ -507,6 +507,16 @@ public: */ static css::lang::Locale convertToLocaleWithFallback( const OUString& rBcp47 ); + /** Convert Locale to MS-LangID with fallback. + + @param bResolveSystem + If TRUE, resolve an empty language tag denoting the system + locale to the real locale used and fallback. + If FALSE, return LANGUAGE_SYSTEM for such a tag and do not fallback. + */ + static LanguageType convertToLanguageTypeWithFallback( const css::lang::Locale& rLocale, + bool bResolveSystem = true ); + /** If rString represents a valid BCP 47 language tag. Never resolves an empty tag to the system locale, in fact an empty |