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

Interface language #329

Merged
merged 18 commits into from
Apr 13, 2023
Merged

Interface language #329

merged 18 commits into from
Apr 13, 2023

Conversation

tymmesyde
Copy link
Member

No description provided.

@elpiel elpiel requested review from nklhtv and elpiel and removed request for nklhtv March 10, 2023 12:45
@elpiel elpiel linked an issue Mar 10, 2023 that may be closed by this pull request
Copy link
Member

@elpiel elpiel left a 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.

Screenshot from 2023-03-15 10-48-59

  • 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.

@elpiel elpiel requested a review from sleeyax March 17, 2023 14:47
sleeyax
sleeyax previously approved these changes Mar 17, 2023
Copy link
Member

@sleeyax sleeyax left a 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.

Comment on lines +98 to +100
if (args && args.settings && typeof args.settings.interfaceLanguage === 'string') {
i18n.changeLanguage(args.settings.interfaceLanguage);
}
Copy link
Member

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.

Suggested change
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.

Copy link
Member Author

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

Copy link
Member

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

Copy link
Member

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') {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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));
Copy link
Member

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 :)

Suggested change
.catch((e) => console.error(e));
.catch(console.error);

Comment on lines +22 to +25
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');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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');

Comment on lines +22 to +25
translation: value
}]));

i18n
Copy link
Member

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.

Comment on lines 5 to 16
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);
};
Copy link
Member

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:

Suggested change
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);
};

Copy link
Member Author

Choose a reason for hiding this comment

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

Much better thank you !

@sleeyax
Copy link
Member

sleeyax commented Mar 17, 2023

  • It would also be nice if the user could type the language they are looking for as they open the language selector. Just like elpiel mentioned, I'm not sure how hard this would be to add to the current dropdown implementation, but this is definitely something builtin into most browsers native select element and could work the same way here.

@tymmesyde
Copy link
Member Author

  • 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?!

I cannot reproduce this issue neither on chrome or firefox as guest or logged in, what steps did you take ?

@tymmesyde tymmesyde mentioned this pull request Mar 20, 2023
@elpiel
Copy link
Member

elpiel commented Mar 23, 2023

@tymmesyde I'm not sure how to reproducing this. I tried clearing cache and to login again but I don't see this afr value anymore.
Is it possible that my User data was corrupted with a bad value for the language in the first place?

@sleeyax I didn't mean search but for the select to scroll down to the picked choice when opened.
But a search functionality might be a good idea in the long run, though, we don't have that many languages and that's why I think this is low priority.

@sleeyax
Copy link
Member

sleeyax commented Mar 23, 2023

@tymmesyde I'm not sure how to reproducing this. I tried clearing cache and to login again but I don't see this afr value anymore.
Is it possible that my User data was corrupted with a bad value for the language in the first place?

@sleeyax I didn't mean search but for the select to scroll down to the picked choice when opened.
But a search functionality might be a good idea in the long run, though, we don't have that many languages and that's why I think this is low priority.

Yes, I know, I just added my own suggestion on top :)

elpiel
elpiel previously approved these changes Apr 12, 2023
Copy link
Member

@elpiel elpiel left a 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.

@tymmesyde tymmesyde dismissed stale reviews from elpiel and sleeyax via 02fceea April 12, 2023 12:00
@elpiel elpiel requested a review from sleeyax April 12, 2023 14:36
Copy link
Member

@elpiel elpiel left a 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.

package.json Show resolved Hide resolved
@tymmesyde tymmesyde merged commit 5705233 into development Apr 13, 2023
@nklhtv nklhtv deleted the interface-language branch May 25, 2023 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Translations and interface language
3 participants