Skip to content

Commit

Permalink
simpler locale fall back code, fixes #5257
Browse files Browse the repository at this point in the history
Signed-off-by: Jamie McClelland <jm@mayfirst.org>
  • Loading branch information
jmcclelland authored and backportbot-nextcloud[bot] committed Sep 9, 2023
1 parent 4fb4d6e commit 8a4969b
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/utils/moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,16 @@ async function getLocaleFor(locale) {
} catch (error) {
const splitLocale = locale.split('-')
try {
// failure: fallback to de
locale = splitLocale[1]
// failure: fallback to first part of locale, which
// should be language
locale = splitLocale[0]

Check warning on line 88 in src/utils/moment.js

View check run for this annotation

Codecov / codecov/patch

src/utils/moment.js#L88

Added line #L88 was not covered by tests
await import(`moment/locale/${locale}.js`)
return locale
} catch (e) {
try {
// failure: fallback to en
locale = splitLocale[0]
await import(`moment/locale/${locale}.js`)
return locale
} catch (e) {
// failure, fallback to english
console.debug('Fallback to locale', 'en')
// English is the default locale and doesn't need to imported.
// It is already included in moment.js.
}
// failure, fallback to english
console.debug('Fallback to locale', 'en')

Check warning on line 93 in src/utils/moment.js

View check run for this annotation

Codecov / codecov/patch

src/utils/moment.js#L93

Added line #L93 was not covered by tests
// English is the default locale and doesn't need to imported.
// It is already included in moment.js.
}
}

Expand Down

0 comments on commit 8a4969b

Please sign in to comment.