diff --git a/experimental/deprecated/constants.go b/experimental/deprecated/constants.go index fd785dbc..f5b67119 100644 --- a/experimental/deprecated/constants.go +++ b/experimental/deprecated/constants.go @@ -1,8 +1,11 @@ package deprecated import ( + "fmt" + "github.com/sagernet/sing-box/common/badversion" C "github.com/sagernet/sing-box/constant" + "github.com/sagernet/sing-box/experimental/locale" F "github.com/sagernet/sing/common/format" "golang.org/x/mod/semver" @@ -33,10 +36,11 @@ func (n Note) Impending() bool { } func (n Note) Message() string { - return F.ToString( - n.Description, " is deprecated in sing-box ", n.DeprecatedVersion, - " and will be removed in sing-box ", n.ScheduledVersion, ", please checkout documentation for migration.", - ) + if n.MigrationLink != "" { + return fmt.Sprintf(locale.Current().DeprecatedMessage, n.Description, n.DeprecatedVersion, n.ScheduledVersion) + } else { + return fmt.Sprintf(locale.Current().DeprecatedMessageNoLink, n.Description, n.DeprecatedVersion, n.ScheduledVersion) + } } func (n Note) MessageWithLink() string { diff --git a/experimental/libbox/setup.go b/experimental/libbox/setup.go index eb5d7c4e..ea941ecf 100644 --- a/experimental/libbox/setup.go +++ b/experimental/libbox/setup.go @@ -9,6 +9,7 @@ import ( "github.com/sagernet/sing-box/common/humanize" C "github.com/sagernet/sing-box/constant" + "github.com/sagernet/sing-box/experimental/locale" _ "github.com/sagernet/sing-box/include" "github.com/sagernet/sing-box/log" ) @@ -54,6 +55,10 @@ func SetupWithUsername(basePath string, workingPath string, tempPath string, use return nil } +func SetLocale(localeId string) { + locale.Set(localeId) +} + func Version() string { return C.Version } diff --git a/experimental/locale/locale.go b/experimental/locale/locale.go new file mode 100644 index 00000000..b1736780 --- /dev/null +++ b/experimental/locale/locale.go @@ -0,0 +1,30 @@ +package locale + +var ( + localeRegistry = make(map[string]*Locale) + current = defaultLocal +) + +type Locale struct { + // deprecated messages for graphical clients + DeprecatedMessage string + DeprecatedMessageNoLink string +} + +var defaultLocal = &Locale{ + DeprecatedMessage: "%s is deprecated in sing-box %s and will be removed in sing-box %s please checkout documentation for migration.", + DeprecatedMessageNoLink: "%s is deprecated in sing-box %s and will be removed in sing-box %s.", +} + +func Current() *Locale { + return current +} + +func Set(localeId string) bool { + locale, loaded := localeRegistry[localeId] + if !loaded { + return false + } + current = locale + return true +} diff --git a/experimental/locale/locale_zh_CN.go b/experimental/locale/locale_zh_CN.go new file mode 100644 index 00000000..5db2f274 --- /dev/null +++ b/experimental/locale/locale_zh_CN.go @@ -0,0 +1,10 @@ +package locale + +var warningMessageForEndUsers = "\n\n如果您不明白此消息意味着什么:您的配置文件已过时,且将很快不可用。请联系您的配置提供者以更新配置。" + +func init() { + localeRegistry["zh_CN"] = &Locale{ + DeprecatedMessage: "%s 已在 sing-box %s 中被弃用,且将在 sing-box %s 中被移除,请参阅迁移指南。" + warningMessageForEndUsers, + DeprecatedMessageNoLink: "%s 已在 sing-box %s 中被弃用,且将在 sing-box %s 中被移除。" + warningMessageForEndUsers, + } +}