简体   繁体   中英

What are advantages of using babel-plugin-react-intl?

I've been trying to learn and understand react-intl library and I encountered babel-plugin-react-intl library. There is a description in the library's page like that;

Extracts string messages for translation from modules that use React Intl.

I wonder that which string messages would be extracted?

Also, what are the benefits of extracted messages?

From: https://blog.johnphoto.se/2016/03/21/react-intl-v2/ (couldn't comment without more rep)

Once it is time to get all these messages translated, you only have to do a webpack build with the babel-plugin react-intl plugin. This will extract all the defined messages from the code base into JSON files. These files are then sent to your translators and they translate all of these messages and the translations is put into a flat JSON hash and this is then loaded into your code and you have a i18n enabled app. So enough with theory!

I am using babel-plugin-react-intl to automatically extract all the labels in my React application. I'd point as main advantages the following two:

  1. Using the plugin, all the labels from my application are automatically extracted to json files. Instead of having to manually update the json files that will be translated. This way, I don't need to worry about this file, as the plugin will push the labels to it.
  2. If I accidentally create a duplicated ID for a label, the plugin tells me that by throwing an error on webpack.

Extra: I am not using, but, if you want to force developers to add a context description for each label, this plugin also has an option to force this behavior so that, if the developer forgets it, an error is thrown on webpack.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM