i18next-parser: Default value is not respected for

  • Is this a bug or a feature request? Bug
  • What version are you running (0.x or 1.x)? 1.0.2
  • Which runner (cli, gulp…)? cli

What I’m trying to do?

Trying to extract key from <Trans>A text</Trans>

How am I doing it?

i18next --config i18next-parser.config.js

Here is my config file:

{
  contextSeparator: '_',
  createOldCatalogs: false,
  defaultNamespace: 'translation',
  defaultValue: ''
  keepRemoved: false,
  keySeparator: false,
  lexers: {
    hbs: ['HandlebarsLexer'],
    handlebars: ['HandlebarsLexer'],

    htm: ['HTMLLexer'],
    html: ['HTMLLexer'],

    mjs: ['JavascriptLexer'],
    js: ['JavascriptLexer'], // if you're writing jsx inside .js files, change this to JsxLexer
    ts: ['JavascriptLexer'],
    jsx: ['JsxLexer'],
    tsx: ['JsxLexer'],

    default: ['JavascriptLexer'],
  },

  lineEnding: 'auto',
  locales: ['en', 'it'],

  namespaceSeparator: '::',
  output: 'public/locales/$LOCALE/$NAMESPACE.json',
  input: [`src/**/*.{ts,tsx}`],
  reactNamespace: true,
  sort: true,
  useKeysAsDefaultValue: false,
  verbose: false,
}

The command I’m running:

i18next --config i18next-parser.config.js

What was the result?

{
  "A text": "A text"
}

What was I expecting?

{
  "A text": ""
}

About this issue

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

Commits related to this issue

Most upvoted comments

I’m sorry, but I’m not familiar with your code base at all, and have a full time job myself. The problem that the original ticket describes is still there, I cannot see any changes in version 3 as mentioned above.

In brief, content of <Trans> component is extracted from the code using the dev language, and puts in it all other language files (in English in my case). I’d expect empty value as for simple t functions.

For example: <Trans i18key="text">A text</Trans>

is extracted in French etc as "{"text": "A text"}

while I would expect to see: "{"text": ""}

Maybe if you can point me on where the related code is, I can come up with something.

Picking up on this:

<Trans key="123" defaultValue="hello world" /> gets extracted as 123: ""

same with <Trans key="456" defaults="hello this is an <1>a tag</1>" />

Is this the expected behavior?