{"id":28565733,"url":"https://github.com/postlight/generate-i18n-types","last_synced_at":"2025-06-10T14:40:14.909Z","repository":{"id":57137742,"uuid":"220071756","full_name":"postlight/generate-i18n-types","owner":"postlight","description":null,"archived":false,"fork":false,"pushed_at":"2019-11-14T17:26:06.000Z","size":339,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-17T21:38:15.738Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/postlight.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE-APACHE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-06T19:16:46.000Z","updated_at":"2024-01-03T03:01:47.000Z","dependencies_parsed_at":"2022-08-22T20:50:17.740Z","dependency_job_id":null,"html_url":"https://github.com/postlight/generate-i18n-types","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postlight%2Fgenerate-i18n-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postlight%2Fgenerate-i18n-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postlight%2Fgenerate-i18n-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postlight%2Fgenerate-i18n-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/postlight","download_url":"https://codeload.github.com/postlight/generate-i18n-types/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postlight%2Fgenerate-i18n-types/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259093955,"owners_count":22804262,"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":[],"created_at":"2025-06-10T14:40:14.247Z","updated_at":"2025-06-10T14:40:14.875Z","avatar_url":"https://github.com/postlight.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# generate-i18n-types\n\n[Postlight](https://postlight.com)'s Generate i18n Types generates types for internationalization strings.\n\n## Installation\n\nInstall `generate-18n-types` in your devDependencies\n```shell\n$ yarn add @postlight/generate-18n-types --dev\n```\n\nThe package also requires installation of `i18next` and `js-yaml` as dependencies, along with `@types/i18next` and `@types/js-yaml` to avoid any Typescript errors\n\n```shell\n$ yarn add i18next js-yaml @types/i18next @types/js-yaml --save\n```\n\n## Usage\n\nThis generator requires 3 arguments to generate your i18n types\n```shell\n$ generate-i18n-types --translations=path/to/translation.yml --stringTypesPath=path/to/strings.ts --utilPath=path/to/i18n.ts\n```\n\n`--translations`\nThis is the path to the YAML file you want to generate types for. Currently this only supports input of a single file. For an example of the format of the YAML file, see [example.yaml](./example.yaml)\n\n`--stringTypesPath`\nThis is the path to the file where you want the generated string types to reside.\n\n`--utilPath`\nThis is the path to the file where you want the generated translation functions for the string types to reside.\n\nNote:\nYou may require additional formatting of the generated `utilPath` file. Using Prettier as an example, you can just add the following additional command to the above\n`\u0026\u0026 prettier --write ./path/to/i18n.ts`\n\nOnce the command succeeds, it will automatically generate the `enum` types for the strings in the translation file, along with matching function signatures if the strings have dynamic fields. Then you can use the new translations in your code. Enjoy!\n\n## Example\n\n`generate-i18n-types` takes a YAML file you want translated\n\n```yaml\ntranslation:\n  appName: 'My App'\n  supportEmail: 'hello@my-app.com'\n  authFirst:\n    text: 'Before we can create your account, please \u003c{{url}}|authenticate with My App\u003e.'\n  errors:\n    invalidUsers: 'The following people could not be invited: {{invalidUsers}}'\n```\n Then generates the enum types for the `stringTypesPath` file\n\n```typescript\n/* tslint:disable */\n/* eslint-disable */\n// This file was automatically generated and should not be edited.\n\nexport enum I18NStringsWithArgs {\n  AuthFirstText = 'authFirst.text',\n  ErrorsInvalidUsers = 'errors.invalidUsers',\n}\n\nexport enum I18NStrings {\n  AppName = 'appName',\n  SupportEmail = 'supportEmail',\n}\n```\nAnd the corresponding translate functions and required packages and imports/exports for the `utilPath` file\n\n```typescript\n/* tslint:disable */\n/* eslint-disable */\n// This file was automatically generated and should not be edited.\n\nimport i18n from 'i18next';\nimport yaml from 'js-yaml';\nimport fs from 'fs';\nimport { I18NStrings, I18NStringsWithArgs } from '../types/strings';\n\nexport { I18NStrings, I18NStringsWithArgs } from '../types/strings';\n\nlet boundT: typeof i18n.t;\n\nconst en = yaml.safeLoad(\n  fs.readFileSync('../../locales/en/translation.yml', 'utf8')\n);\n\n// ==== START OVERLOADED SIGNATURES\nfunction translate(\n  key: I18NStringsWithArgs.AuthFirstText,\n  { url }: { url: string }\n): string;\nfunction translate(\n  key: I18NStringsWithArgs.ErrorsInvalidUsers,\n  { invalidUsers }: { invalidUsers: string }\n): string;\nfunction translate(key: I18NStrings): string;\n// ==== END OVERLOADED SIGNATURES\n\nfunction translate(key: string, data?: { [key: string]: string }) {\n  if (boundT) {\n    return boundT(key, data);\n  }\n  i18n.init({\n    lng: 'en',\n    resources: { en },\n    interpolation: {\n      escapeValue: false,\n    },\n  });\n  const { t } = i18n;\n  boundT = t.bind(i18n);\n  return boundT(key, data);\n}\n\nexport default translate;\n```\n\n\n## License\n\nLicensed under either of the below, at your preference:\n\n- Apache License, Version 2.0\n  ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n- MIT license\n  ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n  \n## Contributing\n\nFor details on how to contribute, see [CONTRIBUTING.md](./CONTRIBUTING.md)\n\nUnless it is explicitly stated otherwise, any contribution intentionally\nsubmitted for inclusion in the work, as defined in the Apache-2.0 license,\nshall be dual licensed as above without any additional terms or conditions.\n\n---\n\n🔬 A Labs project from your friends at [Postlight](https://postlight.com). Happy coding!\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostlight%2Fgenerate-i18n-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpostlight%2Fgenerate-i18n-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostlight%2Fgenerate-i18n-types/lists"}