fix(i18n): use WEKNORA_LANGUAGE env for prompt language fallback instead of hardcoded zh-CN

- Add DefaultLanguage() that reads WEKNORA_LANGUAGE env with zh-CN fallback
- Replace hardcoded zh-CN in LanguageNameFromContext with DefaultLanguage()
- Unify middleware/language.go to use types.DefaultLanguage()
- Add Language field to DocumentProcessPayload (8 enqueue sites + worker restore)
- Add Language field to ImageMultimodalPayload (enqueue + worker restore)
- Propagate language from ImageMultimodalPayload to QuestionGenerationPayload
This commit is contained in:
ochan.kwon
2026-04-01 21:34:17 +09:00
committed by lyingbug
parent 115bc826c2
commit 8a375749f1
5 changed files with 69 additions and 20 deletions
+21 -2
View File
@@ -1,6 +1,24 @@
package types
import "context"
import (
"context"
"os"
"strings"
)
// EnvLanguage returns the WEKNORA_LANGUAGE environment variable value, or empty string if unset.
func EnvLanguage() string {
return strings.TrimSpace(os.Getenv("WEKNORA_LANGUAGE"))
}
// DefaultLanguage returns the configured default language locale.
// It reads the WEKNORA_LANGUAGE environment variable; if unset, falls back to "zh-CN".
func DefaultLanguage() string {
if lang := EnvLanguage(); lang != "" {
return lang
}
return "zh-CN"
}
// TenantIDFromContext extracts the tenant ID from ctx.
// Returns (0, false) when the key is absent or the value is not uint64.
@@ -55,10 +73,11 @@ func LanguageFromContext(ctx context.Context) (string, bool) {
// LanguageNameFromContext returns the human-readable language name for use in prompts.
// e.g. "zh-CN" -> "Chinese (Simplified)", "en-US" -> "English", "ko-KR" -> "Korean"
// Falls back to DefaultLanguage() (WEKNORA_LANGUAGE env, then "zh-CN").
func LanguageNameFromContext(ctx context.Context) string {
lang, ok := LanguageFromContext(ctx)
if !ok {
lang = "zh-CN"
lang = DefaultLanguage()
}
return LanguageLocaleName(lang)
}
+2
View File
@@ -39,6 +39,7 @@ type DocumentProcessPayload struct {
EnableMultimodel bool `json:"enable_multimodel"`
EnableQuestionGeneration bool `json:"enable_question_generation"` // 是否启用问题生成
QuestionCount int `json:"question_count,omitempty"` // 每个chunk生成的问题数量
Language string `json:"language,omitempty"` // Request locale for {{language}} in prompt templates
}
// FAQImportPayload represents the FAQ import task payload (including dry run mode)
@@ -151,6 +152,7 @@ type ImageMultimodalPayload struct {
ImageLocalPath string `json:"image_local_path"` // deprecated: kept for backward compat with in-flight tasks
EnableOCR bool `json:"enable_ocr"`
EnableCaption bool `json:"enable_caption"`
Language string `json:"language,omitempty"` // Request locale for {{language}} in prompt templates
}
// KBCloneTaskStatus represents the status of a knowledge base clone task