-
Notifications
You must be signed in to change notification settings - Fork 3
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
fix(locale): fallback to device preferences instead of 'en' #864
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Grigorii K. Shartsev <[email protected]>
4fefcdb
to
5ccded6
Compare
/** | ||
* Returns the user's locale | ||
*/ | ||
export function getLocale(): string { | ||
return document.documentElement.dataset.locale || 'en' | ||
return document.documentElement.dataset.locale || environmentLocale.replace(/-/g, '_') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only replaces the first instance of -
but BCP47 allows also adding the script which might become a thing for us. Because there are some languages using Latin and Cyrillic script. One popular one is Serbian.
So possible variants:
sr-Latn-RS
sr-Cyrl-RS
@@ -22,7 +24,7 @@ export function getCanonicalLocale(): string { | |||
* Returns the user's language | |||
*/ | |||
export function getLanguage(): string { | |||
return document.documentElement.lang || 'en' | |||
return document.documentElement.lang || environmentLocale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Language is not locale, probably better:
return document.documentElement.lang || environmentLocale | |
return document.documentElement.lang || navigator.language || navigator.userLanguage |
setLanguage('zu') | ||
expect(getLanguage()).toBe('zu') | ||
it('returns the environment locale with underscore if no locale is set', () => { | ||
const environmentLocale = Intl.DateTimeFormat().resolvedOptions().locale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO this should be mocked otherwise there is no control what this value will be
|
||
it('Returns extended locales with hyphens', () => { | ||
setLocale('az_Cyrl_AZ') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are loosing the test case of having the script information in the locale
When language or locale is not available,
@nextcloud/l10n
fallbacks to'en'
.Instead, fallback to the environment (aka Web-Brrowser/OS) settings.
Alternative: fallback locale to language instead of system locale.