All Projects → akameco → Extract React Intl Messages

akameco / Extract React Intl Messages

Licence: mit
extract react intl messages

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Extract React Intl Messages

extract-react-intl
Extract react-intl messages
Stars: ✭ 18 (-89.66%)
Mutual labels:  i18n, extract, messages
Es2015 I18n Tag
ES2015 template literal tag for i18n and l10n (translation and internationalization)
Stars: ✭ 171 (-1.72%)
Mutual labels:  i18n
Libarchivejs
Archive library for browsers
Stars: ✭ 145 (-16.67%)
Mutual labels:  extract
Me Tools
Tools for working with Intel ME
Stars: ✭ 165 (-5.17%)
Mutual labels:  extract
Discordcrypt
End-To-End File & Message Encryption For Discord
Stars: ✭ 150 (-13.79%)
Mutual labels:  messages
Pythonvscode
This extension is now maintained in the Microsoft fork.
Stars: ✭ 2,013 (+1056.9%)
Mutual labels:  extract
Hugo Theme Fuji
A minimal Hugo theme with nice theme color. | 一个主题色极简 Hugo 主题。
Stars: ✭ 145 (-16.67%)
Mutual labels:  i18n
Ngettext
A cross-platform .NET implementation of the GNU/Gettext library.
Stars: ✭ 172 (-1.15%)
Mutual labels:  i18n
Formatjs
The monorepo home to all of the FormatJS related libraries, most notably react-intl.
Stars: ✭ 12,869 (+7295.98%)
Mutual labels:  i18n
Open Semantic Etl
Python based Open Source ETL tools for file crawling, document processing (text extraction, OCR), content analysis (Entity Extraction & Named Entity Recognition) & data enrichment (annotation) pipelines & ingestor to Solr or Elastic search index & linked data graph database
Stars: ✭ 165 (-5.17%)
Mutual labels:  extract
Sypht Python Client
A python client for the Sypht API
Stars: ✭ 160 (-8.05%)
Mutual labels:  extract
Deeply
PHP client for the DeepL.com translation API (unofficial)
Stars: ✭ 152 (-12.64%)
Mutual labels:  i18n
V Selectmenu
SelectMenu for Vuejs, A simple, easier and highly customized menu solution
Stars: ✭ 169 (-2.87%)
Mutual labels:  i18n
Laraflash
⚡ Flash messages on steroids.
Stars: ✭ 150 (-13.79%)
Mutual labels:  messages
Vue Cli Plugin I18n
🌐 Vue CLI plugin to add vue-i18n to your Vue Project
Stars: ✭ 172 (-1.15%)
Mutual labels:  i18n
Xioc
Extract indicators of compromise from text, including "escaped" ones.
Stars: ✭ 148 (-14.94%)
Mutual labels:  extract
Strsync
A CLI tool for localization resource management on Xcode. Built with Google Translator.
Stars: ✭ 157 (-9.77%)
Mutual labels:  i18n
I18n Static
Universal i18n solution for static resources
Stars: ✭ 166 (-4.6%)
Mutual labels:  i18n
Earth Reverse Engineering
Reversing Google's 3D satellite mode
Stars: ✭ 2,083 (+1097.13%)
Mutual labels:  extract
Vue I18next
Internationalization for vue using the i18next i18n ecosystem.
Stars: ✭ 172 (-1.15%)
Mutual labels:  i18n

extract-react-intl-messages

test tested with jest styled with prettier MIT License All Contributors

This package will generate json or yaml files from a glob. It will generate one file per locale, with the ids of each message defined by the defineMessages function of react-intl. The value of each of these keys will be an empty string, except for your defaultLocale which will be populated with the defaultMessage.

Dependencies

Babel

  • 0.x works with Babel 6

Install

$ npm install --save-dev extract-react-intl-messages

Usage

app/components/App/messages.js

import { defineMessages, useIntl } from 'react-intl'

export default defineMessages({
  hello: {
    id: 'a.hello',
    defaultMessage: 'hello'
  },
  world: {
    id: 'a.world',
    defaultMessage: 'world'
  }
})

export const SubmitButton = () => {
  const intl = useIntl()
  const label = intl.formatMessage({
    id: 'a.submit',
    defaultMessage: 'Submit Button'
  })
  return <button aria-label={label}>{label}</button>
}

Run Script

$ extract-messages -l=en,ja -o app/translations -d en --flat false './app/**/!(*.test).js'

Output

app/translations/en.json

{
  "a": {
    "hello": "hello",
    "world": "world",
    "submit": "Submit Button"
  }
}

app/translations/ja.json

{
  "a": {
    "hello": "",
    "world": "",
    "submit": ""
  }
}

Recommend

Use with babel-plugin-react-intl-auto: i18n for the component age. Auto management react-intl ID.

CLI

$ extract-messages --help

  Extract react-intl messages

  Usage
  $ extract-react-intl-messages <input>
  $ extract-messages <input>

  Options
  -o, --output            Output directory [require: true]
  -l, --locales           locales [require: true]
  -f, --format            json | yaml [default: json]
  -d, --defaultLocale     default locale
  --overwriteDefault      default: false
  --flat                  json [default: true] | yaml [default: false]

  Example
  $ extract-messages --locales=ja,en --output app/translations 'app/**/*.js'
  $ extract-messages -l=ja,en -o i18n 'src/**/*.js'
  $ extract-messages -l=ja,en -o app/translations -f yaml 'app/**/messages.js'

create-react-app user

create .babelrc like this.

{
  "presets": ["react-app"]
}

Run with NODE_ENV=development.

$ NODE_ENV=development extract-messages ...

TypeScript

babel required.

See example/with-typescript

npm install --save-dev @babel/core @babel/preset-typescript @babel/preset-react

babel.config.js

module.exports = function (api) {
  api.cache(true)

  return {
    presets: ['@babel/preset-react', '@babel/preset-typescript']
  }
}

API

extractReactIntlMessages(locales, input, buildDir, [options])

locales

Type: Array<string>

Example: ['en', 'ja']

input

Type: Array<string>

Target files. glob.

buildDir

Type: string

Export directory.

options

defaultLocale

Type: string
Default: en

format

Type: json | yaml
Default: json

Set extension to output.

overwriteDefault

Type: boolean
Default: true

If overwriteDefault is false, it will not overwrite messages in the default locale.

flat

Type: boolean
Default: true

If format is yaml, set to false.

Be careful if false. See this issue.

babel-plugin-react-intl's Options

See https://github.com/formatjs/formatjs/tree/master/packages/babel-plugin-react-intl#options

Contributors

Thanks goes to these wonderful people (emoji key):


akameco

💻 ⚠️ 📖 🚇

Hoan Tran

💻 ⚠️

giantpinkwalrus

💻

enrique-ramirez

📖

Stefan Gojan

🐛 💻 ⚠️

Solomon English

💻

Filip "Filson" Pasternak

💻

nodaguti

💻 ⚠️

fix-fix

💻

bradbarrow

🐛 💻 ⚠️

Gregor MacLennan

💻

Dmitry Zarva

💻

Michael Pan

💡

Tom Erik Støwer

💻

Bart Lens

💻

Truong Hoang Dung

💡

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT © akameco

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].