Alias locales to moment supported locales

Moment doesn't have aliases for every locale and doesn't parse some locale IDs correctly so we need to alias them

Close #27982

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
This commit is contained in:
Thomas Citharel 2021-08-12 15:22:00 +02:00 committed by nextcloud-command
parent 9603069cc7
commit 092e6be473
3 changed files with 24 additions and 4 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -103,10 +103,30 @@ const initLiveTimestamps = () => {
}, 30 * 1000)
}
/**
* Moment doesn't have aliases for every locale and doesn't parse some locale IDs correctly so we need to alias them
*/
const localeAliases = {
zh: 'zh-cn',
zh_Hans: 'zh-cn',
zh_Hans_CN: 'zh-cn',
zh_Hans_HK: 'zh-cn',
zh_Hans_MO: 'zh-cn',
zh_Hans_SG: 'zh-cn',
zh_Hant: 'zh-hk',
zh_Hant_HK: 'zh-hk',
zh_Hant_MO: 'zh-mo',
zh_Hant_TW: 'zh-tw',
}
let locale = OC.getLocale()
if (Object.prototype.hasOwnProperty.call(localeAliases, locale)) {
locale = localeAliases[locale]
}
/**
* Set users locale to moment.js as soon as possible
*/
moment.locale(OC.getLocale())
moment.locale(locale)
/**
* Initializes core