{"id":13832190,"url":"https://github.com/ant-tool/atool-l10n","last_synced_at":"2025-04-13T08:31:29.732Z","repository":{"id":57186387,"uuid":"65001166","full_name":"ant-tool/atool-l10n","owner":"ant-tool","description":"🌍 localized message files generating automatic solution","archived":false,"fork":false,"pushed_at":"2019-04-11T05:45:54.000Z","size":25,"stargazers_count":47,"open_issues_count":7,"forks_count":10,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-09T18:43:16.977Z","etag":null,"topics":["i18n","l10n","l10n-helper","react-intl","translation"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ant-tool.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-05T08:10:06.000Z","updated_at":"2024-12-05T08:53:43.000Z","dependencies_parsed_at":"2022-09-14T16:22:20.045Z","dependency_job_id":null,"html_url":"https://github.com/ant-tool/atool-l10n","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ant-tool%2Fatool-l10n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ant-tool%2Fatool-l10n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ant-tool%2Fatool-l10n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ant-tool%2Fatool-l10n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ant-tool","download_url":"https://codeload.github.com/ant-tool/atool-l10n/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248684251,"owners_count":21145046,"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":["i18n","l10n","l10n-helper","react-intl","translation"],"created_at":"2024-08-04T10:01:54.082Z","updated_at":"2025-04-13T08:31:29.419Z","avatar_url":"https://github.com/ant-tool.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# atool-l10n\n\n- collection all meta data generated by babel\n- fetch translate result from machine translation center\n- save the translation into local\n\nautomatical solution for generating localization resource using middlewares\n\n[Demo in React](https://github.com/ant-design/intl-example)\n\n![](https://zos.alipayobjects.com/rmsportal/JoGKhgfuFXaJNzK.gif)\n\n## Usage\n\n\n- setup\n\n  ```bash\n  $ npm i atool-l10n --save-dev\n  ```\n- add `l10n.config.js` into the same root dir of your project\n\n  ```js\n  // default config\n  module.exports = {\n    middlewares: {\n      summary: ['summary?sourcePattern=i18n-messages/**/*.json'],\n      process: [\n        'fetchLocal?source=locales,skip',\n        'metaToResult?from=defaultMessage,to=zh',\n        'youdao?apiname=iamatestmanx,apikey=2137553564',\n        'reduce?-autoPick,autoReduce[]=local,autoReduce[]=meta',\n      ],\n      emit: ['save?dest=locales'],\n    },\n  };\n  ```\n- run\n\n  ```bash\n  $ node_modules/.bin/atool-l10n\n  ```\n\n## Options\n\n```bash\n\n  Usage: atool-l10n [options]\n\n  Options:\n\n    -h, --help        output usage information\n    -v, --version     output the version number\n    --config \u003cdir\u003e    where is the config file, default is l10n.config.js\n\n```\n\n## Middleware\n\n`atool-l10n` middlewares will execute one by one, with parameter `query` and shared context\n\nA middleware may looks like this: \n\n```\nexport default function something(query) {\n  this.getMeta();\n  this.setResult();\n  this.setOption();\n  ...\n}\n```\n\n- query: parameters passed to current middleware\n  - parse from `option.config(default is l10n.config.js)`\n  - parsed by [loader-utils](https://github.com/webpack/loader-utils)\n\n#### Context\n\nThere are necessary operation and usefull methods on `this` context in the function \n\nYou can check the detail API via [file](https://github.com/ant-tool/atool-l10n/tree/master/src/context.js)\n\n#### Built-in middlewares\n\n- `summary`: collect origin data generated from `babel-plugin-react-intl`\n\n|parameter|default|description|\n|:-------:|:-----:|:---------:|\n|`sourcePattern`|`'i18n-messages/**/*.json'`|where the messages json files is, specified in `babel-plugin-react-intl`, array supported|\n\n- `fetchLocal`: add local locales messages as an option of translation result\n\n|parameter|default|description|\n|:-------:|:-----:|:---------:|\n|`source`|`'locales'`|where the local locales messages file is, file name is same as language name, eg: `zh`|\n|`skip`|`true`|if add the id into translating skip array when all local locales messages for it is not empty|\n\n- `metaToResult`: take defaultMessage or other key of meta into an option of translation result\n\n|parameter|default|description|\n|:-------:|:-----:|:---------:|\n|`from`|`'defaultMessage'`|using which key of meta, eg: `defaultMessage`, `id`, `description`...|\n|`to`|`'zh'`|the language you want to save as|\n\n- `youdao`: fetch translate result from zh to en from youdao\n\n|parameter|default|description|\n|:-------:|:-----:|:---------:|\n|`apiname`|`'iamatestmanx'`|apiname you applied for machine translation from youdao|\n|`apikey`|`'2137553564'`|apikey you applied for machine translation from youdao|\n\nyou can easily apply the apiname and apikey from [youdao](http://fanyi.youdao.com/openapi?path=data-mode)\n\n- `google`: fetch translate result from zh to en from google translate\n\n|parameter|default|description|\n|:-------:|:-----:|:---------:|\n|`from`|`'zh-cn'`|string, what languages you want to translate from|\n|`to`|`'en'`|string, what languages you want to translate to|\n|`tld`|`'cn'`|string, which TLD of Google Translate you want to use, form: `translate.google.${tld}`|\n\nuse [google-translate-api](https://github.com/matheuss/google-translate-api)\n\n- `gugu`: automatic contextualized translate for multi languages of each id from gugu, only available in alibaba-network\n\n|parameter|default|description|\n|:-------:|:-----:|:---------:|\n|`from`|`'zh'`|can be an array, what languages you want to translate from|\n|`to`|`'en'`|can be an array, what languages you want to translate to|\n\n- `reduce`: pick the best translation, among all translation options in terminal\n\n|parameter|default|description|\n|:-------:|:-----:|:---------:|\n|`autoPick`|`false`|auto pick the value of index `[autoPick]`|\n|`autoReduce`|`['local', 'meta']`|auto reduce some options, the smallest index wins, values of the other index in the array will be delete|\n\n\n- `save`: save translation result into local locale files, which are required directly by source code\n\n|parameter|default|description|\n|:-------:|:-----:|:---------:|\n|`dest`|`'locales'`|save locales messages into where, message file named by language name|","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fant-tool%2Fatool-l10n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fant-tool%2Fatool-l10n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fant-tool%2Fatool-l10n/lists"}