Comments (3)
Hi,
Thanks for raising an issue.
I don't know anything about ICU and I'll have to read more about it and how it integrates with i18next before I can give you a relevant answer.
About the detection of Trans components that are imported from the macro, maybe #33 could help, but if we don't want to wait for it we could also add macro imports in the existing whitelist. I'm not sure it would really do what you expect in any case: it would consider the Trans component from the macro to be a normal Trans component. I reckon we're looking for something slightly more subtle than that, isn't it?
Once I found this project, I realized how much cleaner it would be if the macro could run first, transform the source to handle the funky ICU format curly braces, then the extractor wouldn't need to know any special format, and would just have a "normal" Trans element to work with.
This is in theory. In practice, I don't think Babel gives you much control over when transformations happen. And you might get bitten by some other transformation if it happens too early (e.g. JSX). That's why the plugin currently runs on the Program node (the root node) and traverses the untransformed AST from there (to ensure no transformation has taken place). I'm definitely not against changing this (since it is terrible performance-wise), yet we have to be very careful about it.
I'm also considering allowing third-party plugins (extractors and exporters) at some point (probably not really short term though). Maybe ICU could be a good use-case for a custom exporter.
Sorry if I missed the point. I'm not against some more examples so that I can have the bigger picture.
from babel-plugin-i18next-extract.
I have a workaround in referencesImport that adds an additional fallback if the bindings don't exist properly, to just look up the import in the ImportDeclarations. Would that be a welcome PR?
Do you mean adding || referencesImport(openingElement.get('name'), 'react-i18next/icu.macro', 'Trans')
to isTransComponent
function? Do you have a fork where I could see what you've done? I don't think I have anything against adding basic support for components from the macro, as long as it doesn't require very deep complications to the code.
from babel-plugin-i18next-extract.
I was just adding this in referencesImport
before the last return false
:
const existingImport = nodePath.hub.file.path.node.body.find(
importNode => BabelTypes.isImportDeclaration(importNode) && importNode.source.value === 'react-i18next',
);
if (existingImport) return true;
return false;
It's failing some tests in the repo so I have to figure that out, but it's working in my app. And I can probably tighten up the checks to be a bit more targeted.
I'm running the plugin like this:
package.json:
"locales:extract": "NODE_ENV=development babel --config-file ./i18next-extract-babel.js 'src/**/*.js'",
i18next-extract-babel.js:
module.exports = {
presets: ['react-app'],
plugins: [
'macros',
[
'i18next-extract',
{
keySeparator: null,
},
],
],
}
from babel-plugin-i18next-extract.
Related Issues (20)
- Action Required: Fix Renovate Configuration
- Randomly JSON.parse Error when using i18n extract plugin HOT 1
- Support i18next JSON v4's format HOT 5
- Translations not extracted when `t` is used as a template tag literal
- when running tests, I get a warning
- Align Trans key extraction with react-i18next for elements with i18nIsDynamicList
- Ability to extract plurals from defaultValues HOT 1
- Using discardOldKeys keeps only strings from last file
- Allow specifying fallback-functions to parse AST-node for extractors
- Allow defining defaults in the "i18next-extract-mark-context-next-line" directive HOT 1
- extraction not working for TransComponent HOT 5
- Feature key prefixes
- excludes doesn't seem to work HOT 1
- One project where "nested
- Race condition in extract HOT 4
- Can't get an Array of strings to translate HOT 1
- Support fallback keys
- Add comment hint to explicitly register translation keys
- Adding count to t options throws error at computeDerivedKeys and causes webpack build to fail HOT 1
- [BUG][0.9.1] Latest Release Packaging is broken? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from babel-plugin-i18next-extract.