Comments (9)
Hi, I met the same problem when running it in an electron-react app. Do you fix the problem? I tried to write a stand-alone script, but it failed. Thank you.
from babel-plugin-react-intl.
@eddiewang Do you use "defaultMessage" prop in your FormattedMessage?
from babel-plugin-react-intl.
@dabosin yes, I do.
from babel-plugin-react-intl.
Hi, I encountered the same problem before. Please kindly check your babel plugins config in webpack.
What I did to fix the problem is that I wrote a stand-alone script to extract messages so the AST will not be polluted by additional babel plugins.
Reference: #125
from babel-plugin-react-intl.
Hi @MabelCheng , yes I did resolve it. I put a code snippet in this issue: #125
FYI:
Above problem has been resolved by:
-
Translating files using
babel-runtime
therefore we can controlpresets
andplugins
better. Prior that, we were applyingbabel-plugin-react-intl
plugin during the build time (with WebPack). Build time has lots morebabel-plugins
applied which may have side effects on the syntax trees. -
Sharing the chunk of code we made:
console.log('🥁 Starting Babel');
globSync('./src/**/!(*.stories|*.test|actions|selectors|reducers|validate).js').forEach(filePath => {
try {
console.log(`🏥 Babel is transforming ${filePath}`);
babel.transformFileSync(path.normalize(filePath), {
presets: ['flow'],
plugins: [
['transform-es2015-arrow-functions', { spec: true }],
'transform-class-properties',
'transform-object-rest-spread',
'transform-runtime',
'flow-react-proptypes',
[
'react-intl',
{
messagesDir: './src/messages',
enforceDescriptions: false,
},
],
],
});
} catch (err) {
console.error(err.message);
}
});
- You need set bindings to true to get class properties being parsed. Just FYI - How
referencesImport()
is implemented - https://npmdoc.github.io/node-npmdoc-babel-core/build/apidoc.html#apidoc.element.babel-core.traverse.NodePath.prototype.referencesImport
['transform-es2015-arrow-functions', { spec: true }],
// examples: https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-arrow-functions
from babel-plugin-react-intl.
@lzhuor can you post what your npm script looks like? Do you have a script just for parsing the translations through babel-plugin-react-intl
?
Also, what do you mean by setting bindings to true? Most of my components are not arrow functions, but rather class Component extends React.Component
.
from babel-plugin-react-intl.
@eddiewang hi, I'm new to react, just wondering how do we extract messages using babel-plugin-react-intl? Do we need to write a script to scan through the code which contains defineMessage and formattedMessage then save into json files? If so, what's the purpose of using babel-plugin when the script basically does all the jobs already?
Thanks!!!
from babel-plugin-react-intl.
@eddiewang The above example is my script for parsing intl - translate.js
.
The npm scripts:
"scripts": {
...
"translate": "babel-node ./tools/translate/translate.js",
...
},
FYI:
- how to programmatically run babel: https://babeljs.io/docs/en/babel-core.html#babeltransformfilesyncfilename-string-options-options-object
- how does babel work and mod AST: https://zhuoran.li/exploring-babel-and-ast/
from babel-plugin-react-intl.
close due to stale
from babel-plugin-react-intl.
Related Issues (20)
- react-native HOT 1
- Not working with babel-loader 8.x HOT 4
- Generate Message ID HOT 1
- The "path" argument must be of type string (v2.4.0) HOT 3
- Allow other component names than the build-in ones HOT 4
- plugin does not seem to do anything HOT 1
- file.log.warn causes TypeError: Cannot read property 'warn' of undefined HOT 3
- Am I supposed to use this plugin to obtain translation files? HOT 3
- Babel 7 support HOT 3
- Error: Cannot find module 'upath' HOT 3
- Cannot find module babel-plugin-react-intl when extracting messages HOT 1
- id containing multiple period would not work.
- [Babel 7] TypeError: Path must be a string. Received undefined HOT 7
- Any option to remove `defaultMessage` field in production? HOT 1
- cache is not working properly HOT 3
- Extracting message by formatMessage directly but defineMessages HOT 1
- Support spread syntax (or expression) for defineMessages
- Plugin does nothing, how to debug? (using with Gatsby) HOT 2
- [React Intl] `undefined()` must be called with an object expression with values that are React Intl Message Descriptors, also defined as object expressions. 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-react-intl.