{"id":20768626,"url":"https://github.com/bang88/typescript-react-intl","last_synced_at":"2025-05-11T09:32:06.168Z","repository":{"id":57383916,"uuid":"75289627","full_name":"BANG88/typescript-react-intl","owner":"BANG88","description":"Extracts string messages from TypeScript React components or ts files that use React Intl.","archived":false,"fork":false,"pushed_at":"2019-12-16T09:49:24.000Z","size":160,"stargazers_count":53,"open_issues_count":3,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-30T12:15:15.655Z","etag":null,"topics":["typescript-react-components"],"latest_commit_sha":null,"homepage":null,"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/BANG88.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":"2016-12-01T12:16:52.000Z","updated_at":"2024-06-13T01:15:28.000Z","dependencies_parsed_at":"2022-09-14T00:52:42.072Z","dependency_job_id":null,"html_url":"https://github.com/BANG88/typescript-react-intl","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BANG88%2Ftypescript-react-intl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BANG88%2Ftypescript-react-intl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BANG88%2Ftypescript-react-intl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BANG88%2Ftypescript-react-intl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BANG88","download_url":"https://codeload.github.com/BANG88/typescript-react-intl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253545013,"owners_count":21925320,"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":["typescript-react-components"],"created_at":"2024-11-17T11:40:08.530Z","updated_at":"2025-05-11T09:32:05.880Z","avatar_url":"https://github.com/BANG88.png","language":"TypeScript","readme":"# typescript-react-intl\n\nExtracts string messages from TypeScript React components or ts files that use React Intl. You can use it in `React Native` too. \n\n[![Build Status](https://travis-ci.org/bang88/typescript-react-intl.svg?branch=master)](https://travis-ci.org/bang88/typescript-react-intl)\n\n## Usage\n\n\u003e If you have many files to processes,you can get contents use node-glob with fs module\n\u003e Custom component support since version `0.3.0`. checkout tests/index.js\n\n```sh\nnpm i typescript-react-intl -D\n```\n\n```js\nvar parse = require(\"typescript-react-intl\").default;\n\n// results is an array\n// contents is your tsx file\nvar results = parse(contents);\n\n// or if you want support custom components\nvar results = parse(contents, {\n  tagNames: [\"MyComponent\", \"StyledText\"],\n});\n```\n\n### React-intl\n\nOnly support `\u003cFormattedMessage/\u003e` and `defineMessages` We don't use `\u003cFormattedHtmlMessage/\u003e`\n\n### Examples\n\n```js\nvar fs = require(\"fs\");\nvar glob = require(\"glob\");\nvar parser = require(\"typescript-react-intl\").default;\n\nfunction runner(pattern, cb) {\n  var results = [];\n  pattern = pattern || \"src/**/*.@(tsx|ts)\";\n  glob(pattern, function(err, files) {\n    if (err) {\n      throw new Error(err);\n    }\n    files.forEach((f) =\u003e {\n      var contents = fs.readFileSync(f).toString();\n      var res = parser(contents);\n      results = results.concat(res);\n    });\n\n    cb \u0026\u0026 cb(results);\n  });\n}\n\n// demo\nrunner(null, function(res) {\n  var locale = {};\n\n  res.forEach((r) =\u003e {\n    locale[r.id] = r.defaultMessage;\n  });\n\n  var locales = {\n    en: locale,\n  };\n\n  // save file to disk。you can save as a json file,just change the ext and contents as you want.\n  fs.writeFileSync(\n    `src/translations/all.ts`,\n    `export default ${JSON.stringify(locales, null, 2)}\\r`,\n  );\n});\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbang88%2Ftypescript-react-intl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbang88%2Ftypescript-react-intl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbang88%2Ftypescript-react-intl/lists"}