feat(i18n): add Russian UI and harden localization

This commit is contained in:
Arthur Koba
2026-10-25 22:35:32 +03:00
parent 65a96670d5
commit b4e94076c9
115 changed files with 7767 additions and 993 deletions
+5 -2
View File
@@ -13,7 +13,6 @@ import (
"github.com/Rain-kl/Wavelet/internal/infra/task"
"github.com/Rain-kl/Wavelet/internal/model"
"github.com/Rain-kl/Wavelet/internal/repository"
"github.com/Rain-kl/Wavelet/pkg/i18n"
pkgpush "github.com/Rain-kl/Wavelet/pkg/push"
"gorm.io/gorm"
)
@@ -25,6 +24,10 @@ type smtpConfig struct {
Password string
}
// This persisted recipient alias predates localization. Display translations
// must never expand the set of reserved routing identifiers.
const legacySystemTarget = "\u7cfb\u7edf"
func loadSMTPConfig(ctx context.Context) smtpConfig {
host, _ := repository.GetSystemConfigByKey(ctx, model.ConfigKeySMTPHost)
port, _ := repository.GetSystemConfigByKey(ctx, model.ConfigKeySMTPPort)
@@ -332,7 +335,7 @@ func resolveTargetUser(ctx context.Context, resolved string, _ string) (model.Us
}
func resolveSystemTarget(ctx context.Context, resolved string, channel string) (string, bool) {
if i18n.Translate("en", resolved) != "System" && resolved != "system" && resolved != "0" {
if resolved != legacySystemTarget && resolved != "system" && resolved != "0" {
return "", false
}
adminUser, err := repository.GetFirstAdminUser(ctx)
+18
View File
@@ -553,6 +553,24 @@ func TestResolveTarget(t *testing.T) {
ctx := context.Background()
for index, username := range []string{"System", "Система"} {
t.Run("translated system label is an ordinary username/"+username, func(t *testing.T) {
user := model.User{
ID: uint64(20000 + index), Username: username,
Email: "ordinary_" + strconv.Itoa(index) + "@example.invalid",
}
if err := dbConn.Create(&user).Error; err != nil {
t.Fatalf("create user %q: %v", username, err)
}
for _, target := range []string{username, "user.username"} {
body := map[string]any{"user.username": username}
if got := resolveTarget(ctx, target, body, channelEmail); got != user.Email {
t.Errorf("resolveTarget(%q, username=%q, email) = %q, want %q", target, username, got, user.Email)
}
}
})
}
t.Run("dynamic user.id resolved and converted for email channel", func(t *testing.T) {
res := resolveTarget(ctx, "user.id", flatBody, "email")
assert.Equal(t, "target@test.com", res)
@@ -0,0 +1,26 @@
// Copyright 2026 Arctel.net
// SPDX-License-Identifier: Apache-2.0
package status
import (
"testing"
"time"
)
func TestFormatDuration(t *testing.T) {
for _, tc := range []struct {
duration time.Duration
want string
}{
{duration: 0, want: "0 seconds"},
{duration: time.Second, want: "1 second"},
{duration: 61 * time.Second, want: "1 minute 1 second"},
{duration: 26 * time.Hour, want: "1 day 2 hours"},
{duration: 48*time.Hour + 2*time.Minute + 5*time.Second, want: "2 days 2 minutes 5 seconds"},
} {
if got := formatDuration(tc.duration); got != tc.want {
t.Errorf("formatDuration(%v) = %q, want %q", tc.duration, got, tc.want)
}
}
}
+14 -13
View File
@@ -16,6 +16,7 @@ import (
"path/filepath"
"runtime"
"strconv"
"strings"
"time"
"github.com/Rain-kl/Wavelet/internal/infra/config"
@@ -118,20 +119,20 @@ func formatDuration(d time.Duration) string {
minutes := int(d.Minutes()) % minutesInHour
seconds := int(d.Seconds()) % secondsInMinute
var res string
if days > 0 {
res += fmt.Sprintf("%d days", days)
var parts []string
for _, part := range []struct {
value int
unit string
}{{days, "day"}, {hours, "hour"}, {minutes, "minute"}, {seconds, "second"}} {
if part.value > 0 || (part.unit == "second" && len(parts) == 0) {
unit := part.unit
if part.value != 1 {
unit += "s"
}
parts = append(parts, fmt.Sprintf("%d %s", part.value, unit))
}
}
if hours > 0 {
res += fmt.Sprintf("%d hours", hours)
}
if minutes > 0 {
res += fmt.Sprintf("%d minutes", minutes)
}
if seconds > 0 || res == "" {
res += fmt.Sprintf("%d seconds", seconds)
}
return res
return strings.Join(parts, " ")
}
// GetSystemStatus 获取系统状态信息