summaryrefslogtreecommitdiff
path: root/internal/processor
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-01 13:00:40 +0300
committerPaul Buetow <paul@buetow.org>2026-04-01 13:00:40 +0300
commitb006582e4c7323821eb836080a9bc9ec24243a47 (patch)
treea8e96ecdc74cd2a5bb19148d8a6a7cf90f6cbbb4 /internal/processor
parenta574e5290261f9ea2cc39fd0a9a2ba756fc1f67a (diff)
zr: add Gemini-backed translation provider
Diffstat (limited to 'internal/processor')
-rw-r--r--internal/processor/processor.go7
-rw-r--r--internal/processor/processor_test.go21
2 files changed, 11 insertions, 17 deletions
diff --git a/internal/processor/processor.go b/internal/processor/processor.go
index d52ca53..94b0448 100644
--- a/internal/processor/processor.go
+++ b/internal/processor/processor.go
@@ -32,12 +32,13 @@ type Processor struct {
// NewProcessor creates a new word processor
func NewProcessor(flags *cli.Flags) *Processor {
- apiKey := cli.GetOpenAIKey()
+ openAIKey := cli.GetOpenAIKey()
+ translationProvider := translation.Provider(viper.GetString("translation.provider"))
return &Processor{
flags: flags,
- translator: translation.NewTranslator(apiKey),
+ translator: translation.NewTranslator(&translation.Config{Provider: translationProvider, OpenAIKey: openAIKey, GoogleAPIKey: cli.GetGoogleAPIKey()}),
translationCache: translation.NewTranslationCache(),
- phoneticFetcher: phonetic.NewFetcher(apiKey),
+ phoneticFetcher: phonetic.NewFetcher(openAIKey),
}
}
diff --git a/internal/processor/processor_test.go b/internal/processor/processor_test.go
index e835681..a9c9ab1 100644
--- a/internal/processor/processor_test.go
+++ b/internal/processor/processor_test.go
@@ -9,15 +9,8 @@ import (
)
func TestNewProcessor(t *testing.T) {
- // Set up test environment
- if err := os.Setenv("OPENAI_API_KEY", "test-key"); err != nil {
- t.Fatalf("Failed to set OPENAI_API_KEY: %v", err)
- }
- defer func() {
- if err := os.Unsetenv("OPENAI_API_KEY"); err != nil {
- t.Errorf("Failed to unset OPENAI_API_KEY: %v", err)
- }
- }()
+ t.Setenv("OPENAI_API_KEY", "test-openai-key")
+ t.Setenv("GOOGLE_API_KEY", "test-google-key")
flags := cli.NewFlags()
p := NewProcessor(flags)
@@ -63,8 +56,8 @@ func TestProcessSingleWord_InvalidWord(t *testing.T) {
func TestProcessSingleWord_ValidWord(t *testing.T) {
// Skip if no API key
- if os.Getenv("OPENAI_API_KEY") == "" {
- t.Skip("Skipping test: OPENAI_API_KEY not set")
+ if os.Getenv("OPENAI_API_KEY") == "" || os.Getenv("GOOGLE_API_KEY") == "" {
+ t.Skip("Skipping test: OPENAI_API_KEY and GOOGLE_API_KEY must be set")
}
flags := cli.NewFlags()
@@ -114,9 +107,9 @@ func TestProcessBatch_ValidFile(t *testing.T) {
flags.SkipImages = true
p := NewProcessor(flags)
- // Skip if no API key
- if os.Getenv("OPENAI_API_KEY") == "" {
- t.Skip("Skipping test: OPENAI_API_KEY not set")
+ // Skip if no API keys
+ if os.Getenv("OPENAI_API_KEY") == "" || os.Getenv("GOOGLE_API_KEY") == "" {
+ t.Skip("Skipping test: OPENAI_API_KEY and GOOGLE_API_KEY must be set")
}
err = p.ProcessBatch()