From 08d76ef1041a922042403253cea79c0b216517f8 Mon Sep 17 00:00:00 2001 From: Spencer Norman Date: Fri, 17 Nov 2017 12:14:02 -0700 Subject: [PATCH 1/3] (fix): Fix translation component issue returning undefined instead of defaultValue When the translation component is passed a defaultValue that matches an i18n key with an object value, `i18next.t` returns `undefined` instead of the default value. Our Translation component was then returning an empty string in place of the default value for these translations. This commit fixes that and returns the defaultValue if `i18next.t` returns `undefined` // i18next returns 'undefined' if the default value happens to be the key for a set of definitions Example of the issue example en.json file ``` ... "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 --- .../components/translation/translation.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/imports/plugins/core/ui/client/components/translation/translation.js b/imports/plugins/core/ui/client/components/translation/translation.js index d05050f3d6d..eb2893bceb1 100644 --- a/imports/plugins/core/ui/client/components/translation/translation.js +++ b/imports/plugins/core/ui/client/components/translation/translation.js @@ -8,6 +8,23 @@ 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 ( + {defaultValue} + ); + } + + return ( {translation} ); From 8edf095316d4f171344340580320a9dc20cd5f78 Mon Sep 17 00:00:00 2001 From: Spencer Norman Date: Mon, 20 Nov 2017 11:05:21 -0700 Subject: [PATCH 2/3] Remove space after spread operator --- .../core/ui/client/components/translation/translation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imports/plugins/core/ui/client/components/translation/translation.js b/imports/plugins/core/ui/client/components/translation/translation.js index eb2893bceb1..27fb1bacf3e 100644 --- a/imports/plugins/core/ui/client/components/translation/translation.js +++ b/imports/plugins/core/ui/client/components/translation/translation.js @@ -20,7 +20,7 @@ const Translation = ({ i18nKey, defaultValue, ...rest }) => { // This checks to see if translation is undefined and returns the default value instead if (typeof translation === "undefined") { return ( - {defaultValue} + {defaultValue} ); } From 736abadc05e4b048ad80838917fe99bee327c484 Mon Sep 17 00:00:00 2001 From: Spencer Norman Date: Mon, 20 Nov 2017 11:06:37 -0700 Subject: [PATCH 3/3] Remove unnecessary extra blank line. --- .../plugins/core/ui/client/components/translation/translation.js | 1 - 1 file changed, 1 deletion(-) diff --git a/imports/plugins/core/ui/client/components/translation/translation.js b/imports/plugins/core/ui/client/components/translation/translation.js index 27fb1bacf3e..507db1f0185 100644 --- a/imports/plugins/core/ui/client/components/translation/translation.js +++ b/imports/plugins/core/ui/client/components/translation/translation.js @@ -24,7 +24,6 @@ const Translation = ({ i18nKey, defaultValue, ...rest }) => { ); } - return ( {translation} );