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

Keys not being extracted when comment is inside React components #988

Open
Myzel394 opened this issue Mar 13, 2024 · 2 comments
Open

Keys not being extracted when comment is inside React components #988

Myzel394 opened this issue Mar 13, 2024 · 2 comments

Comments

@Myzel394
Copy link

🐛 Bug Report

According to https://github.com/i18next/i18next-parser?tab=readme-ov-file#caveats, you need to write a comment and declare all your translation keys so that i18next-parser can pick them up correctly. When you use a comment inside a React evaluation, this doesn't seem to be working.

To Reproduce

const Component = () => {
    const myVariable = "a";  // "a" or "b" or "c"

    return (
        <div>
            {/* 
                t("Test.a")
                t("Test.b")
                t("Test.c")
            */}
            <span>{t(`Test.${myVariable}`)}</span>
        </div>
    );
};

Expected behavior

The keys Test.a, Test.b and Test.c should get extracted. However, they don't. The following example does work:

const Component = () => {
    const myVariable = "a";  // "a" or "b" or "c"

    /* 
                t("Test.a")
                t("Test.b")
                t("Test.c")
            */
    return (
        <div>
            <span>{t(`Test.${myVariable}`)}</span>
        </div>
    );
};

Your Environment

  • runtime version: node v20.10.0
  • i18next version: 23.10.0
  • i18next-parser version: 8.13.0
  • os: Mac
  • any other relevant information
@Myzel394
Copy link
Author

For anyone wondering why keys are not being recognized in the format of:

//t("key1")

you need to make sure to add a space between "//" and "t" 🤦 :

// t("key1")

this is something that should be mentioned in the docs.

@strfngr
Copy link

strfngr commented Aug 8, 2024

Same problem 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