{"id":13578266,"url":"https://github.com/formatjs/babel-plugin-react-intl","last_synced_at":"2025-04-05T16:32:04.050Z","repository":{"id":36807050,"uuid":"41113899","full_name":"formatjs/babel-plugin-react-intl","owner":"formatjs","description":"Extracts string messages from React components that use React Intl.","archived":true,"fork":false,"pushed_at":"2019-06-08T03:50:49.000Z","size":327,"stargazers_count":421,"open_issues_count":0,"forks_count":121,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-27T20:10:27.358Z","etag":null,"topics":["babel-plugin","i18n","internationalization","react-intl"],"latest_commit_sha":null,"homepage":"http://formatjs.io/react/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/formatjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-20T19:03:35.000Z","updated_at":"2025-02-06T01:13:13.000Z","dependencies_parsed_at":"2022-08-20T16:10:24.615Z","dependency_job_id":null,"html_url":"https://github.com/formatjs/babel-plugin-react-intl","commit_stats":null,"previous_names":["yahoo/babel-plugin-react-intl"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formatjs%2Fbabel-plugin-react-intl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formatjs%2Fbabel-plugin-react-intl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formatjs%2Fbabel-plugin-react-intl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formatjs%2Fbabel-plugin-react-intl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/formatjs","download_url":"https://codeload.github.com/formatjs/babel-plugin-react-intl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247181165,"owners_count":20897363,"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":["babel-plugin","i18n","internationalization","react-intl"],"created_at":"2024-08-01T15:01:28.922Z","updated_at":"2025-04-05T16:32:03.550Z","avatar_url":"https://github.com/formatjs.png","language":"JavaScript","readme":"# This repo was migrated to the [monorepo](https://github.com/formatjs/formatjs/tree/master/packages/babel-plugin-react-intl)\n\n# babel-plugin-react-intl\n\n![travis](https://travis-ci.org/formatjs/babel-plugin-react-intl.svg?branch=master)\n\nExtracts string messages for translation from modules that use [React Intl][].\n## Dependencies\n\n### React Intl\nThis Babel plugin works with React Intl v2.x\n\n### Babel\n- **3.x** of this plugin works with Babel 7\n- **2.x** works with Babel 6\n- **1.x** works with Babel 5\n\n## Installation\n\n```sh\n$ npm install babel-plugin-react-intl\n```\n\n## Usage\n\n**This Babel plugin only visits ES6 modules which `import` React Intl.**\n\nThe default message descriptors for the app's default language will be extracted from: `defineMessages()`, `\u003cFormattedMessage\u003e`, and `\u003cFormattedHTMLMessage\u003e`; all of which are named exports of the React Intl package.\n\nIf a message descriptor has a `description`, it'll be removed from the source after it's extracted to save bytes since it isn't used at runtime.\n\n### Via `.babelrc` (Recommended)\n\n**.babelrc**\n\n```json\n{\n  \"plugins\": [\n    [\"react-intl\", {\n        \"messagesDir\": \"./build/messages/\"\n    }]\n  ]\n}\n```\n\n#### Options\n\n- **`messagesDir`**: The target location where the plugin will output a `.json` file corresponding to each component from which React Intl messages were extracted. If not provided, the extracted message descriptors will only be accessible via Babel's API.\n\n- **`enforceDescriptions`**: Whether message declarations _must_ contain a `description` to provide context to translators. Defaults to: `false`.\n\n- **`extractSourceLocation`**: Whether the metadata about the location of the message in the source file should be extracted. If `true`, then `file`, `start`, and `end` fields will exist for each extracted message descriptors. Defaults to `false`.\n\n- **`moduleSourceName`**: The ES6 module source name of the React Intl package. Defaults to: `\"react-intl\"`, but can be changed to another name/path to React Intl.\n\n- **`overrideIdFn`**: A function with the signature `(id: string, defaultMessage: string, description: string|object) =\u003e string` which allows you to override the ID both in the extracted javascript and messages.\n\n- **`removeDefaultMessage`**: Remove `defaultMessage` field in generated js after extraction. \n\n- **`additionalComponentNames`**: Additional component names to extract messages from, e.g: `['FormattedFooBarMessage']`. **NOTE**: By default we check for the fact that `FormattedMessage` \u0026 `FormattedHTMLMessage` are imported from `moduleSourceName` to make sure variable alias works. This option does not do that so it's less safe.\n\n### Via Node API\n\nThe extract message descriptors are available via the `metadata` property on the object returned from Babel's `transform()` API:\n\n```javascript\nrequire('@babel/core').transform('code', {\n  plugins: ['react-intl']\n}) // =\u003e { code, map, ast, metadata['react-intl'].messages };\n```\n\n\n[React Intl]: http://formatjs.io/react/\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformatjs%2Fbabel-plugin-react-intl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fformatjs%2Fbabel-plugin-react-intl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformatjs%2Fbabel-plugin-react-intl/lists"}