i18next-scanner: Unable to parse Trans component with the content

I am using i18next for react-native@0.58.3 i18next cannot parse Trans component , I see similar topics but not helped me

Version

  • i18next: 14.0.1
  • i18next-scanner: 2.9.1

Configuration

module.exports = {
  options: {
    debug: true,
    removeUnusedKeys: true,
    sort: true,
    func: {
      list: [
        't',
      ],
      extensions: [
        '.js',
        '.jsx',
      ],
    },
    trans: {
      component: 'Trans',
      i18nKey: 'i18nKey',
      defaultsKey: 'defaults',
      extensions: [
        '.js',
        '.jsx',
      ],
      fallbackKey: function(ns, value) {
        return value;
      },
    },
    lngs: [
      'en-US',
      'en-GB',
    ],
    ns: [
      'translation',
    ],
    defaultLng: 'en-US',
    defaultNs: 'translation',
    defaultValue(lng, ns, key) {
      return key;
    },
    resource: {
      loadPath: 'src/locales/{{lng}}/{{ns}}.json',
      savePath: 'src/locales/{{lng}}/{{ns}}.json',
      jsonIndent: 2,
      lineEnding: '\n',
    },
    nsSeparator: false,
    keySeparator: false,
    interpolation: {
      prefix: '{{',
      suffix: '}}',
    },
  },
};

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

First, why are you trying typescript or flow? I think you should know what language you write your program in. If you don’t know then I don’t know either and can’t solve your problem. If you are writing in pure javascript remove type lines and then you don’t need custom transform.

@sm2017 There are 1.5 problem in your code. First you parse for Trans twice. First time, default parsing (this will report error), second time custom parsing but you have problem with custom parsing.

You can disable default parsing (and error) with:

    trans: {
            component: 'Trans',
            extensions: [],
        },

Now custom parsing will still not work. If you will write console.log(code) you will see that bunch of plugins are used. console.log(code.code) will show that your code is transformed slightly too much and you have lost jsx. Because of that i18next-scanner will not be able to parse strings from Trans components because there is no Trans component anymore in jsx form. You can delete babel.config.js and problem with too many plugins will go away. I will leave it for you to figure out how to make it work with babel.config.js - I mean how to ignore babel.config.js in customTransform function.