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
Bug 1998347: fix user preference for language and sync with local storage #9902
Bug 1998347: fix user preference for language and sync with local storage #9902
Conversation
@nemesis09: This pull request references Bugzilla bug 1998347, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker. 3 validation(s) were run on this bug
No GitHub users were found matching the public email listed for the QA contact in Bugzilla (gamore@redhat.com), skipping review request. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@nemesis09: This pull request references Bugzilla bug 1998347, which is valid. 3 validation(s) were run on this bug
No GitHub users were found matching the public email listed for the QA contact in Bugzilla (gamore@redhat.com), skipping review request. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
2 similar comments
@nemesis09: This pull request references Bugzilla bug 1998347, which is valid. 3 validation(s) were run on this bug
No GitHub users were found matching the public email listed for the QA contact in Bugzilla (gamore@redhat.com), skipping review request. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@nemesis09: This pull request references Bugzilla bug 1998347, which is valid. 3 validation(s) were run on this bug
No GitHub users were found matching the public email listed for the QA contact in Bugzilla (gamore@redhat.com), skipping review request. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/assign @spadgett |
3aee537
to
e3f1644
Compare
export const getSystemLocale = () => { | ||
return ( | ||
(navigator.languages && navigator.languages.length && navigator.languages[0]) || // array of user's preferred languages ordered by preference with the most preferred language first. supported by most browsers in their latest version. https://developer.mozilla.org/en-US/docs/Web/API/Navigator/languages | ||
navigator.language || // user's preferred language. fallback in case navigator.languages is not supported. | ||
navigator.userLanguage // fallback compatibility for IE older versions | ||
); | ||
}; |
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.
Please make a typescript file here so that we have ?. operator and use as any hack below to support IE. Did you know which IE version we supports with this workaround?
export const getSystemLocale = () => { | |
return ( | |
(navigator.languages && navigator.languages.length && navigator.languages[0]) || // array of user's preferred languages ordered by preference with the most preferred language first. supported by most browsers in their latest version. https://developer.mozilla.org/en-US/docs/Web/API/Navigator/languages | |
navigator.language || // user's preferred language. fallback in case navigator.languages is not supported. | |
navigator.userLanguage // fallback compatibility for IE older versions | |
); | |
}; | |
export const getSystemLocale = () => { | |
return ( | |
// array of user's preferred languages ordered by preference with the most preferred language first. supported by most browsers in their latest version. https://developer.mozilla.org/en-US/docs/Web/API/Navigator/languages | |
navigator.languages?.[0] || | |
// user's preferred language. fallback in case navigator.languages is not supported. | |
navigator.language || | |
// fallback compatibility for IE older versions | |
(navigator as any).userLanguage | |
); | |
}; |
import { useUserSettings } from '@console/shared/src/hooks/useUserSettings'; | ||
import { deseralizeData } from '@console/shared/src/utils/user-settings'; | ||
|
||
export const useUserSettingsLocalStorageSync = ( |
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.
Please remove this unused file
React.useEffect(() => { | ||
if (preferredLanguageLoaded && !preferredLanguage) { | ||
i18n.changeLanguage(defaultLocale); | ||
setPreferredLanguage(defaultPreference); | ||
} | ||
// run this hook only after all resources have loaded | ||
// to set the preferred language user setting when the form loads | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [preferredLanguageLoaded]); | ||
|
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.
Please do not save the preferred language when open the user preferences this could save unexpected values only because this page is opened.
preferredLanguage || | ||
// handles languages we support, languages we don't support, and subsets of languages we support (such as en-us, zh-cn, etc.) | ||
i18n.languages.find((lang) => supportedLocales[lang]); | ||
const defaultPreference: string = `${PREFERRED_LANGUAGE_DEFAULT_VALUE_PREFIX}${defaultLocale}`; |
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.
Please just save null (or undefined, or nothing) until the user selects a preferred language.
const localeOptions: { [key: string]: string } = { | ||
...supportedLocales, | ||
[defaultPreference]: 'Browser default', | ||
}; |
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 think its might be easier to keep selectOptions
independent from the "Browser default" select option. You can maybe add a <SelectOption>
just before {selectOptions}
in the select? Wdyt?
Please also make "Browser default" translatable.
As discussed:
|
frontend/packages/console-app/src/components/user-preferences/language/getPreferredLanguage.ts
Outdated
Show resolved
Hide resolved
frontend/packages/console-app/src/components/user-preferences/language/getPreferredLanguage.ts
Outdated
Show resolved
Hide resolved
frontend/packages/console-app/src/components/user-preferences/language/usePreferredLanguage.ts
Outdated
Show resolved
Hide resolved
74acb27
to
e09a6ee
Compare
updated implementation according to latest UX designs and review comments |
@nemesis09: This pull request references Bugzilla bug 1998347, which is valid. 3 validation(s) were run on this bug
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
<Skeleton | ||
height="15px" | ||
width="100%" | ||
data-test={'checkbox skeleton console.preferredLanguage'} |
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.
data-test={'checkbox skeleton console.preferredLanguage'} | |
data-test="checkbox skeleton console.preferredLanguage" |
<Skeleton | ||
height="30px" | ||
width="100%" | ||
data-test={'dropdown skeleton console.preferredLanguage'} |
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.
data-test={'dropdown skeleton console.preferredLanguage'} | |
data-test="dropdown skeleton console.preferredLanguage" |
frontend/public/i18n.js
Outdated
lng: localStorage.getItem('bridge/language'), | ||
fallbackLng: 'en', | ||
lng: getPreferredLanguage(), | ||
fallbackLng: 'ja', |
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.
Why is fallback ja
?
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.
Ahh!
I was testing and overlooked while cleaning up.
import { usePreferredLanguage, useLanguage } from '../user-preferences/language'; | ||
|
||
const DetectLanguage: React.MemoExoticComponent<() => any> = React.memo(() => { | ||
const [preferredLanguage, , preferredLanguageLoaded] = usePreferredLanguage(); |
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.
Did we lose the query parameter detection for language?
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 think i18next-browser-languageDetector
handles that. The old language preference modal didn't seem to detect language from query params as well.
The Detect Language
just populates the local storage on first load if there is a preferred language in configmap but the same does not reflect in local storage.
This will be useful if the user changes browser after setting a language preference.
PREFERRED_LANGUAGE_USER_SETTING_KEY, | ||
PREFERRED_LANGUAGE_LOCAL_STORAGE_KEY, | ||
); | ||
] => useUserSettings<string>(PREFERRED_LANGUAGE_USER_SETTING_KEY, null, true); |
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.
Will this reset the language to the browser default on upgrade from 4.8 -> 4.9 since we're no longer calling useUserSettingsCompatibility
?
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.
yes it will. as discussed, updated to use useUserSettingsCompatibility
and take the preference in local storage into consideration.
e09a6ee
to
fb50c4e
Compare
@@ -4,3 +4,5 @@ export const supportedLocales = { | |||
ko: '한국어', | |||
ja: '日本語', | |||
}; | |||
|
|||
export const PREFERRED_LANGUAGE_LOCAL_STORAGE_KEY = 'bridge/preferredLanguage'; |
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 would call this something like last-language
or cached-language
to make it more clear what it is. The user preference is the source of truth.
@@ -0,0 +1,4 @@ | |||
import { PREFERRED_LANGUAGE_LOCAL_STORAGE_KEY } from './const'; | |||
|
|||
export const getPreferredLanguage = (): 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.
Same here. We should rename this utility so it's clear it's not the current preference. Rather it's the last-known value.
export const getPreferredLanguage = (): string => | |
export const getLastLanguage = (): string => |
Just a few comments. Should we keep all of the settings in a single view for now? Beau and I had discussed doing that for now since we lost most of the Language and region settings as a part of this round and wait on adding the tab and moving language until we add those in the future? If we keep the two separate tabs should the name be Language for now (since there is nothing related to region as apart of the MVP)? Can we add spacing between the check box content and the dropdown? @beaumorley do you have any other comments? |
@megan-hall I think reorganizing the tabs would need to be a follow on since this is a release blocking bug. Smaller changes like labels and spacing are probably OK to address here as long as they aren't too difficult. |
fb50c4e
to
43114c4
Compare
@spadgett @megan-hall It is great that we are getting language moved to user preferences. Is there a way we could at least remove the "& region" from the tab name? Since it is just language right now? |
That shouldn't be an issue, @nemesis09 can you take a look? |
43114c4
to
203929d
Compare
renamed |
@@ -174,7 +175,7 @@ export const useValuesForQuickStartContext = (): QuickStartContextValues => { | |||
[activeQuickStartID, setAllQuickStartStates, fireTelemetryEvent], | |||
); | |||
|
|||
const language = localStorage.getItem('bridge/language') || 'en'; | |||
const language = getLastLanguage() || 'en'; |
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.
Not new, but en
is not the right default. Can you open a separate bug to look at this?
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.
@@ -0,0 +1,3 @@ | |||
.co-user-preference-language-checkbox { | |||
margin-bottom: var(--pf-global--spacer--sm) !important; |
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.
Not indented.
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.
Ahh! I thought the linter handles it.
Fixed indentation.
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.
Unfortunately, we don't use prettier or a linter for CSS yet :/ We have a story to add it.
@@ -0,0 +1,3 @@ | |||
.co-user-preference-language-checkbox { |
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 should follow BEM naming, something like
.co-user-preference-language-checkbox { | |
.co-language-dropdown__system-default-checkbox { |
@@ -0,0 +1,3 @@ | |||
.co-user-preference-language-checkbox { | |||
margin-bottom: var(--pf-global--spacer--sm) !important; | |||
} |
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.
Missing final newline.
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.
fixed
203929d
to
c9f34e4
Compare
c9f34e4
to
ab94a64
Compare
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
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: nemesis09, spadgett The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
2 similar comments
/retest |
/retest |
/retest-required Please review the full test history for this PR and help us cut down flakes. |
@nemesis09: All pull requests linked via external trackers have merged: Bugzilla bug 1998347 has been moved to the MODIFIED state. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@nemesis09: Bugzilla bug 1998347 is in an unrecognized state (MODIFIED) and will not be moved to the MODIFIED state. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Epic:
https://issues.redhat.com/browse/ODC-5227
Story:
https://issues.redhat.com/browse/ODC-6326
Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1998347
Problem/Statement:
The language preference set from the user preference page is not honored when console loads.
In the absence of a preference, the console defaults to English, ignoring "browser preference".
Waiting for user preference could also cause delay in loading of the console.
Solution/Description:
maintain the language preference in local storage in sync with the user settings.
load the console with value from local storage and update when the user settings loads
if a preference is not found in user settings or local storage, use browser preference for language as default
maintain the existing language preference from older release in the event of an upgrade
Screens:
Test Coverage:
TBD
Browser Conformance: