gilbsgilbs / babel-plugin-i18next-extract

Babel plugin that statically extracts i18next and react-i18next translation keys.
https://i18next-extract.netlify.com
MIT License
161 stars 37 forks source link

discardOldKeys removes phrases when shared by multiple files #181

Open chrys1110 opened 3 years ago

chrys1110 commented 3 years ago

Describe the bug

with discardOldKeys: true already translated keys get removed when multiple files share the same namespaces. i.E Both depend on namespace 'errors' and import them with useTranslation. fileA uses errorA. fileB uses errorB. Babel extracts errorA when compiling fileA and dismisses errorB, and vice versa. Already translated terms get removed unfortunately.

How to reproduce

Described above.

Babel configuration:

{
    "presets": [
        "next/babel"
    ],
    "plugins": [
        [
            "i18next-extract",
            {
                "locales": [
                    "en-US",
                    "de"
                ],
                "defaultNS": "common",
                "discardOldKeys": true,
                "jsonSpace": 4,
                "useI18nextDefaultValue": [
                    "en-US"
                ],
                "outputPath": "public/static/locales/{{locale}}/{{ns}}.json",
                "customUseTranslationHooks": [
                    ["next-i18next", "useTranslation"]
                ]
            }
        ]
    ]
}