[fix] pick a better default language (#1201)
This PR improves the language selection. Previously, we would miss the user's languages that included a locale. For example, if a user's languages were `['en-US', 'fr'], then they would get 'fr' because 'en-US' wasn't in our table—though 'en' was! We were already doing the splitting elsewhere but now we do it here, too. ### Release Note - Improves default language --------- Co-authored-by: Lu[ke] Wilson <l2wilson94@gmail.com>
This commit is contained in:
parent
00d4648ef5
commit
5ab93eef5f
5 changed files with 117 additions and 13 deletions
|
@ -15,7 +15,7 @@ export interface TranslationProviderProps {
|
|||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* ;<TranslationProvider overrides={{ en: { 'style-panel.styles': 'Properties' } }} />
|
||||
* <TranslationProvider overrides={{ en: { 'style-panel.styles': 'Properties' } }} />
|
||||
* ```
|
||||
*/
|
||||
overrides?: Record<string, Record<string, string>>
|
||||
|
@ -58,14 +58,13 @@ export const TranslationProvider = track(function TranslationProvider({
|
|||
let isCancelled = false
|
||||
|
||||
async function loadTranslation() {
|
||||
const localeString = locale ?? navigator.language.split(/[-_]/)[0]
|
||||
const translation = await getTranslation(localeString, getAssetUrl)
|
||||
const translation = await getTranslation(locale, getAssetUrl)
|
||||
|
||||
if (translation && !isCancelled) {
|
||||
if (overrides && overrides[localeString]) {
|
||||
if (overrides && overrides[locale]) {
|
||||
setCurrentTranslation({
|
||||
...translation,
|
||||
messages: { ...translation.messages, ...overrides[localeString] },
|
||||
messages: { ...translation.messages, ...overrides[locale] },
|
||||
})
|
||||
} else {
|
||||
setCurrentTranslation(translation)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue