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

Key incorrect extraction when nsSeparator > 1 symbol #195

Open CarrotIronfoundersson opened 3 years ago

CarrotIronfoundersson commented 3 years ago

Describe the bug Extracted keys include extra symbols at the front when nsSeparator is set to more then 1 symbol.

How to reproduce Set nsSeparator to more then 1 symbol, like double colon nsSeparator: '::'

Babel configuration:

{
  "presets": ["@babel/preset-react"],
  "plugins": [
    "@babel/plugin-proposal-class-properties",
    "@babel/plugin-syntax-dynamic-import",
    [
      "i18next-extract",
      {
        "locales": ["fr"],
        "defaultNS": "common",
        "keySeparator": null,
        "nsSeparator": "::",
        "defaultValue": null
      }
    ]
  ]
}

Reproduction:

import { useTranslation } from 'react-i18next';

const { t } = useTranslation('customers', 'common');

{t('common::Cancel')};
{t('common::OK')};
{t('common::Close')}

Expected behavior common.json:

{
  "Cancel": null,
  "Close": null,
  "OK": null
}

What actually happens

{
  ":Cancel": null,
  ":Close": null,
  ":OK": null
}

Your environment

Workarounds In node_modules\babel-plugin-i18next-extract\index.js

function parseExtractedKey(key, config), line 1685 :

Before:

cleanKey = cleanKey.slice(nsSeparatorPos + 1);

After:

cleanKey = cleanKey.slice(nsSeparatorPos + config.nsSeparator.length);
DannyvanHolten commented 2 years ago

Encountering the same issue here.