1

I use i18next-parser to parse my tsx code but i cannot find the proper configuration argument, i want to fill the value the same string as key is in generated translation.json. It mean that the default values must be the same the key it-self.

I expect use the text string as the keys and as a value, so i found the default config on i18next-parser github but there is no clear explanation what use as default value.

Currently my generated translation.json

{
  "Hello world header!": ""
}

but i need it like this:

{
  "Hello world header!": "Hello world header!"
}

Here is my i18next-parser.config.ts almost default config

export default {
  contextSeparator: '::',// <---- this was customized by me
  defaultValue: '',
  ...
};

1 Answers1

1

I found a solution: the defaultValue maybe a function so it receives the key and get and return the value using regex and my contextSeparator which is set to contextSeparator: '::' in i18next-parser.config.ts (see in the question). So dont forget to replace :: to your contextSeparator

I configured it like this

export default {
  contextSeparator: '::',// <---- this was customized by me
  defaultValue: (locale: string, namespace: string, key: string) =>
    key.match(/^(.*(?=::\w*)|.*(?!::\w*))/g)?.[0],,
  ...
};