mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 04:30:05 +00:00
i18n: replace gettext implementation (#1056)
This commit is contained in:
32
pkg/i18n/i18n_test.go
Normal file
32
pkg/i18n/i18n_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package i18n
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestI18n(t *testing.T) {
|
||||
const testStr = "database error"
|
||||
|
||||
t.Run("SwitchLocale", func(t *testing.T) {
|
||||
loc := NewLocalizer("zh_CN", "nezha", "translations", Translations)
|
||||
translated := loc.T(testStr)
|
||||
if translated != "数据库错误" {
|
||||
t.Fatalf("expected %s, but got %s", "数据库错误", translated)
|
||||
}
|
||||
|
||||
loc.AppendIntl("zh_TW")
|
||||
loc.SetLanguage("zh_TW")
|
||||
translated = loc.T(testStr)
|
||||
if translated != "資料庫錯誤" {
|
||||
t.Fatalf("expected %s, but got %s", "資料庫錯誤", translated)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Fallback", func(t *testing.T) {
|
||||
loc := NewLocalizer("invalid", "nezha", "translations", Translations)
|
||||
fallbackStr := loc.T(testStr)
|
||||
if fallbackStr != testStr {
|
||||
t.Fatalf("expected %s, but got %s", testStr, fallbackStr)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user