Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

来自学弟90%的汉化 #46

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ if (!(";$Path;".ToLower() -like "*;$BinDir;*".ToLower())) {
$Env:Path += ";$BinDir"
}

Write-Output "ipgw was installed successfully to $TargetPath"
Write-Output "Run 'ipgw --help' to get started"
Write-Output "ipgw成功安装至 $TargetPath"
Write-Output "运行 'ipgw --help' 来获取帮助"
10 changes: 5 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

if ! command -v unzip >/dev/null; then
echo "Error: unzip is required to install ipgw." 1>&2
echo "Error: 安装ipgw需要unzip." 1>&2
exit 1
fi

Expand Down Expand Up @@ -37,15 +37,15 @@ unzip -d "$bin_dir" -o "$target_path.zip"
chmod +x "$target_path"
rm "$target_path.zip"

echo "ipgw was installed successfully to $target_path"
echo "ipgw成功安装至 $target_path"
if command -v ipgw >/dev/null; then
echo "Run 'ipgw --help' to get started"
echo "运行 'ipgw --help' 来获取帮助"
else
case $SHELL in
/bin/zsh) shell_profile=".zshrc" ;;
*) shell_profile=".bash_profile" ;;
esac
echo "Manually add the directory to your \$HOME/$shell_profile (or similar)"
echo "请手动添加目录至 \$HOME/$shell_profile (or similar)"
echo " export PATH=\"$bin_dir:\$PATH\""
echo "Run '$target_path --help' to get started"
echo "运行 'ipgw --help' 来获取帮助"
fi
40 changes: 20 additions & 20 deletions pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var (
App = &cli.App{
Name: "ipgw",
HelpName: "ipgw",
Copyright: "Home page:\thttps://github.com/neucn/ipgw\nFeedback:\thttps://github.com/neucn/ipgw/issues/new",
Copyright: "主页:\thttps://github.com/neucn/ipgw\nFeedback:\thttps://github.com/neucn/ipgw/issues/new",
Commands: []*cli.Command{
LoginCommand,
LogoutCommand,
Expand All @@ -27,7 +27,7 @@ var (
},
Action: func(ctx *cli.Context) error {
if ctx.NArg() != 0 {
console.InfoL("command not found\n")
console.InfoL("未找到命令\n")
cli.ShowAppHelpAndExit(ctx, 1)
return nil
}
Expand All @@ -43,7 +43,7 @@ var (
&cli.StringFlag{
Name: "config",
Aliases: []string{"f"},
Usage: "load configuration from specific `file`",
Usage: "载入配置文件",
},
},
OnUsageError: onUsageError,
Expand All @@ -58,13 +58,13 @@ func loginUseDefaultAccount(ctx *cli.Context) error {
}
account := store.Config.GetDefaultAccount()
if account == nil {
return errors.New("no account stored")
return errors.New("无储存账户")
}
console.InfoF("using account '%s'\n", account.Username)
console.InfoF("正在使用账户 '%s'\n", account.Username)
account.Secret = ctx.String("secret")

if err = login(handler.NewIpgwHandler(), account); err != nil {
return fmt.Errorf("login failed: \n\t%v", err)
return fmt.Errorf("登陆失败: \n\t%v", err)
}
return nil
}
Expand All @@ -83,13 +83,13 @@ func getAccountByContext(ctx *cli.Context) (account *model.Account, err error) {
} else if u := ctx.String("username"); u == "" {
// use stored default account
if account = store.Config.GetDefaultAccount(); account == nil {
return nil, errors.New("no stored account\n\tplease provide username and password")
return nil, errors.New("无储存账户\n\t请提供账号与密码")
}
console.InfoF("using account '%s'\n", account.Username)
console.InfoF("正在使用账户 '%s'\n", account.Username)
} else if p := ctx.String("password"); p == "" {
// use stored account
if account = store.Config.GetAccount(u); account == nil {
return nil, fmt.Errorf("account '%s' not found", u)
return nil, fmt.Errorf("账号 '%s' 未找到", u)
}
} else {
// use username and password
Expand Down Expand Up @@ -120,46 +120,46 @@ func onUsageError(ctx *cli.Context, err error, isSubcommand bool) error {
}

func init() {
cli.AppHelpTemplate = `USAGE:
cli.AppHelpTemplate = `用法:
{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}
{{if .Commands}}
COMMANDS:
命令:
{{range .Commands}}{{if not .HideHelp}} {{join .Names ", "}}{{ "\t"}}{{.Usage}}{{ "\n" }}{{end}}{{end}}{{end}}
OPTIONS:
选项:
{{range .VisibleFlags}}{{.}}
{{end}}
{{.Copyright}}
`
cli.CommandHelpTemplate = `{{.Usage}}

USAGE:
用法:
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}}

CATEGORY:
目录:
{{.Category}}{{end}}{{if .Description}}

DESCRIPTION:
描述:
{{.Description | nindent 3 | trim}}{{end}}{{if .VisibleFlags}}

OPTIONS:
选项:
{{range .VisibleFlags}}{{.}}
{{end}}{{end}}
`

cli.SubcommandHelpTemplate = `{{.Usage}}

USAGE:
用法:
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Description}}

DESCRIPTION:
描述:
{{.Description | nindent 3 | trim}}{{end}}

COMMANDS:{{range .VisibleCategories}}{{if .Name}}
命令:{{range .VisibleCategories}}{{if .Name}}
{{.Name}}:{{range .VisibleCommands}}
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}}
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}}

