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

Randomly JSON.parse Error when using i18n extract plugin #202

Closed Vita-Meow closed 3 years ago

Vita-Meow commented 3 years ago

Describe the bug Hi, we currently using i18n and as well as this plugin, but we have a strange and random i18n extract error when we run our tests in jest, looks like this. Same PR or code sometimes it can pass all tests, sometimes it will have the random error look like happening in this plugin. Does someone have any ideas? image

How to reproduce

It's randomly occurred

Babel configuration:

{
  "presets": [
    ["@babel/preset-env", { "targets": { "node": "current" } }],
    "@babel/preset-typescript",
    "@babel/preset-react"
  ],
  "plugins": [
    "i18next-extract"
  ]
}
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import Backend from 'i18next-http-backend';
import LanguageDetector from 'i18next-browser-languagedetector';
import Pseudo from 'i18next-pseudo';

const pseudoTranslator = new Pseudo({
  enabled: false,
  languageToPseudo: 'en',
  wrapped: true,
});
// eslint-disable-next-line @typescript-eslint/no-floating-promises -- i18n is a promise
i18n
  .use(pseudoTranslator)
  .use(Backend)
  .use(LanguageDetector)
  .use(initReactI18next)
  .init({
    defaultNS: 'common',
    postProcess: ['pseudo'],
    ns: ['common', 'home'],
    fallbackLng: 'en',
    lowerCaseLng: true,
    debug: process.env.NODE_ENV === 'development',
    interpolation: {
      escapeValue: false,
    },
    saveMissing: true,
    backend: {
      loadPath: 'locales/{{lng}}/{{ns}}.json',
      crossDomain: true,
    },
    keySeparator: false,
    react: {
      transSupportBasicHtmlNodes: true,
      transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
      useSuspense: false,
    },
  });

export const eanblePseudoTranslator = (): void => {
  pseudoTranslator.configurePseudo({ enabled: true });
};
export const disablePseudoTranslator = (): void => {
  pseudoTranslator.configurePseudo({ enabled: false });
};

export default i18n;

Expected behavior

What actually happens

Your environment

Additional context

Vita-Meow commented 3 years ago

Close it by just remove this plugin when we run test since it does not need to be in test stage