Skip to content
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 logic for setting the locale when using System Default #4570

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,8 @@ function runApp() {
})

ipcMain.handle(IpcChannels.GET_SYSTEM_LOCALE, () => {
return app.getLocale()
// we should switch to getPreferredSystemLanguages at some point and iterate through until we find a supported locale
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the non-electron fallback we can use navigator.languages instead of navigator.language.

return app.getSystemLocale()
})

ipcMain.handle(IpcChannels.GET_USER_DATA_PATH, () => {
Expand Down
19 changes: 10 additions & 9 deletions src/renderer/store/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,20 @@ const stateWithSideEffects = {
let targetLocale = value
if (value === 'system') {
const systemLocaleName = (await getSystemLocale()).replace('-', '_') // ex: en_US
const systemLocaleLang = systemLocaleName.split('_')[0] // ex: en
const targetLocaleOptions = allLocales.filter((locale) => { // filter out other languages
const systemLocaleSplit = systemLocaleName.split('_') // ex: en
const targetLocaleOptions = allLocales.filter((locale) => {
// filter out other languages
const localeLang = locale.replace('-', '_').split('_')[0]
return localeLang.includes(systemLocaleLang)
return localeLang.includes(systemLocaleSplit[0])
}).sort((a, b) => {
const aLocaleName = a.replace('-', '_')
const bLocaleName = b.replace('-', '_')
const aLocale = aLocaleName.split('_') // ex: [en, US]
const bLocale = bLocaleName.split('_')
if (aLocale.includes(systemLocaleName)) { // country & language match, prefer a

if (aLocaleName === systemLocaleName) { // country & language match, prefer a
return -1
} else if (bLocale.includes(systemLocaleName)) { // country & language match, prefer b
} else if (bLocaleName === systemLocaleName) { // country & language match, prefer b
return 1
} else if (aLocale.length === 1) { // no country code for a, prefer a
return -1
Expand All @@ -337,12 +339,11 @@ const stateWithSideEffects = {
return aLocaleName.localeCompare(bLocaleName)
}
})

if (targetLocaleOptions.length > 0) {
targetLocale = targetLocaleOptions[0]
}

// Go back to default value if locale is unavailable
if (!targetLocale) {
} else {
// Go back to default value if locale is unavailable
targetLocale = defaultLocale
// Translating this string isn't necessary
// because the user will always see it in the default locale
Expand Down
2 changes: 1 addition & 1 deletion static/locales/pt-PT.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Put the name of your locale in the same language
Locale Name: Português
Locale Name: Português (PT)
FreeTube: FreeTube
# Currently on Subscriptions, Playlists, and History
'This part of the app is not ready yet. Come back later when progress has been made.': >-
Expand Down