Code Monkey home page Code Monkey logo

Comments (8)

gilbsgilbs avatar gilbsgilbs commented on June 15, 2024 1

Yes this is it. Passing t function as a parameter to other functions is definitely not supported and won't work as expected. If you happen to call your parameter t in getErrorMap function, keys would still be extracted in there, but useTranslation-specific features such as namespaces wouldn't work properly.

After having a closer look at the plugin code, the fact that this specific warning shows is however unintended and quite unlucky. I'm not sure what to do but given the current state of the code, it seems that the initial intent was indeed to not show anything in such cases. Maybe we should stick to it for now although I don't think it's the cleanest thing to do.

By the way this PR should fix the line numbers showing up in warnings.

from babel-plugin-i18next-extract.

gilbsgilbs avatar gilbsgilbs commented on June 15, 2024 1

Fixed in 0.2.6 🎉 .

So, the useTranslation-specific features aren't a big deal. […] Not sure how possible that even is though.

I can see at least two major reasons why it's very unlikely we'll ever be able to handle such cases using static analysis:

  • When passing t as a parameter to a function, all the context you had in it is lost. You may call the same function with another instance of t somewhere else and therefore keeping track of which namespace is bound to which instance of the t function would become a nightmare.
  • As far as I know, Babel just parses one file after another and doesn't create links between the symbols of files (like an IDE would do). That's why keeping contexts across functions that may be imported from another file would be even harder if not impossible using Babel.

from babel-plugin-i18next-extract.

gilbsgilbs avatar gilbsgilbs commented on June 15, 2024

Hi! I don't think the error is at the line you pointed out. Can you try to find which usage of the t function generate this error message? It is true that the error message isn't very correct though.

from babel-plugin-i18next-extract.

bopfer avatar bopfer commented on June 15, 2024

It definitely is that line. Here is an exact error for a specific file:

babel-plugin-i18next-extract: Extraction error in
src/features/Admin/pages/UserProfile/ProfileForm.tsx at line 104.
Couldn't evaluate i18next key. You should either make the key evaluable
or skip the line using a skip comment (/* i18next-extract-disable-line */ or
/* i18next-extract-disable-next-line */).

And the code at that line:

Screen Shot 2019-09-23 at 1 36 18 PM

Interestingly, the comment hints also don't work to stop the error.

from babel-plugin-i18next-extract.

gilbsgilbs avatar gilbsgilbs commented on June 15, 2024

What I'm trying to say is that even though the log indicates that the line 104 is at fault, it is probably not the case and it's likely to be a bug somewhere else. It must be one usage of the t function somewhere after line 104 that generates the warning.

The fact that it indicates the wrong line is another bug I'm working on.

from babel-plugin-i18next-extract.

bopfer avatar bopfer commented on June 15, 2024

Ahh, could be that. I do pass the t function into other functions as an argument. Looks like that is causing it. The error goes away if I put the comment before each of those function calls.

For example, I have stuff like this:

const errorMap = getErrorMap(t);

The error goes away if I do this:

/* i18next-extract-disable-next-line */
const errorMap = getErrorMap(t);

from babel-plugin-i18next-extract.

bopfer avatar bopfer commented on June 15, 2024

Yeah, the extracting from the other functions is working properly. I am using the comment hints to set the namespace for each file. So, the useTranslation-specific features aren't a big deal. They would be a nice thing to have. Not sure how possible that even is though.

from babel-plugin-i18next-extract.

bopfer avatar bopfer commented on June 15, 2024

That makes sense. It's no big deal. I can work around it.

Thanks for 0.2.6. It's working great!

from babel-plugin-i18next-extract.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.