{"id":18926771,"url":"https://github.com/ladjs/mandarin","last_synced_at":"2025-04-15T13:33:18.126Z","repository":{"id":42368202,"uuid":"113726478","full_name":"ladjs/mandarin","owner":"ladjs","description":"Automatic i18n phrase translation using Google Translate","archived":false,"fork":false,"pushed_at":"2024-03-25T16:50:37.000Z","size":593,"stargazers_count":13,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T02:01:54.105Z","etag":null,"topics":["api","automatic","convert","google","i10n","i18n","javascript","keywords","localization","localize","mandarin","node","phrase","phrases","sentences","service","translate","translation"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/ladjs.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":"2017-12-10T05:43:29.000Z","updated_at":"2023-12-28T07:06:02.000Z","dependencies_parsed_at":"2024-06-21T04:10:41.410Z","dependency_job_id":null,"html_url":"https://github.com/ladjs/mandarin","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fmandarin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fmandarin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fmandarin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fmandarin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ladjs","download_url":"https://codeload.github.com/ladjs/mandarin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249080476,"owners_count":21209534,"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":["api","automatic","convert","google","i10n","i18n","javascript","keywords","localization","localize","mandarin","node","phrase","phrases","sentences","service","translate","translation"],"created_at":"2024-11-08T11:17:07.669Z","updated_at":"2025-04-15T13:33:17.853Z","avatar_url":"https://github.com/ladjs.png","language":"JavaScript","readme":"# mandarin\n\n[![build status](https://github.com/ladjs/mandarin/actions/workflows/ci.yml/badge.svg)](https://github.com/ladjs/mandarin/actions/workflows/ci.yml)\n[![code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)\n[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![made with lass](https://img.shields.io/badge/made_with-lass-95CC28.svg)](https://lass.js.org)\n[![license](https://img.shields.io/github/license/ladjs/mandarin.svg)](LICENSE)\n\n\u003e Automatic i18n markdown translation and i18n phrase translation using Google Translate\n\n\n## Table of Contents\n\n* [Install](#install)\n* [Requirements](#requirements)\n  * [Redis](#redis)\n  * [Google Application Credentials](#google-application-credentials)\n* [Usage](#usage)\n* [Contributors](#contributors)\n* [License](#license)\n\n\n## Install\n\n[npm][]:\n\n```sh\nnpm install mandarin\n```\n\n\n## Requirements\n\n### Redis\n\nYou will need to have [Redis][] installed in order for caching to work properly.\n\nIf you do not plan to use Redis, then set `redis: false` as an option.\n\n### Google Application Credentials\n\nYou will also need Google Application Credentials, and you will need to set them as environment variables (e.g. `GOOGLE_APPLICATION_CREDENTIALS=/home/user/Downloads/service-account-file.json`).\n\nFor more information on Google Application credentials, see \u003chttps://cloud.google.com/docs/authentication/getting-started#setting_the_environment_variable\u003e.\n\n\n## Usage\n\n1. Implement Mandarin and pass it an instance of [i18n][]\n\n   ```js\n   const Mandarin = require('mandarin');\n   const I18N = require('@ladjs/i18n');\n\n   const i18n = new I18N();\n\n   // you can also pass a custom `logger` option (it defaults to `console`)\n   const mandarin = new Mandarin({\n\n    // REQUIRED:\n    i18n\n\n    // OPTIONAL:\n    // logger: console,\n\n    // OPTIONAL (see index.js for defaults):\n    // redis: ...\n\n    // OPTIONAL (see index.js for defaults):\n    // redisMonitor: ...\n\n    // OPTIONAL:\n    // see all commented options from this following link:\n    // \u003chttps://googleapis.dev/nodejs/translate/5.0.1/v2_index.js.html\u003e\n    //\n    // clientConfig: {},\n\n    // OPTIONAL (see index.js for defaults):\n    // Files to convert from `index.md` to `index-es.md`\n    // Or `README.md` to `README-ZH.md` for example\n    // \u003chttps://github.com/sindresorhus/globby\u003e\n    //\n    // markdown: ... (note we expose `Mandarin.DEFAULT_PATTERNS` for you)\n   });\n\n   //\n   // Translate Phrases\n   //\n   // with async/await\n   (async () =\u003e {\n     try {\n       await mandarin.translate();\n     } catch (err) {\n       console.log(err);\n     }\n   })();\n\n   // with promises and then/catch\n   mandarin\n     .translate()\n     .then(() =\u003e {\n       console.log('done');\n     })\n     .catch(console.error);\n\n   // with callbacks\n   mandarin.translate(err =\u003e {\n     if (err) throw err;\n     console.log('done');\n   });\n\n   //\n   // Translate Markdown Files\n   //\n   // with async/await\n   (async () =\u003e {\n     try {\n       await mandarin.markdown();\n     } catch (err) {\n       console.log(err);\n     }\n   })();\n\n   // with promises and then/catch\n   mandarin\n     .markdown()\n     .then(() =\u003e {\n       console.log('done');\n     })\n     .catch(console.error);\n\n   // with callbacks\n   mandarin.markdown(err =\u003e {\n     if (err) throw err;\n     console.log('done');\n   });\n   ```\n\n2. This assumes that you have locale files already and a default locale file (e.g. `./locales/en.json` with phrases that need translated to other languages you support). Based off the defaults from [i18n][], you would automatically get your `en.json` file translated to the locales `es` (Spanish) and `zh` (Chinese).\n\n3. Follow the \"Before you begin\" steps here \u003chttps://cloud.google.com/translate/docs/basic/setup-basic\u003e (basically you download a JSON file after creating a Google Cloud Project with Cloud Translation API enabled).\n\n4. Specify the path to the JSON file and run your script that uses `mandarin`:\n\n```sh\nGOOGLE_APPLICATION_CREDENTIALS=\"/home/user/Downloads/[FILE_NAME].json\" node app.js\n```\n\n\n## Contributors\n\n| Name           | Website                    |\n| -------------- | -------------------------- |\n| **Nick Baugh** | \u003chttp://niftylettuce.com/\u003e |\n\n\n## License\n\n[MIT](LICENSE) © [Nick Baugh](http://niftylettuce.com/)\n\n\n##\n\n[npm]: https://www.npmjs.com/\n\n[i18n]: https://github.com/ladjs/i18n\n\n[redis]: https://redis.io/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladjs%2Fmandarin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fladjs%2Fmandarin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladjs%2Fmandarin/lists"}