-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Fix browser language detection for region specific languages (#8982) #9026
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
Changes from 2 commits
f80f83f
25cd7c7
440f8c2
6117055
e651b7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,9 +36,21 @@ export function findAvailableLanguage(language: string) { | |
| return LOCALE_LOOKUP[langLower]; | ||
| } | ||
|
|
||
| return Object.keys(translationMetadata.translations).find( | ||
| let translation = Object.keys(translationMetadata.translations).find( | ||
| (lang) => lang.toLowerCase() === langLower | ||
| ); | ||
| if (translation) { | ||
| return translation; | ||
| } | ||
|
|
||
| if (language.includes("-")) { | ||
| translation = findAvailableLanguage(language.split("-")[0]); | ||
| if (translation) { | ||
| return translation; | ||
| } | ||
|
rmogstad marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| return null; | ||
|
rmogstad marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -94,13 +106,6 @@ export function getLocalLanguage() { | |
| if (language) { | ||
| return language; | ||
| } | ||
| if (navigator.language && navigator.language.includes("-")) { | ||
| language = findAvailableLanguage(navigator.language.split("-")[0]); | ||
| if (language) { | ||
| return language; | ||
| } | ||
| } | ||
|
Comment on lines
-97
to
-102
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think adding it to language = findAvailableLanguage(locale);
if (language) {
return language;
}
if (locale.includes("-")) {
language = findAvailableLanguage(locale.split("-")[0]);
if (language) {
return language;
}
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I see. I misunderstood what navigator.language was. I will make a method and call it in both places.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made a change that is a little different. I couldn't think of a good name for the helper function, and it seemed like something we would want to always check when searching for an available translation, so I added it to that function. I'll understand if you prefer not to have the recursive call there and want me to break it out differently. This is my first time doing a CR on github, first time submitting to HA (or any OS project, for that matter), and first time working with TS, so I'm not super familiar with the industry best practices, nor with the project best practices. I am more than happy to make changes to make it I am in the discord (@Zondebok) if you want to discuss directly. |
||
|
|
||
| // Final fallback | ||
| return "en"; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.