React-admin: Disable missing Translation Warnings?

Created on 14 Jun 2017  路  4Comments  路  Source: marmelab/react-admin

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

Most helpful comment

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

All 4 comments

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

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.

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)
}

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kmaschta picture Kmaschta  路  3Comments

ericwb picture ericwb  路  3Comments

samanmohamadi picture samanmohamadi  路  3Comments

kdabir picture kdabir  路  3Comments

9747749366 picture 9747749366  路  3Comments