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

Key incorrect extraction when nsSeparator > 1 symbol #195

Open
CarrotIronfoundersson opened this issue Jun 29, 2021 · 1 comment
Open

Key incorrect extraction when nsSeparator > 1 symbol #195

CarrotIronfoundersson opened this issue Jun 29, 2021 · 1 comment

Comments

@CarrotIronfoundersson
Copy link

CarrotIronfoundersson commented Jun 29, 2021

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

  • Win10 x64
  • Plugin version 0.8.3
  • Node version 14.17.0

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
Copy link

Encountering the same issue here.

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

2 participants