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): Translation component issue returning undefined instead of defaultValue #3313

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ const Translation = ({ i18nKey, defaultValue, ...rest }) => {
const key = i18nKey || camelCase(defaultValue);
const translation = i18next.t(key, { defaultValue });

// i18next returns 'undefined' if the default value happens to be the key for a set of definitions
// ```
// "components": {
// "componentDef": "Translated Component Def"
// }
// ```
// In this case, a request for i18next.t("components", "defaultValue") will return undefined
// but i18next.t("components.componentDef", "defaultValue") will return correctly
//
// This checks to see if translation is undefined and returns the default value instead
if (typeof translation === "undefined") {
return (
<span {...rest}>{defaultValue}</span>
);
}

return (
<span {...rest}>{translation}</span>
);
Expand Down