{"id":31551346,"url":"https://github.com/betomorrow/i18n-typegen","last_synced_at":"2025-10-04T18:41:59.221Z","repository":{"id":212472665,"uuid":"730735112","full_name":"BeTomorrow/i18n-typegen","owner":"BeTomorrow","description":"Generate TS type for your translations keys and interpolate values","archived":false,"fork":false,"pushed_at":"2024-08-06T13:20:46.000Z","size":930,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-08T14:02:56.734Z","etag":null,"topics":[],"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/BeTomorrow.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-12T15:01:19.000Z","updated_at":"2024-08-06T13:20:50.000Z","dependencies_parsed_at":"2023-12-14T12:51:13.557Z","dependency_job_id":"400a58fd-e33b-4a73-b6db-0fdfa520af98","html_url":"https://github.com/BeTomorrow/i18n-typegen","commit_stats":null,"previous_names":["betomorrow/i18n-typegen"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/BeTomorrow/i18n-typegen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BeTomorrow%2Fi18n-typegen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BeTomorrow%2Fi18n-typegen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BeTomorrow%2Fi18n-typegen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BeTomorrow%2Fi18n-typegen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BeTomorrow","download_url":"https://codeload.github.com/BeTomorrow/i18n-typegen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BeTomorrow%2Fi18n-typegen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278358484,"owners_count":25973946,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-10-04T18:41:53.444Z","updated_at":"2025-10-04T18:41:59.179Z","avatar_url":"https://github.com/BeTomorrow.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# i18n-typegen\n\nGenerate TS type for your translations keys and interpolate values\n\n## Features\n\n- **🛠 TypeScript Definition Generator**: Generate .d.ts for your i18n function. Provide keys, pluralization and interpolation validation\n- **🧘 Not intrusive**: This is a type-only code generator. You are free to use any i18n solutions, including your own. The default works well with i18n-js.\n\n## Usage\n\n### Installation\n\n```bash\nnpm install --save-dev @betomorrow/i18n-typegen\n```\n\n### Configuration\n\n```bash\n# Generate default config file\nnpx i18n-typegen init\n# Generate your type for keys and interpolations\nnpx i18n-typegen codegen\n```\n\n## Example of What it Does\n\nGiven the following JSON input:\n\n```json\n{\n  \"greeting\": \"Hello {{firstName}} {{familyName}}!\",\n  \"duration.day.one\": \"1 day\",\n  \"duration.day.other\": \"{{count}} days\",\n  \"duration.day.zero\": \"0 day\"\n}\n```\n\nThis package generates the following types:\n\n```typescript\ntype Translations = {\n  greeting: { firstName: string; familyName: string };\n  \"duration.day\": { count: number };\n  goodbye: undefined;\n};\nexport { TranslationFunction, TranslationFunctionArgs, TranslationKeys };\n```\n\nUse these types to type your own i18n function:\n\n```typescript\nimport { TranslationFunction } from \"translations\";\n\nconst translate: TranslationFunction = () =\u003e {};\n\ntranslate(\"greeting\", { firstName: \"Harry\", familyName: \"Potter\" }); // OK\n\ntranslate(\"greeting\", { firstName: \"Henry\" }); // Error\n/**\n    Property 'familyName' is missing in type '{ firstName: string }' but required in type '{ firstName:  string; familyName: string; }'.ts(2345)\n    */\n\ntranslate(\"goodbye\"); // OK\n```\n\n## Configuration file\n\n```json\n{\n  \"input\": {\n    \"format\": \"nested\",\n    \"path\": \"./input/default.json\"\n  },\n  \"output\": {\n    \"path\": \"./output/default.d.ts\"\n  },\n  \"rules\": [\n    {\n      \"//\": \"Add pluralization placeholders\",\n      \"condition\": { \"keyEndsWith\": [\"zero\", \"one\", \"other\"] },\n      \"transformer\": {\n        \"addPlaceholder\": { \"name\": \"count\", \"type\": [\"number\"] },\n        \"removeLastPart\": true\n      }\n    },\n    {\n      \"//\": \"Add interpolation values for matched placeholders\",\n      \"condition\": { \"placeholderPattern\": { \"prefix\": \"{{\", \"suffix\": \"}}\" } },\n      \"transformer\": {\n        \"addMatchedPlaceholder\": { \"type\": [\"string\", \"number\"] }\n      }\n    }\n  ],\n  \"extra\": {\n    \"prettierIgnore\": true,\n    \"eslintDisablePrettier\": false\n  }\n}\n```\n\n- input `format` support JSON translations file with\n  - `flatten` keys like `home.header.greeting`\n  - nested scoped dictionnaries: `{ home: { header: { greeting: \"hello\" } } }`\n- extra de-opt generated files from prettier or eslint prettier rule to comply with specific configurations.\n  - `prettierIgnore` add `// prettier-ignore` in generated file.\n  - `eslintDisablePrettier` add `/* eslint-disable prettier/prettier */` in generated file.\n\n### Recommended Toolbox\n\n- Tool for downloading translations from GoogleSheet: [sync-wording](https://github.com/BeTomorrow/sync-wording)\n- Styling without trouble your translations on React and React-Native [styled-tagged-text](https://github.com/BeTomorrow/styled-tagged-text)\n- Works great with [i18n-js](https://github.com/fnando/i18n-js)\n\n### Example of implementation\n\nSee `docs` for complete usage of type generation with some i18n implementations\n\n- i18n-js [docs/i18n-js.md](docs/i18n-js.md)\n- custom implemetation [docs/custom.md](docs/custom.md)\n\n## Contribution\n\nContributions, bug reports, feature requests, or pull requests, are very appreciated. However, please note the following:\n\n- **Bug Reports and Feature Requests**: If you encounter a bug or have a feature request, please open an issue. Provide clear details about the problem or the requested feature.\n\n- **Pull Requests**: Feel free to submit pull requests for bug fixes or new features.\n\n- **Limited Support**:\n  This project is shared as-is with limited ongoing support. While contributions are welcome, bear in mind that the primary focus is on personal usage. If urgent, consider forking the project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbetomorrow%2Fi18n-typegen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbetomorrow%2Fi18n-typegen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbetomorrow%2Fi18n-typegen/lists"}