{"id":18024195,"url":"https://github.com/robisim74/gpt-translate-json","last_synced_at":"2025-03-27T00:30:53.039Z","repository":{"id":181841907,"uuid":"651607254","full_name":"robisim74/gpt-translate-json","owner":"robisim74","description":"Command to automatically translate your app JSON files using OpenAI GPT Chat Completions API","archived":false,"fork":false,"pushed_at":"2024-11-19T21:15:11.000Z","size":977,"stargazers_count":9,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-22T18:11:24.257Z","etag":null,"topics":["gpt","i18n","json","translate"],"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/robisim74.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-06-09T16:09:02.000Z","updated_at":"2025-02-27T10:05:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"572f694e-7795-4d00-97bf-cbd7bbd8a3af","html_url":"https://github.com/robisim74/gpt-translate-json","commit_stats":null,"previous_names":["robisim74/gpt-translate-json"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robisim74%2Fgpt-translate-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robisim74%2Fgpt-translate-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robisim74%2Fgpt-translate-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robisim74%2Fgpt-translate-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robisim74","download_url":"https://codeload.github.com/robisim74/gpt-translate-json/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245760584,"owners_count":20667886,"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":["gpt","i18n","json","translate"],"created_at":"2024-10-30T07:12:09.100Z","updated_at":"2025-03-27T00:30:52.597Z","avatar_url":"https://github.com/robisim74.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GPT Translate JSON\n[![Node.js CI](https://github.com/robisim74/gpt-translate-json/actions/workflows/node.js.yml/badge.svg)](https://github.com/robisim74/gpt-translate-json/actions/workflows/node.js.yml)\n\n\u003e Command to automatically translate your app JSON files using OpenAI GPT Chat Completions API\n\n```shell\nnpm install gpt-translate-json --save-dev\n```\n\n## Requirements\n- Node.js \u003e= 16\n- OpenAI Api key\n\n## Usage\nAdd the command in `package.json`, and provide required parameters:\n```json\n\"scripts\": {\n  \"gpt-translate-json\": \"gpt-translate-json --apiKey=openai_api_key --model=gpt-3.5-turbo --maxTokens=3000 --langs=en-US,it-IT --originalLang=en-US\"\n}\n```\nAvailable options:\n- `apiKey` OpenAI API key. Required\n- `model` OpenAI Chat Completion model. Required\n- `maxTokens` OpenAI model max tokens per request. Required\n- `langs` All supported languages. Required\n- `originalLang` Original language. Required\n- `basePath` The base path. Default to `'./'`\n- `assetsPath` Path to translation files: `[basePath]/[assetsPath]/[lang]/*.json`. Default to `'i18n'`\n- `rules` Prompt rules. Defaults:\n    - `'do not translate proper names'`\n    - `'do not translate texts enclosed in double braces {{}}'`\n    - `'do not translate the html tags''`\n    - `'do not translate URLs'`\n\n\u003e Depending on the model used, requests can use up to `maxTokens` shared between prompt and completion. Keep the number of `maxTokens` lower than the maximum allowed by the model: in fact, the command splits the files into multiple requests to respect the maximum number of tokens in each request based on the English language, but depending on the target language, the number of tokens used can vary significantly\n\nHaving a file structure like this:\n```\ni18n/\n│   \n└───en-US/\n        app.json\n```\n\n_i18n/en-US/app.json_\n```json\n{\n  \"app\": {\n    \"title\": \"\u003ch1\u003eLibrary to translate JSON using GPT\u003c/h1\u003e\"\n  }\n}\n```\nthe command:\n```shell\nnpm run gpt-translate-json\n```\nwill generate:\n```\ni18n/\n│   \n└───en-US/\n│       app.json\n└───it-IT/\n│       app.json\n└───.metadata/\n        translated.json\n        translated-langs.json\n```\n\n_i18n/it-IT/app.json_\n```json\n{\n  \"app\": {\n    \"title\": \"\u003ch1\u003eLibreria per tradurre JSON usando GPT\u003c/h1\u003e\u003e\"\n  }\n}\n```\n\n### Add translations\nThe file `.metadata/translated.json` contains the paths of translated values, so if you add new translations:\n\n_i18n/en-US/app.json_\n```json\n{\n  \"app\": {\n    \"title\": \"\u003ch1\u003eLibrary to translate JSON using GPT\u003c/h1\u003e\"\n  },\n  \"about\": \"About us\"\n}\n```\nthe command will request only the new translations, reducing tokens usage, and the files will be updated:\n\n_i18n/it-IT/app.json_\n```json\n{\n  \"app\": {\n    \"title\": \"\u003ch1\u003eLibreria per tradurre JSON usando GPT\u003c/h1\u003e\u003e\"\n  },\n  \"about\": \"Chi siamo\"\n}\n```\n\n### Add languages\nThe file `.metadata/translated-langs.json` contains the langs already translated, so if you add a new lang:\n\n```json\n\"scripts\": {\n  \"gpt-translate-json\": \"gpt-translate-json --apiKey=openai_api_key --model=gpt-3.5-turbo --maxTokens=3000 --langs=en-US,it-IT,es-ES --originalLang=en-US\"\n}\n```\nwill generate:\n```\ni18n/\n│   \n└───en-US/\n│       app.json\n└───it-IT/\n│       app.json\n└───es-ES/\n│       app.json\n└───.metadata/\n        translated.json\n        translated-langs.json\n```\n\n_i18n/es-ES/app.json_\n```json\n{\n  \"app\": {\n    \"title\": \"\u003ch1\u003eBiblioteca para traducir JSON usando GPT\u003c/h1\u003e\"\n  },\n  \"about\": \"Sobre nosotros\"\n}\n```\n\n## Using it programmatically\nRather than using the command, you can invoke `gptTranslateJson` function:\n```javascript\nimport { gptTranslateJson } from 'gpt-translate-json';\n\nawait gptTranslateJson({\n  apiKey: 'openai_api_key',\n  model: 'gpt-3.5-turbo',\n  maxTokens: 3000,\n  langs: ['en-US', 'it-IT'],\n  originalLang: 'en-US',\n  rules: [\n    // your custom rules\n  ]\n});\n```\n\n## Development Builds\n### Build\n```shell\nnpm install\nnpm run build\n\nnpm test\n```\n\n## License\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobisim74%2Fgpt-translate-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobisim74%2Fgpt-translate-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobisim74%2Fgpt-translate-json/lists"}