Skip to content

Commit 262fb67

Browse files
authored
Merge pull request #81 from toodofun/feat/i18n
Feat/i18n: Supports i18n, English and Chinese
2 parents 06273c6 + 52bb2c9 commit 262fb67

32 files changed

+740
-158
lines changed

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@ Usage:
2929
gvm [command]
3030

3131
Available Commands:
32-
completion Generate the autocompletion script for the specified shell
33-
current Show Current version of a language
34-
help Help about any command
35-
install Install a specific version of a language
36-
ls List installed versions of language
37-
ls-remote List remote versions of language
38-
ui Run in the terminal UI
39-
uninstall Uninstall a specific version of a language
40-
use Set default versions of language
32+
add Add a new addon to the GVM
33+
completion Generate the autocompletion script for the specified shell
34+
current Show Current version of a language
35+
help Help about any command
36+
install Install a specific version of a language
37+
ls List installed versions of language
38+
ls-remote List remote versions of language
39+
set-language Set default application language, supported languages: en, zh
40+
ui Run in the terminal UI
41+
uninstall Uninstall a specific version of a language
42+
use Set default versions of language
43+
version Print version information
4144

4245
Flags:
4346
-d, --debug debug mode

README_zh.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@ Usage:
2929
gvm [command]
3030

3131
Available Commands:
32-
completion Generate the autocompletion script for the specified shell
33-
current Show Current version of a language
34-
help Help about any command
35-
install Install a specific version of a language
36-
ls List installed versions of language
37-
ls-remote List remote versions of language
38-
ui Run in the terminal UI
39-
uninstall Uninstall a specific version of a language
40-
use Set default versions of language
32+
add Add a new addon to the GVM
33+
completion Generate the autocompletion script for the specified shell
34+
current Show Current version of a language
35+
help Help about any command
36+
install Install a specific version of a language
37+
ls List installed versions of language
38+
ls-remote List remote versions of language
39+
set-language Set default application language, supported languages: en, zh
40+
ui Run in the terminal UI
41+
uninstall Uninstall a specific version of a language
42+
use Set default versions of language
43+
version Print version information
4144

4245
Flags:
4346
-d, --debug debug mode

cmd/root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"io"
2020
"os"
2121

22+
"github.com/toodofun/gvm/i18n"
2223
"github.com/toodofun/gvm/internal/core"
2324
"github.com/toodofun/gvm/internal/log"
2425

@@ -46,6 +47,7 @@ func NewRootCmd() *cobra.Command {
4647
if debug {
4748
log.SetLevel(logrus.DebugLevel)
4849
}
50+
i18n.InitI18n(ctx)
4951
},
5052
}
5153

@@ -61,6 +63,7 @@ func NewRootCmd() *cobra.Command {
6163
NewUICmd(),
6264
NewCmdVersion(),
6365
NewAddAddonCmd(),
66+
NewSetLanguageCmd(),
6467
)
6568
cmd.PersistentFlags().BoolVarP(&debug, "debug", "d", false, "debug mode")
6669

cmd/root_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func TestNewRootCmd(t *testing.T) {
9494
"current",
9595
"ui",
9696
"version",
97+
"set-language",
9798
"add",
9899
}
99100

cmd/set_language.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2025 The Toodofun Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http:www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cmd
16+
17+
import (
18+
"errors"
19+
20+
"github.com/spf13/cobra"
21+
22+
"github.com/toodofun/gvm/i18n"
23+
)
24+
25+
func NewSetLanguageCmd() *cobra.Command {
26+
return &cobra.Command{
27+
Use: "set-language <language name>",
28+
Short: "Set default application language, supported languages: en, zh",
29+
Args: func(cmd *cobra.Command, args []string) error {
30+
if len(args) != 1 {
31+
return errors.New("this command needs exactly one argument: <language name>, eg: en")
32+
}
33+
return nil
34+
},
35+
RunE: func(cmd *cobra.Command, args []string) error {
36+
return i18n.SetLanguage(args[0])
37+
},
38+
}
39+
}

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/google/uuid v1.6.0
1010
github.com/hashicorp/go-version v1.7.0
1111
github.com/jedib0t/go-pretty/v6 v6.6.9
12+
github.com/nicksnyder/go-i18n/v2 v2.6.0
1213
github.com/patrickmn/go-cache v2.1.0+incompatible
1314
github.com/rivo/tview v0.42.0
1415
github.com/schollz/progressbar/v3 v3.18.0
@@ -17,6 +18,7 @@ require (
1718
github.com/spf13/pflag v1.0.10
1819
github.com/stretchr/testify v1.11.1
1920
golang.org/x/sys v0.37.0
21+
golang.org/x/text v0.28.0
2022
resty.dev/v3 v3.0.0-beta.3
2123
)
2224

