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

addResourceBundle mutates its argument "resources" #2081

Closed
sadstag opened this issue Dec 11, 2023 · 1 comment
Closed

addResourceBundle mutates its argument "resources" #2081

sadstag opened this issue Dec 11, 2023 · 1 comment

Comments

@sadstag
Copy link

sadstag commented Dec 11, 2023

🐛 Bug Report

Hi, First sorry if it is not a bug, but perhaps it deserves a word in the documentation if not.

It's about reusing the same base translation for different namespaces, and doing it using the same object for base.

As the sample code shows, the function addResouceBundle mutates its third parameters, leading to confusion

To Reproduce

https://codesandbox.io/p/sandbox/test-z3hr2l

import i18n from "i18next";

const base = { k1: { k2: "v" } };

i18n.init({ fallbackLng: "en"})
  .then((t) => {
    i18n.addResourceBundle("en", "ns1", base);
    i18n.addResourceBundle(
      "en",
      "ns1",
      { k1: { k2: "v for ns1" } },
      true,
      true
    );

    // reusing base : fail
    i18n.addResourceBundle("en", "ns2", base); // work : i18n.addResourceBundle('en', 'ns2',  deepCopy(base)}
    i18n.addResourceBundle(
      "en",
      "ns2",
      { k1: { k2: "v for ns2" } },
      true,
      true
    );

    console.log({ translated: t("ns1:k1.k2") });
    document.getElementById("app")!.innerHTML = `t("ns1:k1.k2")=${t(
      "ns1:k1.k2"
    )}`;
  });

Expected behavior

Naively expecting : "v for ns1", but get "v for ns2" instead.

Maybe a deepcopy done by the library itself, so that it prints v for ns1 or a few word accompagnying the document for addResourceBundle

Your Environment

  • runtime version: Chrome 120.0.6099.62 (Build officiel) (64 bits)
  • i18next version: 23.7.8
  • os: Linux
@adrai adrai closed this as completed in d2d7608 Feb 17, 2024
@adrai
Copy link
Member

adrai commented Feb 17, 2024

should be addressed with v23.8.3

heharm pushed a commit to wanderlog/i18next that referenced this issue Aug 15, 2024
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