-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add aliases #682
Comments
maybe you can add your own helper function to fix this at the moment. like
|
This works for the moment, thanks. For anyone looking for something like that.: const dayjs = require('dayjs')
const UTC = require('dayjs/plugin/utc')
const LocalizedFormat = require('dayjs/plugin/localizedFormat')
const { isDev } = require('../environment.js')
const availableLanguages = ['en', 'de']
// include locale for each available language
require('dayjs/locale/de')
const localeHelper = lang => {
const locale = availableLanguages.find(locale => {
if (locale === lang) {
return true
}
const regex = new RegExp(`${locale}-.*`)
return regex.test(lang)
})
return locale ? locale : availableLanguages[0]
}
module.exports = () => {
const lang = window.navigator.language
const locale = localeHelper(lang)
dayjs.extend(LocalizedFormat)
dayjs.extend(UTC)
dayjs.locale(locale)
if (isDev) {
console.log('Preferred language:', lang, locale)
}
} |
I'll close this issue since it's been a while since it's been opened. Feel free to reopen if you have updates on this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the feature
I want to set dayjs locale with
window.navigator.language
. The problem is, that in my case,window.navigator.language
returnsde-DE
which is not a valid format. It would be great if you could add aliases.Here is a SO question with a list of valid locales, but I guess there must be something on the internet that browsers use as reference: https://stackoverflow.com/questions/3191664/list-of-all-locales-and-their-short-codes
The text was updated successfully, but these errors were encountered: