Skip to content

feat: Add multi-translator support with DeepL backend - #5

Merged
gilang-as merged 52 commits into
mainfrom
feat/multi-translator-support
Feb 2, 2026
Merged

feat: Add multi-translator support with DeepL backend#5
gilang-as merged 52 commits into
mainfrom
feat/multi-translator-support

Conversation

@gilang-as

Copy link
Copy Markdown
Owner

Summary

  • Add DeepL as a second translation backend alongside Google Translate
  • Introduce unified Translator interface for consistent API across backends
  • Restructure codebase with standardized package layout
  • Add comprehensive examples and documentation

Changes

New Features

  • DeepL Support: Full DeepL translation client with proxy and session support
  • Multi-translator API: Switch between backends using UseGoogle() / UseDeepL()
  • Translator Interface: Common interface allowing custom translator implementations
  • Proxy Support: Both clients now support proxy configuration via WithProxyURL()

API Additions

// Switch default translator                                                                                                        
gt.UseGoogle()                                                                                                                      
gt.UseDeepL()                                                                                                                       
                                                                                                                                    
// Use specific translator                                                                                                          
google := gt.NewGoogleTranslator()                                                                                                  
deepl := gt.NewDeepLTranslator()                                                                                                    
gt.TranslateWith(ctx, translator, text, targetLang)                                                                                 
                                                                                                                                    
Package Structure                                                                                                                   
                                                                                                                                    
Both googletranslate/ and deepl/ now share identical structure:                                                                     
- *.go - Client, options, getters/setters                                                                                           
- translate.go - Translation logic                                                                                                  
- types.go - Type definitions                                                                                                       
- utils.go - Helper functions                                                                                                       
                                                                                                                                    
Dependencies                                                                                                                        
                                                                                                                                    
- Both packages use github.com/imroc/req/v3 for HTTP                                                                                
- Both packages use github.com/tidwall/gjson for JSON parsing                                                                       
                                                                                                                                    
Breaking Changes                                                                                                                    
                                                                                                                                    
- Removed legacy gtranslate.go re-exports                                                                                           
- Module renamed to gopkg.gilang.dev/translator                                                                                     
                                                                                                                                    
Test Plan                                                                                                                           
                                                                                                                                    
- All existing tests pass                                                                                                           
- New unit tests for DeepL client                                                                                                   
- Benchmark tests for both packages                                                                                                 
- Integration tests with live APIs                                                                                                  
                                                                                                                                    
🤖 Generated with https://claude.com/claude-code                                                                                    
                                                                                                                                    
---                                                        

gilang-as and others added 7 commits February 2, 2026 09:47
- 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>
@gilang-as
gilang-as requested a review from Copilot February 2, 2026 04:09
- 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>
gilang-as and others added 2 commits February 2, 2026 11:15
- 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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Translator interface allowing switching between backends via UseGoogle() / UseDeepL() or using specific translators with TranslateWith()
  • Restructured codebase with googletranslate/ and deepl/ 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-translate to gopkg.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.

Comment thread deepl/deepl.go
Comment thread translate.go Outdated
Comment thread translate.go Outdated
Comment thread translate.go Outdated
Comment thread deepl/benchmark_test.go Outdated
Comment thread deepl/deepl.go
Comment thread translate.go Outdated
Comment thread googletranslate/benchmark_test.go Outdated
Comment thread googletranslate/benchmark_test.go Outdated
Comment thread deepl/benchmark_test.go Outdated

Copilot AI commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

@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.

Copilot AI commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

@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.

Copilot AI commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

@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.

Copilot AI commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

@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.

Copilot AI and others added 10 commits February 2, 2026 04:53
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"

Copilot AI commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

@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.

Copilot AI commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

@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.

Copilot AI and others added 14 commits February 2, 2026 05:00
…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>
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
@gilang-as
gilang-as merged commit 51388df into main Feb 2, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants