-
Notifications
You must be signed in to change notification settings - Fork 504
feat(@clayui/localized-input): LPD-50722 Use Language Picker for switching languages #6049
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
base: master
Are you sure you want to change the base?
Conversation
…anslated if total is 0
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.
Thanks Patrick... just a couple things.
Also, the ticket is missing this, but we had discussed that we should use the trigger-without-language-label version of the Language selector since it takes up less space. Can you update to use that? With that change it will also be important to ensure that version of the Language Selector has a tooltip so that it's clear for accessibility.
Thanks.
displayType = 'info'; | ||
label = messages.default; | ||
} else if (translation) { | ||
if (translation) { |
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.
Since we are now checking if translation exists, we should make it an optional prop. translation?
<LanguagePicker | ||
defaultLocaleId={defaultLanguage.id} | ||
locales={languagePickerLocales} | ||
onSelectedLocaleChange={(locale: any) => |
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 call this localeId to make it clearer.
const languagePickerLocales = useMemo(() => { | ||
locales.forEach((locale, index) => { | ||
if (!locale.id) { | ||
locales[index]!['id'] = locale.label; |
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.
Currently this is mutating the array, which can cause big problems in React. Instead we can simplify this with the following:
locales.forEach((locale, index) => {
return locales.map(locale => ({
id: locale.label,
...locale,
}))
}, []);
This will create a new array and also let a passed id take precedence over using the label as the id.
} else { | ||
displayType = 'secondary'; | ||
label = sub(messages.translating, [translated, total]); | ||
if (total !== 0) { |
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 logic doesn't seem right. This means the only way to display the untranslated message would be if total is 0. But I think total refers to "total available translations", so this isn't correct. It should probably be if (translated !== 0)
since translated refers to which of the available translations have been translated.
total: 1, | ||
translated: translations[selectedLocale.label] ? 1 : 0, | ||
}; | ||
}, [translations]); |
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 can all be updated to something like this:
const languagePickerTranslations = useMemo(() => {
const languagePickerTranslations = {};
locales.forEach((locale) => {
languagePickerTranslations[locale.symbol] = {
total: 1, // this should always be one because we just have one input being translated.
translated: translations[locale.symbol] ? 1 : 0],
};
}
return languagePickerTranslations;
}, [locales, translations]);
For localized input the status label should never be "translating", so make sure to check that.
Also, an empty string should be rendered as untranslated, not translated. Test this by adding a translation and then removing it.
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.
@ethib137 in the storybook, translations
keys match locales
label values. The symbol values are lower case. translations[locale.symbol]
returns undefined because en-us
should be en-US
should lower case keys still be valid or should it be an exact match?
I'm also getting an error when trying to apply clay/packages/clay-localized-input/src/index.tsx Lines 27 to 32 in a9af679
messages .clay/packages/clay-core/src/language-picker/LanguagePicker.tsx Lines 24 to 31 in a9af679
I get the same error when trying to apply directly to the LanguagePicker story. clay/packages/clay-core/stories/LanguagePicker.stories.tsx Lines 145 to 154 in a9af679
I can't figure out how the data should be organized. |
https://liferay.atlassian.net/browse/LPD-50722