Unverified Commit 4c1125a8 authored by Eric_Lee's avatar Eric_Lee Committed by GitHub

Dev i18n (#118)

 [Update] i18n info
parent 79010965
......@@ -8,171 +8,161 @@ msgstr ""
"X-Generator: xgotext\n"
#. i18n.T
#: pkg/auth/server.go:17
msgid "Please enter 6 digits."
msgstr ""
#. i18n.T
#: pkg/auth/server.go:18
msgid "[MFA auth]: "
msgstr ""
#. i18n.T
#: pkg/handler/banner.go:32
#: pkg/handler/banner.go:31
msgid "\t%d) Enter {{.GreenBoldColor}}%s{{.ColorEnd}} to %s.%s"
msgstr ""
#. i18n.T
#: pkg/handler/banner.go:47
#: pkg/handler/banner.go:46
msgid "Welcome to use Jumpserver open source fortress system"
msgstr ""
#. i18n.T
#: pkg/handler/banner.go:49
#: pkg/handler/banner.go:48
msgid "directly login"
msgstr ""
#. i18n.T
#: pkg/handler/banner.go:50
#: pkg/handler/banner.go:49
msgid "part IP, Hostname, Comment"
msgstr ""
#. i18n.T
#: pkg/handler/banner.go:50
#: pkg/handler/banner.go:49
msgid "to search login if unique"
msgstr ""
#. i18n.T
#: pkg/handler/banner.go:51
#: pkg/handler/banner.go:50
msgid "/ + IP, Hostname, Comment"
msgstr ""
#. i18n.T
#: pkg/handler/banner.go:51
#: pkg/handler/banner.go:50
msgid "to search, such as: /192.168"
msgstr ""
#. i18n.T
#: pkg/handler/banner.go:52
#: pkg/handler/banner.go:51
msgid "display the host you have permission"
msgstr ""
#. i18n.T
#: pkg/handler/banner.go:53
#: pkg/handler/banner.go:52
msgid "display the node that you have permission"
msgstr ""
#. i18n.T
#: pkg/handler/banner.go:54
#: pkg/handler/banner.go:53
msgid "refresh your assets and nodes"
msgstr ""
#. i18n.T
#: pkg/handler/banner.go:55
#: pkg/handler/banner.go:54
msgid "print help"
msgstr ""
#. i18n.T
#: pkg/handler/banner.go:56
#: pkg/handler/banner.go:55
msgid "exit"
msgstr ""
#. i18n.T
#: pkg/handler/pagination.go:133
#: pkg/handler/banner.go:90
msgid "ID"
msgstr ""
#. i18n.T
#: pkg/handler/pagination.go:133
#: pkg/handler/banner.go:91
msgid "hostname"
msgstr ""
#. i18n.T
#: pkg/handler/pagination.go:133
#: pkg/handler/banner.go:92
msgid "IP"
msgstr ""
#. i18n.T
#: pkg/handler/pagination.go:133
msgid "systemUsers"
#: pkg/handler/banner.go:93
msgid "comment"
msgstr ""
#. i18n.T
#: pkg/handler/pagination.go:133
msgid "comment"
#: pkg/handler/banner.go:94
msgid "Page: %d, Count: %d, Total Page: %d, Total Count: %d"
msgstr ""
#. i18n.T
#: pkg/handler/pagination.go:152
msgid "Page: %d, Count: %d, Total Page: %d, Total Count: %d"
#: pkg/handler/banner.go:95
msgid "No Assets"
msgstr ""
#. i18n.T
#: pkg/handler/pagination.go:179
#: pkg/handler/banner.go:96
msgid ""
"\n"
"Tips: Enter the asset ID and log directly into the asset.\n"
"Tips: Enter the asset ID and directly login the asset.\n"
msgstr ""
#. i18n.T
#: pkg/handler/pagination.go:180
#: pkg/handler/banner.go:97
msgid ""
"\n"
"Page up: P/p\tPage down: Enter|N/n\tBACK: b.\n"
msgstr ""
#. i18n.T
#: pkg/handler/session.go:267
msgid "No Assets"
msgstr ""
#. i18n.T
#: pkg/handler/session.go:289
#: pkg/handler/banner.go:98
msgid "Node: [ ID.Name(Asset amount) ]"
msgstr ""
#. i18n.T
#: pkg/handler/session.go:290
#: pkg/handler/banner.go:99
msgid "Tips: Enter g+NodeID to display the host under the node, such as g1"
msgstr ""
#. i18n.T
#: pkg/handler/session.go:304
#: pkg/handler/banner.go:100
msgid "Refresh done"
msgstr ""
#. i18n.T
#: pkg/proxy/parser.go:124
#: pkg/proxy/parser.go:131
msgid "Command `%s` is forbidden"
msgstr ""
#. i18n.T
#: pkg/proxy/proxy.go:152
#: pkg/proxy/proxy.go:143
msgid "Reuse SSH connections (%s@%s) [Number of connections: %d]"
msgstr ""
#. i18n.T
#: pkg/proxy/proxy.go:161
msgid "Connecting to %s@%s %.1f"
msgstr ""
#. i18n.T
#: pkg/proxy/proxy.go:171
#: pkg/proxy/proxy.go:180
msgid "System user <%s> and asset <%s> protocol are inconsistent."
msgstr ""
#. i18n.T
#: pkg/proxy/proxy.go:177
#: pkg/proxy/proxy.go:186
msgid ""
"Terminal only support protocol ssh/telnet, please use web terminal to access"
msgstr ""
#. i18n.T
#: pkg/proxy/sessmanager.go:63
#: pkg/proxy/sessmanager.go:67
msgid "Connect with api server failed"
msgstr ""
#. i18n.T
#: pkg/proxy/switch.go:142
#: pkg/proxy/switch.go:159
msgid "Connect idle more than %d minutes, disconnect"
msgstr ""
#. i18n.T
#: pkg/proxy/switch.go:148
#: pkg/proxy/switch.go:166
msgid "Terminated by administrator"
msgstr ""
......@@ -8,116 +8,107 @@ msgstr ""
"X-Generator: xgotext\n"
#. i18n.T
#: pkg/auth/server.go:17
msgid "Please enter 6 digits."
msgstr "请输入六位数字"
#. i18n.T
#: pkg/auth/server.go:18
msgid "[MFA auth]: "
msgstr "[MFA认证]"
#. i18n.T
#: pkg/handler/banner.go:32
#: pkg/handler/banner.go:31
msgid "\t%d) Enter {{.GreenBoldColor}}%s{{.ColorEnd}} to %s.%s"
msgstr "\t%d) 输入 {{.GreenBoldColor}}%s{{.ColorEnd}} 进行%s.%s"
#. i18n.T
#: pkg/handler/banner.go:47
#: pkg/handler/banner.go:46
msgid "Welcome to use Jumpserver open source fortress system"
msgstr "欢迎使用Jumpserver开源堡垒机系统"
#. i18n.T
#: pkg/handler/banner.go:49
#: pkg/handler/banner.go:48
msgid "directly login"
msgstr "直接登陆"
#. i18n.T
#: pkg/handler/banner.go:50
#: pkg/handler/banner.go:49
msgid "part IP, Hostname, Comment"
msgstr "部分IP、主机名、备注"
#. i18n.T
#: pkg/handler/banner.go:50
#: pkg/handler/banner.go:49
msgid "to search login if unique"
msgstr "进行搜索登录(如果唯一)"
#. i18n.T
#: pkg/handler/banner.go:51
#: pkg/handler/banner.go:50
msgid "/ + IP, Hostname, Comment"
msgstr "/ + IP, 主机名 or 备注"
#. i18n.T
#: pkg/handler/banner.go:51
#: pkg/handler/banner.go:50
msgid "to search, such as: /192.168"
msgstr "搜索, 如: /192.168"
#. i18n.T
#: pkg/handler/banner.go:52
#: pkg/handler/banner.go:51
msgid "display the host you have permission"
msgstr "显示您有权限的主机"
#. i18n.T
#: pkg/handler/banner.go:53
#: pkg/handler/banner.go:52
msgid "display the node that you have permission"
msgstr "显示您有权限的节点"
#. i18n.T
#: pkg/handler/banner.go:54
#: pkg/handler/banner.go:53
msgid "refresh your assets and nodes"
msgstr "刷新最新的机器和节点信息"
#. i18n.T
#: pkg/handler/banner.go:55
#: pkg/handler/banner.go:54
msgid "print help"
msgstr "显示帮助"
#. i18n.T
#: pkg/handler/banner.go:56
#: pkg/handler/banner.go:55
msgid "exit"
msgstr "退出"
#. i18n.T
#: pkg/handler/pagination.go:133
#: pkg/handler/banner.go:90
msgid "ID"
msgstr "ID"
#. i18n.T
#: pkg/handler/pagination.go:133
#: pkg/handler/banner.go:91
msgid "hostname"
msgstr "主机名"
#. i18n.T
#: pkg/handler/pagination.go:133
#: pkg/handler/banner.go:92
msgid "IP"
msgstr "IP"
#. i18n.T
#: pkg/handler/pagination.go:133
msgid "systemUsers"
msgstr "登录用户"
#. i18n.T
#: pkg/handler/pagination.go:133
#: pkg/handler/banner.go:93
msgid "comment"
msgstr "备注"
#. i18n.T
#: pkg/handler/pagination.go:152
#: pkg/handler/banner.go:94
msgid "Page: %d, Count: %d, Total Page: %d, Total Count: %d"
msgstr "页码: %d, 每页行数: %d, 总页数: %d, 总数量: %d"
#. i18n.T
#: pkg/handler/pagination.go:179
#: pkg/handler/banner.go:95
msgid "No Assets"
msgstr "没有资产"
#. i18n.T
#: pkg/handler/banner.go:96
#, fuzzy
msgid ""
"\n"
"Tips: Enter the asset ID and log directly into the asset.\n"
"Tips: Enter the asset ID and directly login the asset.\n"
msgstr ""
"\n"
"提示: 输入资产ID,直接登录资产.\n"
#. i18n.T
#: pkg/handler/pagination.go:180
#: pkg/handler/banner.go:97
msgid ""
"\n"
"Page up: P/p\tPage down: Enter|N/n\tBACK: b.\n"
......@@ -126,57 +117,57 @@ msgstr ""
"上一页: P/p 下一页: Enter|N/n 返回: B/b\n"
#. i18n.T
#: pkg/handler/session.go:267
msgid "No Assets"
msgstr "没有资产"
#. i18n.T
#: pkg/handler/session.go:289
#: pkg/handler/banner.go:98
msgid "Node: [ ID.Name(Asset amount) ]"
msgstr "节点: [ ID.名称(资产数量) ]"
#. i18n.T
#: pkg/handler/session.go:290
#: pkg/handler/banner.go:99
msgid "Tips: Enter g+NodeID to display the host under the node, such as g1"
msgstr "提示: 输入 g+节点ID 显示节点下主机. 如: g1"
#. i18n.T
#: pkg/handler/session.go:304
#: pkg/handler/banner.go:100
msgid "Refresh done"
msgstr "刷新完成"
#. i18n.T
#: pkg/proxy/parser.go:124
#: pkg/proxy/parser.go:131
msgid "Command `%s` is forbidden"
msgstr "命令 `%s` 是被禁止的 ..."
#. i18n.T
#: pkg/proxy/proxy.go:152
#: pkg/proxy/proxy.go:143
msgid "Reuse SSH connections (%s@%s) [Number of connections: %d]"
msgstr "复用SSH连接(%s@%s)[连接数量: %d]"
#. i18n.T
#: pkg/proxy/proxy.go:161
msgid "Connecting to %s@%s %.1f"
msgstr "开始连接到 %s@%s %.1f"
#. i18n.T
#: pkg/proxy/proxy.go:171
#: pkg/proxy/proxy.go:180
msgid "System user <%s> and asset <%s> protocol are inconsistent."
msgstr "系统用户<%s>和资产<%s>协议不一致"
#. i18n.T
#: pkg/proxy/proxy.go:177
#: pkg/proxy/proxy.go:186
msgid ""
"Terminal only support protocol ssh/telnet, please use web terminal to access"
msgstr "终端仅支持ssh/telnet协议,请使用web终端登录"
#. i18n.T
#: pkg/proxy/sessmanager.go:63
#: pkg/proxy/sessmanager.go:67
msgid "Connect with api server failed"
msgstr "连接API服务失败"
#. i18n.T
#: pkg/proxy/switch.go:142
#: pkg/proxy/switch.go:159
msgid "Connect idle more than %d minutes, disconnect"
msgstr "空闲时间超过%d分钟,断开连接"
#. i18n.T
#: pkg/proxy/switch.go:148
#: pkg/proxy/switch.go:166
msgid "Terminated by administrator"
msgstr "管理员中断连接"
......@@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"io"
"sync"
"text/template"
"github.com/jumpserver/koko/pkg/config"
......@@ -79,3 +80,25 @@ func displayBanner(sess io.ReadWriter, user string) {
utils.IgnoreErrWriteString(sess, v.Text())
}
}
var i18nMap map[string]string
var i18nOnce sync.Once
func getI18nFromMap(name string) string {
i18nOnce.Do(func() {
i18nMap = map[string]string{
"ID": i18n.T("ID"),
"Hostname": i18n.T("hostname"),
"IP": i18n.T("IP"),
"Comment": i18n.T("comment"),
"AssetTableCaption": i18n.T("Page: %d, Count: %d, Total Page: %d, Total Count: %d"),
"NoAssets": i18n.T("No Assets"),
"LoginTip": i18n.T("\nTips: Enter the asset ID and directly login the asset.\n"),
"PageActionTip": i18n.T("\nPage up: P/p Page down: Enter|N/n BACK: b.\n"),
"NodeHeaderTip": i18n.T("Node: [ ID.Name(Asset amount) ]"),
"NodeEndTip": i18n.T("Tips: Enter g+NodeID to display the host under the node, such as g1"),
"RefreshDone": i18n.T("Refresh done"),
}
})
return i18nMap[name]
}
......@@ -8,7 +8,6 @@ import (
"github.com/jumpserver/koko/pkg/common"
"github.com/jumpserver/koko/pkg/config"
"github.com/jumpserver/koko/pkg/i18n"
"github.com/jumpserver/koko/pkg/model"
"github.com/jumpserver/koko/pkg/service"
"github.com/jumpserver/koko/pkg/utils"
......@@ -132,7 +131,8 @@ func (p *AssetPagination) Start() []model.Asset {
}
func (p *AssetPagination) displayPageAssets() {
Labels := []string{i18n.T("ID"), i18n.T("hostname"), i18n.T("IP"), i18n.T("comment")}
Labels := []string{getI18nFromMap("ID"), getI18nFromMap("Hostname"),
getI18nFromMap("IP"), getI18nFromMap("Comment")}
fields := []string{"ID", "hostname", "IP", "comment"}
data := make([]map[string]string, len(p.currentData))
for i, j := range p.currentData {
......@@ -152,7 +152,7 @@ func (p *AssetPagination) displayPageAssets() {
data[i] = row
}
w, _ := p.term.GetSize()
caption := fmt.Sprintf(i18n.T("Page: %d, Count: %d, Total Page: %d, Total Count: %d"),
caption := fmt.Sprintf(getI18nFromMap("AssetTableCaption"),
p.page.CurrentPage(), p.page.PageSize(), p.page.TotalPage(), p.page.TotalCount(),
)
caption = utils.WrapperString(caption, utils.Green)
......@@ -269,12 +269,12 @@ func (p *UserAssetPagination) Start() []model.Asset {
func (p *UserAssetPagination) displayPageAssets() {
if len(p.Data.Data) == 0 {
_, _ = p.term.Write([]byte(i18n.T("No Assets")))
_, _ = p.term.Write([]byte("\n\r"))
_, _ = p.term.Write([]byte(getI18nFromMap("NoAssets")+"\n\r"))
return
}
Labels := []string{i18n.T("ID"), i18n.T("hostname"), i18n.T("IP"), i18n.T("comment")}
Labels := []string{getI18nFromMap("ID"), getI18nFromMap("Hostname"),
getI18nFromMap("IP"), getI18nFromMap("Comment")}
fields := []string{"ID", "hostname", "IP", "comment"}
p.currentData = model.AssetList(p.Data.Data).SortBy(config.GetConf().AssetListSortBy)
data := make([]map[string]string, len(p.currentData))
......@@ -324,9 +324,9 @@ func (p *UserAssetPagination) displayPageAssets() {
currentPage = (currentOffset / pageSize) + 1
}
}
caption := fmt.Sprintf(i18n.T("Page: %d, Count: %d, Total Page: %d, Total Count: %d"),
currentPage, pageSize, totalPage, totalCount,
)
caption := fmt.Sprintf(getI18nFromMap("AssetTableCaption"),
currentPage, pageSize, totalPage, totalCount)
caption = utils.WrapperString(caption, utils.Green)
table := common.WrapperTable{
Fields: fields,
......@@ -387,11 +387,6 @@ func getPageSize(term *utils.Terminal) int {
}
func displayAssetPaginationTipsInfo(w io.Writer) {
tips := []string{
i18n.T("\nTips: Enter the asset ID and log directly into the asset.\n"),
i18n.T("\nPage up: P/p Page down: Enter|N/n BACK: b.\n"),
}
for _, tip := range tips {
_, _ = w.Write([]byte(tip))
}
utils.IgnoreErrWriteString(w, getI18nFromMap("LoginTip"))
utils.IgnoreErrWriteString(w, getI18nFromMap("PageActionTip"))
}
......@@ -13,7 +13,6 @@ import (
"github.com/jumpserver/koko/pkg/cctx"
"github.com/jumpserver/koko/pkg/config"
"github.com/jumpserver/koko/pkg/i18n"
"github.com/jumpserver/koko/pkg/logger"
"github.com/jumpserver/koko/pkg/model"
"github.com/jumpserver/koko/pkg/proxy"
......@@ -239,7 +238,7 @@ func (h *interactiveHandler) chooseSystemUser(systemUsers []model.SystemUser) mo
func (h *interactiveHandler) displayAssets(assets model.AssetList) {
if len(assets) == 0 {
_, _ = io.WriteString(h.term, i18n.T("No Assets")+"\n\r")
_, _ = io.WriteString(h.term, getI18nFromMap("NoAssets")+"\n\r")
} else {
sortedAssets := assets.SortBy(config.GetConf().AssetListSortBy)
pag := NewAssetPagination(h.term, sortedAssets)
......@@ -259,12 +258,9 @@ func (h *interactiveHandler) displayAssets(assets model.AssetList) {
func (h *interactiveHandler) displayNodes(nodes []model.Node) {
tree := ConstructAssetNodeTree(nodes)
tipHeaderMsg := i18n.T("Node: [ ID.Name(Asset amount) ]")
tipEndMsg := i18n.T("Tips: Enter g+NodeID to display the host under the node, such as g1")
_, err := io.WriteString(h.term, "\n\r"+tipHeaderMsg)
_, err := io.WriteString(h.term, "\n\r"+getI18nFromMap("NodeHeaderTip"))
_, err = io.WriteString(h.term, tree.String())
_, err = io.WriteString(h.term, tipEndMsg+"\n\r")
_, err = io.WriteString(h.term, getI18nFromMap("NodeEndTip")+"\n\r")
if err != nil {
logger.Info("displayAssetNodes err:", err)
}
......@@ -277,7 +273,7 @@ func (h *interactiveHandler) refreshAssetsAndNodesData() {
h.loadAllAssets()
}
h.loadUserNodes("2")
_, err := io.WriteString(h.term, i18n.T("Refresh done")+"\n\r")
_, err := io.WriteString(h.term, getI18nFromMap("RefreshDone")+"\n\r")
if err != nil {
logger.Error("refresh Assets Nodes err:", err)
}
......
......@@ -140,11 +140,10 @@ func (p *ProxyServer) getServerConn() (srvConn srvconn.ServerConnection, err err
}()
go p.sendConnectingMsg(done, config.GetConf().SSHTimeout*time.Second)
} else {
reuseMsg := fmt.Sprintf("You reuse SSH client (%s@%s) [current reuse count: %d]",
reuseMsg := fmt.Sprintf(i18n.T("Reuse SSH connections (%s@%s) [Number of connections: %d]"),
p.SystemUser.Username, p.Asset.Hostname, p.cacheSSHClient.RefCount())
utils.IgnoreErrWriteString(p.UserConn, utils.WrapperString("Please notice:\r\n", utils.Green))
utils.IgnoreErrWriteString(p.UserConn, utils.WrapperString(reuseMsg+"\r\n", utils.Green))
utils.IgnoreErrWriteString(p.UserConn, reuseMsg+"\r\n")
logger.Infof("Request %s: Reuse connection for SSH. SSH client %p current ref: %d", p.UserConn.ID(),
p.cacheSSHClient, p.cacheSSHClient.RefCount())
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment