Skip to content

Commit

Permalink
chore(i18n): add warning logging for missed keys [#40]
Browse files Browse the repository at this point in the history
  • Loading branch information
Drapegnik committed Oct 21, 2018
1 parent 50143e5 commit 6bd7057
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion components/common/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ const SEPARATOR = '||';

const defaultRender = text => <>{text}</>;

const extract = key => {
const translation = get(dict, key, '');
if (!translation && !__PROD__) {
console.warn('[i18n]: No translation for ', key);
}
return translation;
};

export const localize = (id, lang) =>
get(dict, `${id}.${lang}`) || get(dict, `${id}.${DEFAULT_LOCALE}`) || '';
extract(`${id}.${lang}`) || extract(`${id}.${DEFAULT_LOCALE}`);

const Text = ({ id, children, render = children }) => (
<LocaleContext.Consumer>
Expand Down

0 comments on commit 6bd7057

Please sign in to comment.