Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

translation resource files get overwritten #271

Open
stoefln opened this issue Feb 28, 2024 · 3 comments
Open

translation resource files get overwritten #271

stoefln opened this issue Feb 28, 2024 · 3 comments

Comments

@stoefln
Copy link

stoefln commented Feb 28, 2024

Describe the bug

When I change a string somewhere it seems that the babel plugin regenerates the all translation files. For example I added german translations to ./extractedTranslations/de/common.json, but those were deleted when I edited some strings and the compiler ran again.

How to reproduce

I am not sure if this is only on my end, or if this is expected behavior. Am I missing a config setting somewhere?

  1. I start webpack, and my electron project
  2. Files are generated: extractedTranslations/en/common.json, extractedTranslations/de/common.json
  3. I translate a string in extractedTranslations/de/common.json and place it in the respective json field
  4. I edit some source that contains a trans string (just edit "Validate license" -> "Validate licenses")
  5. previously translated string is reset (file is probably completely regenerated)

Babel configuration:

{
  "presets": ["@babel/preset-env", "@babel/preset-react"],
  "env": {
    "production": {
      "plugins": [
        ["@babel/plugin-proposal-decorators", { "legacy": true }],
        "@babel/plugin-proposal-class-properties",
        "@babel/plugin-syntax-optional-chaining"
      ]
    },
    "development": {
      "plugins": [
        ["@babel/plugin-proposal-decorators", { "legacy": true }],
        "@babel/plugin-proposal-class-properties",
        "@babel/plugin-syntax-optional-chaining",
        "react-refresh/babel",
        [
          "i18next-extract", // https://i18next-extract.netlify.app/#/configuration
          {
            "locales": ["en", "de"],
            "defaultNS": "common",
            "keySeparator": null,
            "nsSeparator": "::",
            "defaultValue": null,
            "discardOldKeys": true,
            "tFunctionNames": ["i18nTrans"]
          }
        ]
      ]
    },
    "test": {
      "plugins": [
        ["@babel/plugin-proposal-decorators", { "legacy": true }],
        "@babel/plugin-proposal-class-properties",
        "@babel/plugin-syntax-optional-chaining"
      ]
    }
  }
}

Expected behavior

I'd expect the plugin to only remove the keys that are not existing anymore and change the ones that I changed in my sources.

What actually happens

Resource files get overwritten.

Your environment

  • OS (e.g. ArchLinux): Mac os
  • Plugin version (e.g. 0.3.0): v0.10.0
  • Node version (e.g. 12.13.0): v16.13.0
@stoefln
Copy link
Author

stoefln commented Feb 29, 2024

Just realized, that if I am restarting the webpack dev server process between the edits, that I can work around the issue. It's just really annoying and I have to be super-careful not to accidentally delete stuff that was translated already

@jmlavoier
Copy link

It seems to be an issue when using hot reload. The need of restart the server every changes I do on the code is showing that there is something wrong with this library with new webpack version. I'm trying to figure out this, but if anyone here already sorted out this, please update this issue with the solution.

@peterbernhardt
Copy link

I'm still experiencing this issue. Best workaround I know of as of now is to check in the correct versions of my JSON files to source control so I know when the plugin overwrites them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants