mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) User language switcher
Summary: New language selector on the Account page for logged-in users. New icon for switching language for an anonymous user. For anonymous users, language is stored in a cookie grist_user_locale. Language is stored in user settings for authenticated users and takes precedence over what is stored in the cookie. Test Plan: New tests Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D3766
This commit is contained in:
@@ -68,3 +68,17 @@ try {
|
||||
}
|
||||
|
||||
currencies = [...currencies].sort((a, b) => nativeCompare(a.code, b.code));
|
||||
|
||||
|
||||
export function getCountryCode(locale: string) {
|
||||
// We have some defaults defined.
|
||||
if (locale === 'en') { return 'US'; }
|
||||
let countryCode = locale.split(/[-_]/)[1];
|
||||
if (countryCode) { return countryCode.toUpperCase(); }
|
||||
countryCode = locale.toUpperCase();
|
||||
// Test if we can use language as a country code.
|
||||
if (localeCodes.map(code => code.split(/[-_]/)[1]).includes(countryCode)) {
|
||||
return countryCode;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user