-
Notifications
You must be signed in to change notification settings - Fork 224
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
Interface language #329
Interface language #329
Conversation
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.
-
it seems that when you open the Settings it does not load the user chosen language in the dropdown. After changing the language, I do not experience this issue anymore. Was the value somehow wrong and the dropdown couldn't select the given language?!We haven't been able to reproduce this issue, if it happens again then a bug should be raised.
- It would be nice feature to scroll the dropdown to the chosen language if this could be easily achieved with the current dropdown impl Multiselect search #350
Another thing that I noticed is that Settings and other parts of the application are still not translated but that is part of the stremio-translations
strings rather than this PR.
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.
I commented some minor suggestions.
if (args && args.settings && typeof args.settings.interfaceLanguage === 'string') { | ||
i18n.changeLanguage(args.settings.interfaceLanguage); | ||
} |
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 can use optional chaining to simplify this. All latest browsers except IE already support it and it's included in babel's @babel/preset-env
preset.
if (args && args.settings && typeof args.settings.interfaceLanguage === 'string') { | |
i18n.changeLanguage(args.settings.interfaceLanguage); | |
} | |
const language = args?.settings?.interfaceLanguage; | |
if (typeof language === 'string') { | |
i18n.changeLanguage(language); | |
} |
The additional const variable assignment in my suggestion is optional, but makes it even more readable imo.
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.
I did not used optional chaining because i wanted to follow the current way everything is checked in the app
Also i think in js it might be clearer to spot mistakes with this syntax since there are no linting
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.
let's indeed keep it consistent and update it all at once if the time arises
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.
There are other places where optional chaining is used. So an inconsistency already exists. I agree this is out of scope for this PR though, we can pick one style and create a refactoring PR later.
} | ||
}; | ||
const onCtxState = (state) => { | ||
if (state && state.profile && state.profile.settings && typeof state.profile.settings.interfaceLanguage === 'string') { |
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.
if (state && state.profile && state.profile.settings && typeof state.profile.settings.interfaceLanguage === 'string') { | |
if (typeof state?.profile?.settings?.interfaceLanguage === 'string') { |
services.core.transport | ||
.getState('ctx') | ||
.then(onCtxState) | ||
.catch((e) => console.error(e)); |
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.
Nitpicking but this can be even shorter :)
.catch((e) => console.error(e)); | |
.catch(console.error); |
case 'play': | ||
return props.deepLinks && typeof props.deepLinks.player === 'string'; | ||
case 'details': | ||
return props.deepLinks && (typeof props.deepLinks.metaDetailsVideos === 'string' || typeof props.deepLinks.metaDetailsStreams === 'string'); |
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.
case 'play': | |
return props.deepLinks && typeof props.deepLinks.player === 'string'; | |
case 'details': | |
return props.deepLinks && (typeof props.deepLinks.metaDetailsVideos === 'string' || typeof props.deepLinks.metaDetailsStreams === 'string'); | |
case 'play': | |
return typeof props.deepLinks?.player === 'string'; | |
case 'details': | |
return (typeof props.deepLinks?.metaDetailsVideos === 'string' || typeof props.deepLinks?.metaDetailsStreams === 'string'); |
translation: value | ||
}])); | ||
|
||
i18n |
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.
Consider adding i18next-browser-languagedetector so the webapp tries to select whatever language the browser is set to before falling back to en-US.
src/common/translateOption.js
Outdated
const translateOption = (option, translateKeyPrefix = '') => { | ||
const translateKey = `${translateKeyPrefix}${option}`; | ||
const translateKeyUppercase = translateKey.toUpperCase(); | ||
const translateValue = t(translateKey); | ||
const translateValueUppercase = t(translateKeyUppercase); | ||
if (translateKey !== translateValue) { | ||
return translateValue; | ||
} else if (translateKeyUppercase !== translateValueUppercase) { | ||
return translateValueUppercase; | ||
} | ||
return option.charAt(0).toUpperCase() + option.slice(1); | ||
}; |
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 function is relatively hard to follow. If I understand what it's doing correctly, I believe it can be heavily simplified as follows:
const translateOption = (option, translateKeyPrefix = '') => { | |
const translateKey = `${translateKeyPrefix}${option}`; | |
const translateKeyUppercase = translateKey.toUpperCase(); | |
const translateValue = t(translateKey); | |
const translateValueUppercase = t(translateKeyUppercase); | |
if (translateKey !== translateValue) { | |
return translateValue; | |
} else if (translateKeyUppercase !== translateValueUppercase) { | |
return translateValueUppercase; | |
} | |
return option.charAt(0).toUpperCase() + option.slice(1); | |
}; | |
const translateOption = (option, translateKeyPrefix = '') => { | |
const translateKey = `${translateKeyPrefix}${option}`; | |
const translateValue = t(translateKey, {defaultValue: t(translateKey.toUpperCase(), {defaultValue: null})}); | |
return translateValue ?? option.charAt(0).toUpperCase() + option.slice(1); | |
}; |
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.
Much better thank you !
|
I cannot reproduce this issue neither on chrome or firefox as guest or logged in, what steps did you take ? |
@tymmesyde I'm not sure how to reproducing this. I tried clearing cache and to login again but I don't see this @sleeyax I didn't mean search but for the select to scroll down to the picked choice when opened. |
Yes, I know, I just added my own suggestion on top :) |
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.
LGTM! @tymmesyde Decide if you'd like to tackle PR comments from @sleeyax in this PR or can be done in subsequent PR. At this stage I consider the PR ready.
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.
LGTM - Tested locally and it works.
No description provided.