-
Notifications
You must be signed in to change notification settings - Fork 121
Does this work with create-react-app? #108
Comments
Related issue: facebook/create-react-app#1227 (comment) |
It’s possible to trigger babel-plugin-react-intl manually without ejecting (at least using a recent version of react-create-app). Also, using react-intl-translations-manager it’s possible to easily maintain the translations required by react-intl. Step 1 Install the following packages. npm install @babel/cli babel-plugin-react-intl react-intl-translations-manager --save-dev Step 2 Create a {
"presets": ["react-app"],
"plugins": [
[
"react-intl", {
"messagesDir": "translations/messages",
}
]
]
} Step 3 Create a const manageTranslations = require('react-intl-translations-manager').default;
manageTranslations({
messagesDirectory: 'translations/messages',
translationsDirectory: 'src/translations/locales/',
languages: ['fr', 'en']
}); Step 4 Add the following properties ( {
"scripts": {
"messages": "NODE_ENV=production babel src/**/*.tsx >/dev/null",
"locales": "node ./translationRunner.js",
"translate": "npm run messages; npm run locales"
}
} Step 5 Run |
Hello guys, I am also trying to use react-intl with a create-react-app (with TypeScript), and I tried what your mention @sunknudsen, but it doesn't extract my messages. Shouldn't it? For now I try it on only one component which uses Could you provide more information please? |
@glecetre I personally use the <FormattedMessage
id="about.description"
defaultMessage="Lickstats is..."
/> |
@glecetre Can you please share a screenshot of the folders and files in your project? Anything under |
This worked for me: |
I was having lots of problems with this so wrote a post here for using react-intl, babel-plugin-react-intl and create-react-app, without ejecting. |
@jamieallen59 Thanks for writing that post! It finally got me working. |
close due to stale |
I'm pretty sure the answer to my question is "no", but I want to ask it anyway, just to be sure.
So my understanding is that I were to go the
.babelrc
route that when I build a project, I'd wind up with a translations JSON file somewhere in my build folder, which I could then hand off to a translation service. But after some digging around, it would appear that the only way to get this plugin to work with acreate-react-app
-based app is to eject the app, which I don't want to do.So given that issue, I think the only currently solution is to write a script that I can invoke directly in NodeJS at the command line. I did that, and the code seems to do the right thing (I can share that code, if people want it).
Obviously, it would be cleaner if this could just be part of the translation process, so I was hoping that I was missing something, and that it could be done with a CRA-based app.
Thanks in advance!
The text was updated successfully, but these errors were encountered: