feat: Add multi-translator support with DeepL backend - #5
Conversation
- Update module name from gopkg.gilang.dev/google-translate to gopkg.gilang.dev/translator - Update all import paths in source files - Update README with new module name and migration guide - Remove .idea directory - Add CLAUDE.md for development instructions The legacy module remains available on the v1 branch. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Rename api.go to gtranslate.go and api_test.go to gtranslate_test.go - Rename translateV1 function to gtranslate - Replace deprecated io/ioutil with io - Add context.Context parameter to all public API functions - Update HTTP requests to use NewRequestWithContext Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add GoogleTranslate struct with Host and Client fields - Add functional options: WithHost, WithHTTPClient - Add NewGoogleTranslate constructor for custom configuration - Convert check and translate to methods on GoogleTranslate - Add defaultClient for backward-compatible package-level functions - Update CLAUDE.md documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…afety - Create googletranslate package with concurrency-safe client - Add sync.RWMutex for thread-safe host/client access - Rename NewGoogleTranslate to New in googletranslate package - Add getter/setter methods: Host(), SetHost(), Client(), SetClient() - Simplify gtranslate.go to re-export only essential types - Remove unused type re-exports (TranslateFrom*, DefaultHost) - Add unit tests for googletranslate package - Update CLAUDE.md documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Create separate benchmark_test.go file - Use modern b.Loop() pattern for benchmarks - Add benchmarks for New, Host, SetHost, Translate - Add concurrent benchmarks for thread-safety testing Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add deepl package with concurrency-safe client - Add Translator interface for unified API across backends - Add UseGoogle/UseDeepL to switch default translator - Add NewGoogleTranslator/NewDeepLTranslator factory functions - Add TranslateWith for using specific translator instance - Add proxy support (WithProxyURL) to both clients - Add DeepL session support (WithDLSession) for Pro features - Remove legacy gtranslate.go re-exports - Add comprehensive examples (basic, google, deepl, multi) - Update tests and benchmarks for both packages - Update CLAUDE.md and README.md documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Rename DeepLX to DeepL (TranslateByDeepLX -> TranslateByDeepL) - Rename DeepLXTranslationResult to DeepLTranslationResult - Restructure googletranslate to match deepl file structure: - googletranslate.go: client, options, getters/setters - translate.go: translation logic - types.go: type definitions - utils.go: helper functions - Use github.com/imroc/req/v3 and github.com/tidwall/gjson in googletranslate - Both packages now use identical dependencies and structure Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Update actions/checkout to v4 - Update actions/setup-go to v5 - Test against Go 1.21, 1.22, 1.23 - Add build step before tests - Run tests for all packages (./...) - Add separate benchmark job Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add Benchmarks section with results for both packages - Include Google Translate and DeepL benchmark comparisons - Show client creation, getters/setters, and translation benchmarks Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add GitHub-style note callout at top of README - Link to v1 branch documentation for previous version - Include go get command for installing legacy version Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This pull request adds DeepL as a second translation backend alongside Google Translate, introducing a unified Translator interface for consistent API usage across backends. The codebase has been significantly restructured with new package organization, comprehensive examples, and updated documentation.
Changes:
- Added DeepL translation backend with full client implementation including proxy and session support
- Introduced
Translatorinterface allowing switching between backends viaUseGoogle()/UseDeepL()or using specific translators withTranslateWith() - Restructured codebase with
googletranslate/anddeepl/packages, each containing client, translation logic, types, and utilities - Added context.Context parameter to all translation functions for proper cancellation/timeout support
- Updated module path from
gopkg.gilang.dev/google-translatetogopkg.gilang.dev/translator(breaking change)
Reviewed changes
Copilot reviewed 25 out of 27 changed files in this pull request and generated 27 comments.
Show a summary per file
| File | Description |
|---|---|
| translate.go | Core API with Translator interface, adapters, and package-level translation functions |
| translate_test.go | Updated tests with context parameters and new multi-translator tests |
| googletranslate/*.go | Google Translate client implementation (refactored from api.go) |
| googletranslate/*_test.go | Unit and benchmark tests for Google client |
| deepl/*.go | New DeepL client implementation with full translation support |
| deepl/*_test.go | Unit and benchmark tests for DeepL client |
| go.mod/go.sum | Updated module path and added new dependencies (req/v3, gjson, whatlanggo, etc.) |
| example/* | Comprehensive examples for basic usage, Google, DeepL, and multi-translator scenarios |
| README.md | Updated documentation covering both backends and new API |
| CLAUDE.md | New developer documentation file |
| api.go/api_test.go | Removed legacy implementation |
| .idea/workspace.xml | Removed IDE-specific file (good practice) |
Files not reviewed (1)
- .idea/workspace.xml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@gilang-as I've opened a new pull request, #6, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
@gilang-as I've opened a new pull request, #7, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
@gilang-as I've opened a new pull request, #8, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
@gilang-as I've opened a new pull request, #9, to work on those changes. Once the pull request is ready, I'll request review from you. |
Co-authored-by: gilang-as <47550176+gilang-as@users.noreply.github.com>
Co-authored-by: gilang-as <47550176+gilang-as@users.noreply.github.com>
Co-authored-by: gilang-as <47550176+gilang-as@users.noreply.github.com>
[WIP] WIP Address feedback on multi-translator support
[WIP] Update multi-translator support with DeepL backend
Fix typo in error messages: "is't" → "isn't"
Co-authored-by: gilang-as <47550176+gilang-as@users.noreply.github.com>
Co-authored-by: gilang-as <47550176+gilang-as@users.noreply.github.com>
Fix typo in error messages: "is't" → "isn't"
|
@gilang-as I've opened a new pull request, #14, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
@gilang-as I've opened a new pull request, #15, to work on those changes. Once the pull request is ready, I'll request review from you. |
…tion Co-authored-by: gilang-as <47550176+gilang-as@users.noreply.github.com>
…4a0b-9242-1a181bf1e98d [WIP] Address feedback on multi-translator support
Co-authored-by: gilang-as <47550176+gilang-as@users.noreply.github.com>
Co-authored-by: gilang-as <47550176+gilang-as@users.noreply.github.com>
Co-authored-by: gilang-as <47550176+gilang-as@users.noreply.github.com>
Co-authored-by: gilang-as <47550176+gilang-as@users.noreply.github.com>
…ec5ee1-7a7e-409b-8f58-0f4862985fda
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…409b-8f58-0f4862985fda Fix DeepL client to use configured HTTP client with context support
Summary
Translatorinterface for consistent API across backendsChanges
New Features
UseGoogle()/UseDeepL()WithProxyURL()API Additions