{"id":13727375,"url":"https://github.com/akameco/extract-react-intl-messages","last_synced_at":"2025-05-16T14:07:24.474Z","repository":{"id":20198177,"uuid":"89123647","full_name":"akameco/extract-react-intl-messages","owner":"akameco","description":"extract react intl messages","archived":false,"fork":false,"pushed_at":"2023-01-06T02:47:20.000Z","size":2023,"stargazers_count":182,"open_issues_count":44,"forks_count":42,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-12T12:45:55.856Z","etag":null,"topics":["extract","i18n","messages","react","react-intl","react-intl-auto"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akameco.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-23T07:03:41.000Z","updated_at":"2025-04-08T18:46:56.000Z","dependencies_parsed_at":"2023-01-14T07:45:17.208Z","dependency_job_id":null,"html_url":"https://github.com/akameco/extract-react-intl-messages","commit_stats":null,"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akameco%2Fextract-react-intl-messages","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akameco%2Fextract-react-intl-messages/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akameco%2Fextract-react-intl-messages/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akameco%2Fextract-react-intl-messages/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akameco","download_url":"https://codeload.github.com/akameco/extract-react-intl-messages/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254544146,"owners_count":22088807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["extract","i18n","messages","react","react-intl","react-intl-auto"],"created_at":"2024-08-03T01:03:52.579Z","updated_at":"2025-05-16T14:07:24.448Z","avatar_url":"https://github.com/akameco.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# extract-react-intl-messages\n\n[![test](https://github.com/akameco/extract-react-intl-messages/workflows/test/badge.svg)](https://github.com/akameco/extract-react-intl-messages/actions?query=workflow%3Atest)\n[![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)\n[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![MIT License](https://img.shields.io/npm/l/nps.svg?style=flat-square)](./license)\n[![All Contributors](https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square)](#contributors-)\n\nThis 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`](https://github.com/yahoo/react-intl/wiki/API#definemessages) function of [react-intl](https://github.com/yahoo/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`](https://github.com/yahoo/react-intl/wiki/API#message-descriptor).\n\n## Dependencies\n\n### Babel\n\n- 0.x works with Babel 6\n\n## Install\n\n```\n$ npm install --save-dev extract-react-intl-messages\n```\n\n## Usage\n\napp/components/App/messages.js\n\n```js\nimport { defineMessages, useIntl } from 'react-intl'\n\nexport default defineMessages({\n  hello: {\n    id: 'a.hello',\n    defaultMessage: 'hello'\n  },\n  world: {\n    id: 'a.world',\n    defaultMessage: 'world'\n  }\n})\n\nexport const SubmitButton = () =\u003e {\n  const intl = useIntl()\n  const label = intl.formatMessage({\n    id: 'a.submit',\n    defaultMessage: 'Submit Button'\n  })\n  return \u003cbutton aria-label={label}\u003e{label}\u003c/button\u003e\n}\n```\n\n### Run Script\n\n```\n$ extract-messages -l=en,ja -o app/translations -d en --flat false './app/**/!(*.test).js'\n```\n\n### Output\n\napp/translations/en.json\n\n```json\n{\n  \"a\": {\n    \"hello\": \"hello\",\n    \"world\": \"world\",\n    \"submit\": \"Submit Button\"\n  }\n}\n```\n\napp/translations/ja.json\n\n```json\n{\n  \"a\": {\n    \"hello\": \"\",\n    \"world\": \"\",\n    \"submit\": \"\"\n  }\n}\n```\n\n## Recommend\n\nUse with [babel-plugin-react-intl-auto: i18n for the component age. Auto management react-intl ID.](https://github.com/akameco/babel-plugin-react-intl-auto)\n\n## CLI\n\n```console\n$ extract-messages --help\n\n  Extract react-intl messages\n\n  Usage\n  $ extract-react-intl-messages \u003cinput\u003e\n  $ extract-messages \u003cinput\u003e\n\n  Options\n  -o, --output            Output directory [require: true]\n  -l, --locales           locales [require: true]\n  -f, --format            json | yaml [default: json]\n  -d, --defaultLocale     default locale\n  --overwriteDefault      default: false\n  --flat                  json [default: true] | yaml [default: false]\n\n  Example\n  $ extract-messages --locales=ja,en --output app/translations 'app/**/*.js'\n  $ extract-messages -l=ja,en -o i18n 'src/**/*.js'\n  $ extract-messages -l=ja,en -o app/translations -f yaml 'app/**/messages.js'\n```\n\n### create-react-app user\n\ncreate `.babelrc` like this.\n\n```json\n{\n  \"presets\": [\"react-app\"]\n}\n```\n\nRun with `NODE_ENV=development`.\n\n```\n$ NODE_ENV=development extract-messages ...\n```\n\n### TypeScript\n\nbabel required.\n\nSee [example/with-typescript](example/with-typescript)\n\n```\nnpm install --save-dev @babel/core @babel/preset-typescript @babel/preset-react\n```\n\n`babel.config.js`\n\n```js\nmodule.exports = function (api) {\n  api.cache(true)\n\n  return {\n    presets: ['@babel/preset-react', '@babel/preset-typescript']\n  }\n}\n```\n\n## API\n\n### extractReactIntlMessages(locales, input, buildDir, [options])\n\n#### locales\n\nType: `Array\u003cstring\u003e`\n\nExample: `['en', 'ja']`\n\n#### input\n\nType: `Array\u003cstring\u003e`\n\nTarget files.\nglob.\n\n#### buildDir\n\nType: `string`\n\nExport directory.\n\n#### options\n\n##### defaultLocale\n\nType: `string`\u003cbr\u003e\nDefault: `en`\n\n##### format\n\nType: `json` | `yaml`\u003cbr\u003e\nDefault: `json`\n\nSet extension to output.\n\n##### overwriteDefault\n\nType: `boolean`\u003cbr\u003e\nDefault: true\n\nIf overwriteDefault is `false`, it will not overwrite messages in the default locale.\n\n##### flat\n\nType: `boolean`\u003cbr\u003e\nDefault: `true`\n\nIf format is `yaml`, set to `false`.\n\nBe careful if `false`.\nSee [this issue](https://github.com/akameco/extract-react-intl-messages/issues/3).\n\n##### babel-plugin-react-intl's Options\n\nSee https://github.com/formatjs/formatjs/tree/master/packages/babel-plugin-react-intl#options\n\n## Contributors\n\nThanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://akameco.github.io\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/4002137?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eakameco\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=akameco\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=akameco\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=akameco\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"#infra-akameco\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://hoantran.info\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/13161875?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eHoan Tran\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=hoantran-it\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=hoantran-it\" title=\"Tests\"\u003e⚠️\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/giantpinkwalrus\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/3383240?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003egiantpinkwalrus\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=giantpinkwalrus\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/enrique-ramirez\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/1190640?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eenrique-ramirez\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=enrique-ramirez\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://stefan-gojan.de\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/163128?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eStefan Gojan\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/akameco/extract-react-intl-messages/issues?q=author%3Ahoschi\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=hoschi\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=hoschi\" title=\"Tests\"\u003e⚠️\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://lithe.net\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/857744?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eSolomon English\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=solomon23\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/Filson14\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/4540538?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eFilip \"Filson\" Pasternak\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=Filson14\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://about.me/nodaguti\"\u003e\u003cimg src=\"https://avatars0.githubusercontent.com/u/27622?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003enodaguti\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=nodaguti\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=nodaguti\" title=\"Tests\"\u003e⚠️\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/fix-fix\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/11943024?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003efix-fix\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=fix-fix\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://bradbarrow.com\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/1264276?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ebradbarrow\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/akameco/extract-react-intl-messages/issues?q=author%3Abradbarrow\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=bradbarrow\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=bradbarrow\" title=\"Tests\"\u003e⚠️\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://ddem.us/\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/290457?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eGregor MacLennan\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=gmaclennan\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/zarv1k\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/6296643?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDmitry Zarva\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=zarv1k\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/panpanc\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/29132669?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eMichael Pan\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#example-panpanc\" title=\"Examples\"\u003e💡\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/testower\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/231492?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eTom Erik Støwer\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=testower\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://nextbook.io\"\u003e\u003cimg src=\"https://avatars0.githubusercontent.com/u/20876627?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eBart Lens\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/akameco/extract-react-intl-messages/commits?author=lensbart\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/revskill10\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/1390196?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eTruong Hoang Dung\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#example-revskill10\" title=\"Examples\"\u003e💡\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-enable --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!\n\n## License\n\nMIT © [akameco](http://akameco.github.io)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakameco%2Fextract-react-intl-messages","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakameco%2Fextract-react-intl-messages","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakameco%2Fextract-react-intl-messages/lists"}