{"id":17787359,"url":"https://github.com/simon-he95/translate","last_synced_at":"2025-08-13T01:33:32.762Z","repository":{"id":154124407,"uuid":"631889114","full_name":"Simon-He95/translate","owner":"Simon-He95","description":"api for translating powered by bing","archived":false,"fork":false,"pushed_at":"2024-10-03T15:13:47.000Z","size":140,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-24T20:49:33.976Z","etag":null,"topics":["translate","translate-api"],"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/Simon-He95.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"Simon-He95","custom":["https://github.com/Simon-He95/sponsor"]}},"created_at":"2023-04-24T09:19:17.000Z","updated_at":"2024-10-03T15:13:51.000Z","dependencies_parsed_at":"2023-12-15T03:47:23.887Z","dependency_job_id":"613a66ef-2668-476a-b330-c1a738897ca9","html_url":"https://github.com/Simon-He95/translate","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Simon-He95%2Ftranslate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Simon-He95%2Ftranslate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Simon-He95%2Ftranslate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Simon-He95%2Ftranslate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Simon-He95","download_url":"https://codeload.github.com/Simon-He95/translate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229724349,"owners_count":18114429,"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":["translate","translate-api"],"created_at":"2024-10-27T10:10:19.385Z","updated_at":"2025-08-13T01:33:32.733Z","avatar_url":"https://github.com/Simon-He95.png","language":"TypeScript","funding_links":["https://github.com/sponsors/Simon-He95","https://github.com/Simon-He95/sponsor"],"categories":[],"sub_categories":[],"readme":"# @simon_he/translate\n\n🚀 A fast, robust, and lightweight translation library supporting **6 translation services** with automatic fallback, batch processing, intelligent caching, and full TypeScript support.\n\n## ✨ Features\n\n- 🌐 **Multiple Translation Providers**: Google, Bing, DeepL, MyMemory, Lingva\n- 🔄 **Automatic Fallback**: If one service fails, automatically tries others\n- ⚡ **Batch Processing**: Translate multiple texts concurrently\n- 🧠 **Smart Caching**: LRU cache to avoid repeated API calls\n- 🎯 **Promise.any Racing**: Uses the fastest available service\n- 📦 **Zero Dependencies**: Lightweight and fast\n- 🔒 **TypeScript Support**: Full type safety\n- 🆓 **Free Options**: Includes free translation services\n\n## 🌍 Supported Translation Services\n\n| Service | Type | Status | Free Tier | API Key Required |\n|---------|------|--------|-----------|------------------|\n| **MyMemory** | Free | ✅ Working | 1000 requests/day | No |\n| **Bing Translator** | Commercial | ✅ Working | 2M chars/month | No* |\n| **Google Translate** | Commercial | ⚠️ Limited | 500K chars/month | No* |\n| **DeepL** | Commercial | ⚠️ Rate Limited | 500K chars/month | No* |\n| **Lingva** | Free Proxy | ⚠️ Blocked | Unlimited | No |\n\n*\\* These services use unofficial APIs and may have limitations or availability issues*\n\n**✅ Recommended for Production**: MyMemory, Bing\n**⚠️ Use with Caution**: Google (timeouts), DeepL (rate limits), Lingva (blocked)\n\n## 📦 Installation\n\n```bash\nnpm install @simon_he/translate\n# or\npnpm add @simon_he/translate\n# or\nyarn add @simon_he/translate\n```\n\n## 🚀 Quick Start\n\n```typescript\nimport translateLoader from '@simon_he/translate'\n\nconst translate = translateLoader()\n\n// Translate single text\nconst result = await translate('Hello world', 'zh')\nconsole.log(result) // ['世界您好']\n\n// Translate multiple texts (batch processing)\nconst results = await translate(['Hello', 'Good morning'], 'zh')\nconsole.log(results) // ['你好', '早上好']\n\n// English to Chinese (default)\nconst zhResult = await translate('Hello')\nconsole.log(zhResult) // ['你好']\n\n// Chinese to English\nconst enResult = await translate('你好', 'en')\nconsole.log(enResult) // ['Hello']\n```\n\n## 🔧 Advanced Usage\n\n### Individual Service Usage\n\n```typescript\nimport {\n  bingTranslate,\n  googleTranslate,\n  lingvaTranslate,\n  mymemoryTranslate\n} from '@simon_he/translate'\n\n// Use specific service\nconst google = googleTranslate()\nconst result = await google('Hello', 'zh')\nconsole.log(result.text) // '你好'\n```\n\n### Custom Cache Configuration\n\n```typescript\nimport translateLoader from '@simon_he/translate'\n\n// Create translator with custom cache size\nconst translate = translateLoader(createLimitedCache(500))\n```\n\n## 🎯 API Reference\n\n### `translateLoader(cacheMap?)`\n\nCreates a translation function with automatic service fallback.\n\n**Parameters:**\n- `cacheMap` (optional): Custom cache implementation\n\n**Returns:** `(texts: string | string[], to?: 'en' | 'zh') =\u003e Promise\u003cstring[]\u003e`\n\n### Individual Services\n\nEach service exports a `fanyi()` function:\n\n```typescript\ntype TranslateFunction = (text: string, to?: string, from?: string) =\u003e Promise\u003c{ text: string }\u003e\n```\n\n## 🧪 Testing\n\n```bash\n# Run main tests\nnpm test\n\n# Run performance tests\nnpm run test:performance\n\n# Run stress tests\nnpm run test:stress\n\n# Run benchmark tests\nnpm run test:benchmark\n\n# Run all tests\nnpm run test:all\n```\n\n## License\n[MIT](./LICENSE) License © 2022 [Simon He](https://github.com/Simon-He95)\n\n\u003ca href=\"https://github.com/Simon-He95/sponsor\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/default-orange.png\" alt=\"Buy Me A Coffee\" style=\"height: 51px !important;width: 217px !important;\" \u003e\u003c/a\u003e\n\n\u003cspan\u003e\u003cdiv align=\"center\"\u003e![sponsors](https://www.hejian.club/images/sponsors.jpg)\u003c/div\u003e\u003c/span\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimon-he95%2Ftranslate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimon-he95%2Ftranslate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimon-he95%2Ftranslate/lists"}