feat(i18n): bilingual EN/ZH setup guide with language selection

store/telegram_config.go:
- Add Language field to TelegramConfig (persisted in DB)
- Add SetLanguage(lang) and GetLanguage() methods
- Default language: English (en)

telegram/bot.go:
- First /start triggers language selection (1=English, 2=中文)
- /lang command to change language at any time
- awaitingLang state machine handles language choice before any other input
- buildSetupGuide() now fully bilingual (EN/ZH), context-aware:
  Step 1: configure AI model (no model yet)
  Step 2: configure exchange (model OK, no exchange)
  Ready: show full capabilities
- tryHandleSetupCommand() bilingual: 'configure/配置 <provider> <key>'
- helpMessage(lang) fully bilingual
- All error/status messages bilingual

Default: English. isLangDefault() detects whether user has explicitly
chosen a language vs falling back to the 'en' default.
This commit is contained in:
tinkle-community
2026-03-08 18:44:38 +08:00
parent 1bbd4b44ac
commit d160301359
2 changed files with 242 additions and 55 deletions

View File

@@ -17,6 +17,7 @@ type TelegramConfig struct {
Username string `gorm:"column:username"` // @username for display
BoundAt time.Time `gorm:"column:bound_at"`
ModelID string `gorm:"column:model_id;default:''"` // AI model used for Telegram replies
Language string `gorm:"column:language;default:''"` // "zh" or "en"; empty = not chosen yet
CreatedAt time.Time
UpdatedAt time.Time
}
@@ -40,6 +41,8 @@ type TelegramConfigStore interface {
IsBound() (bool, error) // Check if any user is bound
GetBoundChatID() (int64, error) // Get bound chat ID (0 if not bound)
Unbind() error // Remove binding
SetLanguage(lang string) error // Set UI language ("en" or "zh")
GetLanguage() string // Get UI language; returns "en" if not set
}
type telegramConfigStore struct {
@@ -133,3 +136,29 @@ func (s *telegramConfigStore) Unbind() error {
"username": "",
}).Error
}
func (s *telegramConfigStore) SetLanguage(lang string) error {
s.mu.Lock()
defer s.mu.Unlock()
var cfg TelegramConfig
result := s.db.First(&cfg, 1)
if result.Error != nil && !errors.Is(result.Error, gorm.ErrRecordNotFound) {
return result.Error
}
cfg.ID = 1
cfg.Language = lang
return s.db.Save(&cfg).Error
}
func (s *telegramConfigStore) GetLanguage() string {
s.mu.RLock()
defer s.mu.RUnlock()
var cfg TelegramConfig
if err := s.db.First(&cfg, 1).Error; err != nil {
return "en" // default: English
}
if cfg.Language == "" {
return "en"
}
return cfg.Language
}