mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-12-27 01:55:39 +08:00
Add locale support ford deprecated messages
This commit is contained in:
parent
2ac2589d14
commit
e6847ff50e
|
@ -1,8 +1,11 @@
|
||||||
package deprecated
|
package deprecated
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/sagernet/sing-box/common/badversion"
|
"github.com/sagernet/sing-box/common/badversion"
|
||||||
C "github.com/sagernet/sing-box/constant"
|
C "github.com/sagernet/sing-box/constant"
|
||||||
|
"github.com/sagernet/sing-box/experimental/locale"
|
||||||
F "github.com/sagernet/sing/common/format"
|
F "github.com/sagernet/sing/common/format"
|
||||||
|
|
||||||
"golang.org/x/mod/semver"
|
"golang.org/x/mod/semver"
|
||||||
|
@ -33,10 +36,11 @@ func (n Note) Impending() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n Note) Message() string {
|
func (n Note) Message() string {
|
||||||
return F.ToString(
|
if n.MigrationLink != "" {
|
||||||
n.Description, " is deprecated in sing-box ", n.DeprecatedVersion,
|
return fmt.Sprintf(locale.Current().DeprecatedMessage, n.Description, n.DeprecatedVersion, n.ScheduledVersion)
|
||||||
" and will be removed in sing-box ", n.ScheduledVersion, ", please checkout documentation for migration.",
|
} else {
|
||||||
)
|
return fmt.Sprintf(locale.Current().DeprecatedMessageNoLink, n.Description, n.DeprecatedVersion, n.ScheduledVersion)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n Note) MessageWithLink() string {
|
func (n Note) MessageWithLink() string {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/sagernet/sing-box/common/humanize"
|
"github.com/sagernet/sing-box/common/humanize"
|
||||||
C "github.com/sagernet/sing-box/constant"
|
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/include"
|
||||||
"github.com/sagernet/sing-box/log"
|
"github.com/sagernet/sing-box/log"
|
||||||
)
|
)
|
||||||
|
@ -54,6 +55,10 @@ func SetupWithUsername(basePath string, workingPath string, tempPath string, use
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetLocale(localeId string) {
|
||||||
|
locale.Set(localeId)
|
||||||
|
}
|
||||||
|
|
||||||
func Version() string {
|
func Version() string {
|
||||||
return C.Version
|
return C.Version
|
||||||
}
|
}
|
||||||
|
|
30
experimental/locale/locale.go
Normal file
30
experimental/locale/locale.go
Normal file
|
@ -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
|
||||||
|
}
|
10
experimental/locale/locale_zh_CN.go
Normal file
10
experimental/locale/locale_zh_CN.go
Normal file
|
@ -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,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user