{"id":15653402,"url":"https://github.com/anandchowdhary/auto-i18n","last_synced_at":"2025-08-20T03:31:52.787Z","repository":{"id":38272647,"uuid":"176261027","full_name":"AnandChowdhary/auto-i18n","owner":"AnandChowdhary","description":"🌐 Automatically translate your JSON I18N files","archived":false,"fork":false,"pushed_at":"2024-07-15T20:33:51.000Z","size":949,"stargazers_count":31,"open_issues_count":4,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-12T17:16:00.157Z","etag":null,"topics":["automation","google-translate","i18n","l18n","nodejs","translation","typescript"],"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/AnandChowdhary.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":"2019-03-18T10:41:08.000Z","updated_at":"2024-11-15T21:15:25.000Z","dependencies_parsed_at":"2024-10-23T07:30:25.792Z","dependency_job_id":null,"html_url":"https://github.com/AnandChowdhary/auto-i18n","commit_stats":{"total_commits":311,"total_committers":5,"mean_commits":62.2,"dds":"0.22186495176848875","last_synced_commit":"a96a7533687fc7149de06aeb82a684c9e477bbd2"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandChowdhary%2Fauto-i18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandChowdhary%2Fauto-i18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandChowdhary%2Fauto-i18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandChowdhary%2Fauto-i18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AnandChowdhary","download_url":"https://codeload.github.com/AnandChowdhary/auto-i18n/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230388131,"owners_count":18217755,"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":["automation","google-translate","i18n","l18n","nodejs","translation","typescript"],"created_at":"2024-10-03T12:45:34.794Z","updated_at":"2024-12-19T06:10:05.034Z","avatar_url":"https://github.com/AnandChowdhary.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🌐 Auto I18N\n\n[![Travis CI](https://img.shields.io/travis/AnandChowdhary/auto-i18n.svg)](https://travis-ci.org/AnandChowdhary/auto-i18n)\n[![Coverage Status](https://coveralls.io/repos/github/AnandChowdhary/auto-i18n/badge.svg?branch=master\u0026v=2)](https://coveralls.io/github/AnandChowdhary/auto-i18n?branch=master)\n[![GitHub](https://img.shields.io/github/license/anandchowdhary/auto-i18n.svg)](https://github.com/AnandChowdhary/auto-i18n/blob/master/LICENSE)\n![Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/github/AnandChowdhary/auto-i18n.svg)\n![NPM type definitions](https://img.shields.io/npm/types/auto-i18n.svg)\n[![NPM](https://img.shields.io/npm/v/auto-i18n.svg)](https://www.npmjs.com/package/auto-i18n)\n\n[![NPM](https://nodei.co/npm/auto-i18n.png)](https://www.npmjs.com/package/auto-i18n)\n\nAuto I18N is a package which automagically translate your JSON files, objects, or strings using Google Translate. It's automating your internationalization.\n\n## ⭐ Usage\n\nAdd the dependency from NPM:\n\n```bash\nnpm install auto-i18n\n```\n\nImport the modules you require from the package:\n\n```js\nimport * from \"auto-i18n\";\n```\n\nAnd then configure your Project ID and API key as environment variables (see [Configuration](#configuration)).\n\n### Translating words\n\nTo translate a single phrase:\n\n```js\nimport { translate } from \"auto-i18n\";\nconst hello = await translate(\"Hello!\", \"fr\"); // Bonjour!\n```\n\nFor every function, can also use promises:\n\n```js\ntranslate(\"Hello!\", \"nl\")\n  .then(translation =\u003e {\n      console.log(translation); // Hallo!\n  })\n  .catch(error =\u003e {\n      console.log(\"Got an error\", error);\n  });\n```\n\n### Translating objects\n\nTo translate an entire object:\n\n```js\nimport { translateObject } from \"auto-i18n\";\nconst translateMe = {\n    hello: \"Hello\",\n    world: [\"world\", \"earth\"]\n};\nconst translated = await translateObject(translateMe, \"es\");\nconsole.log(translated);\n/* { hello: \"Hola\",\n     world: [\"mundo\", \"tierra\"] } */\n```\n\n### Translating a single-translation file\n\nA single translation file is a JSON file which contains keys for language codes and terms under each key. You can write one for English like this, for example:\n\nFile `en.json`:\n\n```json\n{\n    \"en\": {\n        \"greeting\": \"Hello!\",\n        \"question\": \"How are you?\"\n    }\n}\n```\n\nTo translate it, use the `translateFileSingle` function:\n\n```js\nimport { translateFileSingle } from \"auto-i18n\";\nimport path from \"path\"; // Node.js path helper\nconst filePath = path.join(__dirname, \"en.json\");\nconst translated = await translateFileSingle(filePath, [\"fr\", \"nl\", \"es\"]);\nconsole.log(translated);\n```\n\nThis is what `translated` looks like:\n\n```json\n{\n    \"en\": {\n        \"greeting\": \"Hello!\",\n        \"question\": \"How are you?\"\n    },\n    \"fr\": {\n        \"greeting\": \"Bonjour!\",\n        \"question\": \"Comment vas-tu?\"\n    },\n    \"nl\": {\n        \"greeting\": \"Hallo!\",\n        \"question\": \"Hoe gaat het met je?\"\n    },\n    \"es\": {\n        \"greeting\": \"Hola!\",\n        \"question\": \"¿Cómo estás?\"\n    }\n}\n```\n\nYou can also write the file directly by supplying the third parameter as `true`:\n\n```js\nawait translateFileSingle(filePath, [\"fr\", \"nl\", \"es\"], true);\n```\n\n### Translation a regular JSON file\n\nIf you have a JSON file which is not a single-translation-file, you can also translate it:\n\n```js\nawait translateFile(\n    \"en.json\", /* File path */\n    \"nl\", /* Language code (single) */\n    false /* Overwrite the file with translation? */\n);\n```\n\n### Generated translated files\n\nIf you have a JSON file (e.g., `en.json`), you can also generate corresponding language files:\n\n```js\nawait generate(\n    \"en.json\", /* File path */\n    [\"nl\", \"fr\", \"es\"], /* Languages */\n);\n```\n\n## 💡 Notes\n\n### Caching\n\nAuto I18N uses local caching powered by [Fraud](https://github.com/AnandChowdhary/fraud) to decrease API usage and therefore billing. A caching directory, `.cache/auto-i18n` is used, which should be added to your `.gitignore`. You can overwrite this directory as a parameter in each function.\n\n### Configuration\n\nAuto I18N uses the Google Cloud Translation API, for which an API key and Project ID are required. These should be available as environment variables in your `.env` file. For example:\n\n```dotenv\nPROJECT_ID = \"google-cloud-project-id\"\nAPI_KEY = \"google-cloud-api-key\"\n```\n\nThe library will automatically read them from the `.env` file, as long as it's in your project root directory.\n\n## 🛠️ Development\n\nInstall dependencies:\n\n```bash\nyarn\n```\n\nCompile Typescript to ES6 before publishing to NPM:\n\n```bash\nyarn build\n```\n\n## 📝 License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanandchowdhary%2Fauto-i18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanandchowdhary%2Fauto-i18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanandchowdhary%2Fauto-i18n/lists"}