@@ -34,6 +36,5 @@ require (
3436
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a // indirect
3537
golang.org/x/net v0.41.0 // indirect
3638
golang.org/x/term v0.34.0 // indirect
37-
golang.org/x/text v0.28.0 // indirect
3839
gopkg.in/yaml.v3 v3.0.1 // indirect
3940
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
2+
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
13
github.com/chengxilo/virtualterm v1.0.4 h1:Z6IpERbRVlfB8WkOmtbHiDbBANU7cimRIof7mk9/PwM=
24
github.com/chengxilo/virtualterm v1.0.4/go.mod h1:DyxxBZz/x1iqJjFxTFcr6/x+jSpqN0iwWCOK1q10rlY=
35
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
@@ -30,6 +32,8 @@ github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6T
3032
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
3133
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
3234
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
35+
github.com/nicksnyder/go-i18n/v2 v2.6.0 h1:C/m2NNWNiTB6SK4Ao8df5EWm3JETSTIGNXBpMJTxzxQ=
36+
github.com/nicksnyder/go-i18n/v2 v2.6.0/go.mod h1:88sRqr0C6OPyJn0/KRNaEz1uWorjxIKP7rUUcvycecE=
3337
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
3438
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
3539
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

i18n/active.en.yaml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Copyright 2025 The Toodofun Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http:www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
global:
15+
loading:
16+
title:
17+
other: "Loading..."
18+
loadingInfo:
19+
other: "Loading {{ .lang }} version info"
20+
confirm:
21+
confirm:
22+
other: "Confirm"
23+
cancel:
24+
other: "Cancel"
25+
alert:
26+
title:
27+
other: "ERROR"
28+
dismiss:
29+
other: "Dismiss"
30+
info:
31+
title:
32+
other: "INFO"
33+
dismiss:
34+
other: "Dismiss"
35+
header:
36+
hostname:
37+
other: "Hostname"
38+
system:
39+
other: "System"
40+
revision:
41+
other: "GVM Rev."
42+
username:
43+
other: "Username"
44+
logLevel:
45+
other: "LogLevel"
46+
newVersion:
47+
other: "New Ver."
48+
keyAction:
49+
colon:
50+
other: "Enter command mode"
51+
slash:
52+
other: "Enter filter mode"
53+
g:
54+
other: "Go to top"
55+
G:
56+
other: "Go to bottom"
57+
colonQ:
58+
other: "Quit"
59+
page:
60+
language:
61+
fullName:
62+
other: "Global Version Manager"
63+
table:
64+
header:
65+
language:
66+
other: "Language/Application"
67+
keyAction:
68+
enter:
69+
other: "Enter"
70+
languageVersion:
71+
fullName:
72+
other: "{{ .lang }} Versions"
73+
table:
74+
header:
75+
version:
76+
other: "Version"
77+
comment:
78+
other: "Comment"
79+
location:
80+
other: "Location"
81+
installed:
82+
other: "Installed"
83+
keyAction:
84+
i:
85+
other: "Filter by installed"
86+
enter:
87+
other: "Install or set as default"
88+
esc:
89+
other: "Go back"
90+
ctrlD:
91+
other: "Uninstall selected"
92+
installer:
93+
install:
94+
other: "Install"
95+
languages:
96+
startInstall:
97+
other: "Start install {{ .lang }} {{ .version }}"
98+
download:
99+
other: "Downloading"
100+
extracting:
101+
other: "Extracting package..."
102+
installComplete:
103+
other: "{{ .lang }} {{ .version }} installation complete! location: {{ .location }}"
104+
setDefaultInfo:
105+
other: "Are you sure you want to set {{ .version }} as the default?"
106+
alreadyDefault:
107+
other: "{{ .version }} is already the default version."
108+
setDefault:
109+
other: "Set {{ .version }} as default"
110+
setDefaultError:
111+
other: "Failed to set {{ .version }} as default: {{ .error }}"
112+
uninstallInfo:
113+
other: "Are you sure you want to uninstall {{ .version }}?"
114+
uninstall:
115+
other: "Uninstall {{ .version }}"
116+
uninstallError:
117+
other: "Uninstall {{ .version }} Failed: {{ .error }}"

0 commit comments

Comments
 (0)