OPTIONS:
选项:
{{range .VisibleFlags}}{{.}}
{{end}}{{end}}
`
Expand Down
40 changes: 20 additions & 20 deletions pkg/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
var (
ConfigCommand = &cli.Command{
Name: "config",
Usage: "manage config",
Usage: "管理配置文件",
Subcommands: []*cli.Command{
{
Name: "account",
Usage: "manage accounts stored in config",
Usage: "管理配置文件中的账户",
Subcommands: []*cli.Command{
configAccountAddCommand,
configAccountDelCommand,
Expand All @@ -29,19 +29,19 @@ var (

configAccountAddCommand = &cli.Command{
Name: "add",
Usage: "add account into config",
Usage: "在配置文件中添加账户",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "username",
Aliases: []string{"u"},
Required: true,
Usage: "student number `id`",
Usage: "学号",
},
&cli.StringFlag{
Name: "password",
Aliases: []string{"p"},
Required: true,
Usage: "`password` for pass.neu.edu.cn",
Usage: "网关密码",
},
&cli.StringFlag{
Name: "secret",
Expand All @@ -50,7 +50,7 @@ var (
},
&cli.BoolFlag{
Name: "default",
Usage: "add the account as the default one",
Usage: "添加默认账户",
},
},
Action: func(ctx *cli.Context) error {
Expand All @@ -64,7 +64,7 @@ var (
username,
password,
ctx.String("secret")); err != nil {
return fmt.Errorf("fail to add account:\n\t%v", err)
return fmt.Errorf("无法添加账户:\n\t%v", err)
}

if ctx.Bool("default") {
Expand All @@ -73,21 +73,21 @@ var (
if err = store.Persist(); err != nil {
return err
}
console.InfoF("'%s' added successfully\n", username)
console.InfoF("'%s' 添加成功\n", username)
return nil
},
OnUsageError: onUsageError,
}

configAccountDelCommand = &cli.Command{
Name: "del",
Usage: "delete account from config",
Usage: "从配置文件中删除账户",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "username",
Aliases: []string{"u"},
Required: true,
Usage: "student number `id` to be deleted",
Usage: "要删除的账户学号",
},
},
Action: func(ctx *cli.Context) error {
Expand All @@ -98,32 +98,32 @@ var (
username := ctx.String("username")

if !store.Config.DelAccount(username) {
return fmt.Errorf("fail to delete account:\n\t'%s' not found", username)
return fmt.Errorf("无法删除账户:\n\t'%s' 账户没有找到", username)
}

if err = store.Persist(); err != nil {
return err
}
console.InfoF("'%s' deleted successfully\n", username)
console.InfoF("'%s' 删除成功\n", username)
return nil
},
OnUsageError: onUsageError,
}

configAccountSetCommand = &cli.Command{
Name: "set",
Usage: "edit account in config",
Usage: "编辑配置文件中的账户",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "username",
Aliases: []string{"u"},
Required: true,
Usage: "student number `id` to be edited",
Usage: "要编辑的账户学号",
},
&cli.StringFlag{
Name: "password",
Aliases: []string{"p"},
Usage: "new `password` for pass.neu.edu.cn",
Usage: "新的登陆网关密码",
},
&cli.StringFlag{
Name: "secret",
Expand All @@ -132,7 +132,7 @@ var (
},
&cli.BoolFlag{
Name: "default",
Usage: "set the account as the default one",
Usage: "设置为默认账户",
},
},
Action: func(ctx *cli.Context) error {
Expand All @@ -143,13 +143,13 @@ var (
username := ctx.String("username")
account := store.Config.GetAccount(username)
if account == nil {
return fmt.Errorf("fail to set account:\n\t'%s' not found", username)
return fmt.Errorf("无法设置账户:\n\t'%s' 账户没有找到", username)
}

password := ctx.String("password")
if password != "" {
if err = account.SetPassword(ctx.String("password"), []byte(ctx.String("secret"))); err != nil {
return fmt.Errorf("fail to set account:\n\t'%s' not found", username)
return fmt.Errorf("无法设置账户:\n\t'%s' 账户没有找到", username)
}
}

Expand All @@ -160,7 +160,7 @@ var (
if err = store.Persist(); err != nil {
return err
}
console.InfoF("'%s' edited successfully\n", username)
console.InfoF("'%s' 编辑成功\n", username)
return nil
},
OnUsageError: onUsageError,
Expand All @@ -169,7 +169,7 @@ var (
configAccountListCommand = &cli.Command{
Name: "list",
Aliases: []string{"ls"},
Usage: "list accounts in config",
Usage: "配置文件中的账户列表",
Action: func(ctx *cli.Context) error {
store, err := getStoreHandler(ctx)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import (
var (
InfoCommand = &cli.Command{
Name: "info",
Usage: "list account info",
Usage: "列出账户信息",
UseShortOptionHandling: true,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "username",
Aliases: []string{"u"},
Usage: "student number `id` (required only if not use the default or first stored account)",
Usage: "学号 (仅在使用非默认账户或者首次储存默认账户时使用)",
},
&cli.StringFlag{
Name: "password",
Aliases: []string{"p"},
Usage: "`password` for pass.neu.edu.cn (required only if account is not stored)",
Usage: "网关登陆密码 (仅在账户未储存时需要)",
},
&cli.StringFlag{
Name: "secret",
Expand All @@ -44,7 +44,7 @@ var (
}
h := handler.NewDashboardHandler()
if err := h.Login(account); err != nil {
return fmt.Errorf("fail to login:\n\t%v", err)
return fmt.Errorf("无法登陆:\n\t%v", err)
}
processInfoPrint(ctx, &infoPrinter{h})
return nil
Expand Down
10 changes: 5 additions & 5 deletions pkg/cmd/kick.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ var (
&cli.StringFlag{
Name: "username",
Aliases: []string{"u"},
Usage: "student number `id` (required only if not use the default or first stored account)",
Usage: "学号 (仅在使用非默认账户或者首次储存默认账户时使用)",
},
&cli.StringFlag{
Name: "password",
Aliases: []string{"p"},
Usage: "`password` for pass.neu.edu.cn (required only if account is not stored)",
Usage: "网关登陆密码 (仅在账户未储存时需要)",
},
&cli.StringFlag{
Name: "secret",
Expand All @@ -32,7 +32,7 @@ var (
Action: func(ctx *cli.Context) error {
sids := ctx.Args().Slice()
if len(sids) == 0 {
console.InfoL("no sid")
console.InfoL("无sid")
return nil
}
account, err := getAccountByContext(ctx)
Expand All @@ -50,9 +50,9 @@ var (
for _, sid := range sids {
result, err := h.Kick(sid)
if result {
console.InfoF("#%s: done\n", sid)
console.InfoF("#%s: 完成\n", sid)
} else {
console.InfoF("#%s: fail\n", sid)
console.InfoF("#%s: 失败\n", sid)
if err != nil {
console.InfoF("\t%v\n", err)
}
Expand Down
Loading