react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

Disable missing Translation Warnings?

Open thochi opened this issue 9 years ago • 7 comments

Is it possible to disable the translation warnings if we don't use i18n?

thochi avatar Jun 14 '17 14:06 thochi

Not possible currently. Polyglot does support allowing undefined translations (see its options) however. This would requires an additional prop to disable custom translations.

This babel plugin might be useful: babel-plugin-transform-dev-warning

djhi avatar Jun 14 '17 21:06 djhi

Which translation warnings are you seeing? It must be on your custom components, because aor components don't throw translation warnings in case of missing translation for a field label. It uses the (non-documented- default translation everywhere:

translate(label, { _: label }

As for the interface labels ("Save", "Filter", etc), they must always be in your translation dictionary. If they are not, that's a bug, and the warning should not be silenced.

fzaninotto avatar Jun 28 '17 15:06 fzaninotto

Temporary you can override console.error.

var originalLog = console.error
console.error = function log(...args) {
	if (args.length > 0 && typeof args[0] === "string" && /^Warning: Missing translation/.test(args[0])) {
		return
	}
	originalLog.apply(console, args)
}

onka13 avatar Apr 04 '19 15:04 onka13

Solved it by adding a custom i18nProvider that allows missing keys:

const i18nProvider = polyglotI18nProvider(locale => i18nMessages[locale], 'en', { allowMissing: true });

<Admin
    i18nProvider={i18nProvider}
    ...
 >

More details: https://marmelab.com/react-admin/Translation.html and: https://www.npmjs.com/package/node-polyglot#options-overview

fvoordeckers avatar Sep 01 '20 08:09 fvoordeckers

Which package gives me the "i18nMessages" instance?

caiquejjx avatar Feb 12 '21 00:02 caiquejjx

Which package gives me the "i18nMessages" instance?

@caiquejjx That's a dict you build containing all the locales you want to support

fvoordeckers avatar Feb 17 '21 12:02 fvoordeckers

  • it would be good to see one line entries instead of printing the whole stack trace with each one missing translation...

EDIT

  • which can be achieved by adjusting the functionality of i18nProvider...
const KEEP_DEV_CONSOLE_WITHOUT_ERRORS = true;
/**
 * https://marmelab.com/react-admin/Translation.html
 * https://www.npmjs.com/package/node-polyglot#options-overview
 *
 * https://github.com/marmelab/react-admin/issues/758
 */
export const i18nProvider = polyglotI18nProvider(
  (locale: string) => {
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore
    return messages[locale];
  },
  initialLocale,
  {
    allowMissing: KEEP_DEV_CONSOLE_WITHOUT_ERRORS,
    onMissingKey: (missingKey: string) => {
      console.info(`[i18nProvider.tsx] ${missingKey}}`);
    },
  }
);

image

dkocich avatar Nov 05 '21 11:11 dkocich