All Projects → evenchange4 → react-intl.macro

evenchange4 / react-intl.macro

Licence: MIT license
Extract react-intl messages with babel-plugin-macros.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-intl.macro

react-hot-reload.macro
Zero configuration 🔥Hot Module Replacement🔥 using Babel macro
Stars: ✭ 31 (-20.51%)
Mutual labels:  create-react-app, babel-plugin-macros
cra-macro-example
This is an example of how you can use Create React App with Babel Plugin Macros.
Stars: ✭ 38 (-2.56%)
Mutual labels:  create-react-app, babel-plugin-macros
egghead-bookshelf
An example React application to accompany the "Add Internationalization (i18n) to a React app using React Intl" Egghead.io course
Stars: ✭ 28 (-28.21%)
Mutual labels:  create-react-app, react-intl
react-intl-po-example
👉 This is a standalone project for using react-intl-po with CRA.
Stars: ✭ 38 (-2.56%)
Mutual labels:  create-react-app, react-intl
react-intl-cra
🔧 Extract messages of Creact React App from the command line.
Stars: ✭ 68 (+74.36%)
Mutual labels:  create-react-app, react-intl
netlify-forms-formik
📝 Netlify Forms with Formik and ReCaptcha
Stars: ✭ 33 (-15.38%)
Mutual labels:  create-react-app
forex-web-app
💱 foreign currency exchange app built with react hooks
Stars: ✭ 17 (-56.41%)
Mutual labels:  create-react-app
arnold
🎬 A modern Kodi web interface
Stars: ✭ 16 (-58.97%)
Mutual labels:  create-react-app
hotlist
今日热榜(前端)
Stars: ✭ 51 (+30.77%)
Mutual labels:  create-react-app
Itunes-Top-100-albums
Fetching data from itunes api With lazy Loading using react
Stars: ✭ 14 (-64.1%)
Mutual labels:  create-react-app
movies
🍿 react-app for movies
Stars: ✭ 60 (+53.85%)
Mutual labels:  create-react-app
inside-client
Human Resources Department Tool. https://ifactory-solutions.github.io/inside-client/
Stars: ✭ 42 (+7.69%)
Mutual labels:  create-react-app
react-intl-demo
使用 react-intl 实现 React 国际化多语言
Stars: ✭ 30 (-23.08%)
Mutual labels:  react-intl
adonisjs-create-react-app
Adonisjs + Create React App Boilerplate
Stars: ✭ 22 (-43.59%)
Mutual labels:  create-react-app
craco-cesium
Let's use 🌍Cesium with create-react-app today!
Stars: ✭ 58 (+48.72%)
Mutual labels:  create-react-app
create-react-app-express
⚙️ Express server for your Create React App (Backbone of cra-universal)
Stars: ✭ 20 (-48.72%)
Mutual labels:  create-react-app
alda
A boilerplate for React isomorphic aplication with Material Design
Stars: ✭ 16 (-58.97%)
Mutual labels:  react-intl
ml-resources-react
A simple react app displaying resources to learn Machine learning.
Stars: ✭ 15 (-61.54%)
Mutual labels:  create-react-app
wx-react-app
使用Create-React-App 和 Ant Design Pro 框架整合,演示地址:
Stars: ✭ 16 (-58.97%)
Mutual labels:  create-react-app
meal-planner
A web application to plan what you eat daily in accordance to dietary needs
Stars: ✭ 53 (+35.9%)
Mutual labels:  create-react-app

react-intl.macro

Extract react-intl messages with babel-plugin-macros.

Travis Codecov Status npm package npm downloads

prettier license

Installation

$ yarn add react-intl.macro

Note: You'll need to install and configure babel-plugin-macros if you haven't already.

React-intl@2 should be installed in your project.

Example

evenchange4/react-intl.macro-example (with [email protected]) [DEMO]

Usage

Code

// Component.js
-import { defineMessages } from 'react-intl';
+import { defineMessages } from 'react-intl.macro';

const messages = defineMessages({
  'Component.greet': {
    id: 'Component.greet',
    defaultMessage: 'Hello, {name}!',
    description: 'Greeting to welcome the user to the app',
  },
});
// Component.js
import * as React from 'react';
-import { injectIntl, defineMessages, FormattedMessage, FormattedHTMLMessage } from 'react-intl';
+import { injectIntl } from 'react-intl';
+import { defineMessages, FormattedMessage, FormattedHTMLMessage } from 'react-intl.macro';

const messages = defineMessages({
  'Component.greet': {
    id: 'defineMessages.greet',
    defaultMessage: 'Hello, {name}!',
    description: 'Greeting to welcome the user to the app',
  },
});

class Foo extends React.Component {
  render() {
    return (
      <React.Fragment>
        <FormattedMessage
          id="Foo.hello1"
          defaultMessage='Hello, {name}!'
          description='Greeting to welcome the user to the app'
        />
        <FormattedMessage
          id="Foo.hello2"
          defaultMessage='Hello, {name}!'
          description='Greeting to welcome the user to the app'
        />
      </React.Fragment>
    );
  }
}

const Component = () => (
  <FormattedHTMLMessage
    id="FormattedHTMLMessage.hello"
    defaultMessage='<div>Hello, {name}!</div>'
    description='Greeting to welcome the user to the app'
  />
)

Extract CLI

Create React App

// package.json
"scripts": {
  "start": "react-scripts start",
  "build": "react-scripts build",
+ "extract": "MESSAGE_DIR='./.messages' react-scripts build"
},

Next.js

"scripts": {
  "dev": "next",
  "build": "next build",
+ "extract": "MESSAGE_DIR='./.messages' next build"
},

API

  • MESSAGE_DIR: string: The directory of output json files.

Config

Use cosmiconfig to set the babel-plugin-macros configuration: https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/user.md#config-experimental

verbose: To disable the log messages

default: true

// babel-plugin-macros.config.js
module.exports = {
  'react-intl': {
    verbose: false,
  },
};

Alternative

Development

Requirements

  • node >= 12.7.0
  • yarn >= 1.17.3
$ yarn install --pure-lockfile

Test

$ yarn run format
$ yarn run eslint
$ yarn run flow
$ yarn run test:watch
$ yarn run build

Publish

$ npm version patch
$ npm run changelog
git commit & push

CONTRIBUTING

  • ⇄ Pull requests and ★ Stars are always welcome.
  • For bugs and feature requests, please create an issue.
  • Pull requests must be accompanied by passing automated tests.

CHANGELOG

LICENSE

MIT: http://michaelhsu.mit-license.org

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].