diff options
author | Julius Härtl <jus@bitgrid.net> | 2020-02-03 22:29:02 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2020-03-29 15:40:07 +0300 |
commit | 78e220daad36917d65ffae159f7aba99cf60cbfc (patch) | |
tree | ac4cfd7484482c93eeea11e8269e457f27490e29 | |
parent | e7d83b9c955e658e5fef9e7148018ebc9fd82d75 (diff) |
Fix lang handling
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r-- | src/helpers/index.js | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/helpers/index.js b/src/helpers/index.js index 31cf98b4..d473571f 100644 --- a/src/helpers/index.js +++ b/src/helpers/index.js @@ -23,9 +23,30 @@ import { getLanguage, getLocale } from 'nextcloud-l10n' const languageToBCP47 = () => { + let language = getLanguage().replace(/_/g, '-') + let locale = getLocale() + + // German formal should just be treated as 'de' + if (language === 'de-DE') { + language = 'de' + } + // special case where setting the bc47 region depending on the locale setting makes sense + const whitelist = { + de: { + 'de_CH': 'de-CH', + 'gsw': 'de-CH', + 'gsw_CH': 'de-CH' + } + } + const matchingWhitelist = whitelist[language] + if (typeof matchingWhitelist !== 'undefined' && typeof matchingWhitelist[locale] !== 'undefined') { + return matchingWhitelist[locale] + } + // loleaflet expects a BCP47 language tag syntax - return (getLanguage() + '-' + getLocale()) - .replace(/^([a-z]{2}).*_([A-Z]{2})$/, (match, p1, p2) => p1 + '-' + p2.toLowerCase()) + // when a the nextcloud language constist of two parts we sent both + // as the region is then provided by the language setting + return language } const getNextcloudVersion = () => { |