gilbsgilbs / babel-plugin-i18next-extract

Babel plugin that statically extracts i18next and react-i18next translation keys.

Home Page:https://i18next-extract.netlify.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow defining defaults in the "i18next-extract-mark-context-next-line" directive

ymoran00 opened this issue · comments

commented

I have the following tranlation in code:

// i18next-extract-mark-context-next-line ["type1", "type2", "type3"]
t('label', 'Type-1', {context: type})

There are 3 possible labels here, dependent on "type" prop.
When I run i18n-extract I need to translations json to have this entry:

labe_type1: "Type-1",
label_type2: "Type-2",
label_type3: "Type-3"

But since there is no way to define the defaults in the i18next-extract-mark-context-next-line directive, what I get is:

labe_type1: "",
label_type2: "",
label_type3: ""

This means that each time I run extraction, my English dictionary gets overwritten for these keys with empty values.
I need a way to define the expected defaults also in the i18next-extract-mark-context-next-line directive

Possible solution is to allow the directive to be written like this:

// i18next-extract-mark-context-next-line ["type1=Type-1", "type2=Type-2", "type3=Type-3"]

or something to that effect (whatever fits best the current comment scheme.

maybe a simplest solution can be add a new comment to specify custom extractions like

// i18next-extract-mark type1 type-1
// i18next-extract-mark label defaultValue