Skip to content

Commit

Permalink
Feat/zh cli (#204)
Browse files Browse the repository at this point in the history
* zh docs

* zh-cli but not help doc

* put back ai-removed comment

* image translations

* translated assets

* zh for documented clio

* replaceTranslations script

* ioutil lint

* update ffi

* translate market cmds

* Add debug for make gen

* add gotext to CI

* add lang to GA

* remove debug steps

* move translation txt

---------

Co-authored-by: LexLuthr <lexluthr@curiostorage.org>
  • Loading branch information
snadrus and LexLuthr authored Jan 13, 2025
1 parent 59c7a4f commit 1418afb
Show file tree
Hide file tree
Showing 39 changed files with 5,067 additions and 1,215 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ jobs:
- install-ubuntu-deps
- run: go install golang.org/x/tools/cmd/goimports
- run: go install github.com/hannahhoward/cbor-gen-for
- run: go install golang.org/x/text/cmd/gotext
- run: make deps gen
- run: git --no-pager diff && git --no-pager diff --quiet

Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ jobs:
run: go install github.com/hannahhoward/cbor-gen-for
shell: bash

- name: Install gotext
run: go install golang.org/x/text/cmd/gotext
shell: bash

- name: Install FFI
env:
GITHUB_TOKEN: ${{ github.token }}
Expand All @@ -319,6 +323,8 @@ jobs:
shell: bash

- name: Generate Code
env:
LANG: en-US
run: make gen
shell: bash

Expand Down
26 changes: 15 additions & 11 deletions cmd/curio/calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import (
"github.com/fatih/color"
"github.com/urfave/cli/v2"

"github.com/filecoin-project/curio/cmd/curio/internal/translations"
"github.com/filecoin-project/curio/tasks/sealsupra"
)

var calcCmd = &cli.Command{
Name: "calc",
Usage: "Math Utils",
Name: "calc",

Usage: translations.T("Math Utils"),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "actor",
Expand All @@ -24,12 +26,13 @@ var calcCmd = &cli.Command{
}

var calcBatchCpuCmd = &cli.Command{
Name: "batch-cpu",
Usage: "Analyze and display the layout of batch sealer threads",
Description: `Analyze and display the layout of batch sealer threads on your CPU.
Name: "batch-cpu",

Usage: translations.T("Analyze and display the layout of batch sealer threads"),
Description: translations.T(`Analyze and display the layout of batch sealer threads on your CPU.
It provides detailed information about CPU utilization for batch sealing operations, including core allocation, thread
distribution for different batch sizes.`,
distribution for different batch sizes.`),
Flags: []cli.Flag{
&cli.BoolFlag{Name: "dual-hashers", Value: true},
},
Expand Down Expand Up @@ -139,17 +142,18 @@ distribution for different batch sizes.`,
}

var calcSuprasealConfigCmd = &cli.Command{
Name: "supraseal-config",
Usage: "Generate a supra_seal configuration",
Description: `Generate a supra_seal configuration for a given batch size.
Name: "supraseal-config",

Usage: translations.T("Generate a supra_seal configuration"),
Description: translations.T(`Generate a supra_seal configuration for a given batch size.
This command outputs a configuration expected by SupraSeal. Main purpose of this command is for debugging and testing.
The config can be used directly with SupraSeal binaries to test it without involving Curio.`,
The config can be used directly with SupraSeal binaries to test it without involving Curio.`),
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "dual-hashers",
Value: true,
Usage: "Zen3 and later supports two sectors per thread, set to false for older CPUs",
Usage: translations.T("Zen3 and later supports two sectors per thread, set to false for older CPUs"),
},
&cli.IntFlag{
Name: "batch-size",
Expand Down
9 changes: 5 additions & 4 deletions cmd/curio/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/filecoin-project/go-jsonrpc/auth"

"github.com/filecoin-project/curio/cmd/curio/internal/translations"
"github.com/filecoin-project/curio/cmd/curio/rpc"
"github.com/filecoin-project/curio/deps"
"github.com/filecoin-project/curio/lib/reqcontext"
Expand All @@ -29,11 +30,11 @@ const providerEnvVar = "CURIO_API_INFO"

var cliCmd = &cli.Command{
Name: "cli",
Usage: "Execute cli commands",
Usage: translations.T("Execute cli commands"),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "machine",
Usage: "machine host:port (curio run --listen address)",
Usage: translations.T("machine host:port (curio run --listen address)"),
},
},
Before: func(cctx *cli.Context) error {
Expand Down Expand Up @@ -209,11 +210,11 @@ var cliCmd = &cli.Command{

var waitApiCmd = &cli.Command{
Name: "wait-api",
Usage: "Wait for Curio api to come online",
Usage: translations.T("Wait for Curio api to come online"),
Flags: []cli.Flag{
&cli.DurationFlag{
Name: "timeout",
Usage: "duration to wait till fail",
Usage: translations.T("duration to wait till fail"),
Value: time.Second * 30,
},
},
Expand Down
43 changes: 22 additions & 21 deletions cmd/curio/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import (
"github.com/urfave/cli/v2"
"golang.org/x/xerrors"

"github.com/filecoin-project/curio/cmd/curio/internal/translations"
"github.com/filecoin-project/curio/deps"
"github.com/filecoin-project/curio/deps/config"
"github.com/filecoin-project/curio/harmony/harmonydb"
)

var configCmd = &cli.Command{
Name: "config",
Usage: "Manage node config by layers. The layer 'base' will always be applied at Curio start-up.",
Usage: translations.T("Manage node config by layers. The layer 'base' will always be applied at Curio start-up."),
Subcommands: []*cli.Command{
configDefaultCmd,
configSetCmd,
Expand All @@ -38,11 +39,11 @@ var configCmd = &cli.Command{
var configDefaultCmd = &cli.Command{
Name: "default",
Aliases: []string{"defaults"},
Usage: "Print default node config",
Usage: translations.T("Print default node config"),
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "no-comment",
Usage: "don't comment default values",
Usage: translations.T("don't comment default values"),
},
},
Action: func(cctx *cli.Context) error {
Expand All @@ -60,12 +61,12 @@ var configDefaultCmd = &cli.Command{
var configSetCmd = &cli.Command{
Name: "set",
Aliases: []string{"add", "update", "create"},
Usage: "Set a config layer or the base by providing a filename or stdin.",
ArgsUsage: "a layer's file name",
Usage: translations.T("Set a config layer or the base by providing a filename or stdin."),
ArgsUsage: translations.T("a layer's file name"),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "title",
Usage: "title of the config layer (req'd for stdin)",
Usage: translations.T("title of the config layer (req'd for stdin)"),
},
},
Action: func(cctx *cli.Context) error {
Expand Down Expand Up @@ -124,8 +125,8 @@ func setConfig(db *harmonydb.DB, name, config string) error {
var configGetCmd = &cli.Command{
Name: "get",
Aliases: []string{"cat", "show"},
Usage: "Get a config layer by name. You may want to pipe the output to a file, or use 'less'",
ArgsUsage: "layer name",
Usage: translations.T("Get a config layer by name. You may want to pipe the output to a file, or use 'less'"),
ArgsUsage: translations.T("layer name"),
Action: func(cctx *cli.Context) error {
args := cctx.Args()
if args.Len() != 1 {
Expand Down Expand Up @@ -158,7 +159,7 @@ func getConfig(db *harmonydb.DB, layer string) (string, error) {
var configListCmd = &cli.Command{
Name: "list",
Aliases: []string{"ls"},
Usage: "List config layers present in the DB.",
Usage: translations.T("List config layers present in the DB."),
Flags: []cli.Flag{},
Action: func(cctx *cli.Context) error {
db, err := deps.MakeDB(cctx)
Expand All @@ -181,7 +182,7 @@ var configListCmd = &cli.Command{
var configRmCmd = &cli.Command{
Name: "remove",
Aliases: []string{"rm", "del", "delete"},
Usage: "Remove a named config layer.",
Usage: translations.T("Remove a named config layer."),
Flags: []cli.Flag{},
Action: func(cctx *cli.Context) error {
args := cctx.Args()
Expand All @@ -206,12 +207,12 @@ var configRmCmd = &cli.Command{
var configViewCmd = &cli.Command{
Name: "interpret",
Aliases: []string{"view", "stacked", "stack"},
Usage: "Interpret stacked config layers by this version of curio, with system-generated comments.",
ArgsUsage: "a list of layers to be interpreted as the final config",
Usage: translations.T("Interpret stacked config layers by this version of curio, with system-generated comments."),
ArgsUsage: translations.T("a list of layers to be interpreted as the final config"),
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "layers",
Usage: "comma or space separated list of layers to be interpreted (base is always applied)",
Usage: translations.T("comma or space separated list of layers to be interpreted (base is always applied)"),
Required: true,
},
},
Expand All @@ -236,32 +237,32 @@ var configViewCmd = &cli.Command{

var configEditCmd = &cli.Command{
Name: "edit",
Usage: "edit a config layer",
ArgsUsage: "[layer name]",
Usage: translations.T("edit a config layer"),
ArgsUsage: translations.T("[layer name]"),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "editor",
Usage: "editor to use",
Usage: translations.T("editor to use"),
Value: "vim",
EnvVars: []string{"EDITOR"},
},
&cli.StringFlag{
Name: "source",
Usage: "source config layer",
Usage: translations.T("source config layer"),
DefaultText: "<edited layer>",
},
&cli.BoolFlag{
Name: "allow-overwrite",
Usage: "allow overwrite of existing layer if source is a different layer",
Usage: translations.T("allow overwrite of existing layer if source is a different layer"),
},
&cli.BoolFlag{
Name: "no-source-diff",
Usage: "save the whole config into the layer, not just the diff",
Usage: translations.T("save the whole config into the layer, not just the diff"),
},
&cli.BoolFlag{
Name: "no-interpret-source",
Usage: "do not interpret source layer",
DefaultText: "true if --source is set",
Usage: translations.T("do not interpret source layer"),
DefaultText: translations.T("true if --source is set"),
},
},
Action: func(cctx *cli.Context) error {
Expand Down
5 changes: 3 additions & 2 deletions cmd/curio/config_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/urfave/cli/v2"
"golang.org/x/xerrors"

"github.com/filecoin-project/curio/cmd/curio/internal/translations"
"github.com/filecoin-project/curio/deps"

"github.com/filecoin-project/lotus/api"
Expand All @@ -15,8 +16,8 @@ import (

var configNewCmd = &cli.Command{
Name: "new-cluster",
Usage: "Create new configuration for a new cluster",
ArgsUsage: "[SP actor address...]",
Usage: translations.T("Create new configuration for a new cluster"),
ArgsUsage: translations.T("[SP actor address...]"),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "repo",
Expand Down
3 changes: 2 additions & 1 deletion cmd/curio/debug-ipni.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import (
"github.com/urfave/cli/v2"
"golang.org/x/xerrors"

"github.com/filecoin-project/curio/cmd/curio/internal/translations"
"github.com/filecoin-project/curio/market/ipni/chunker"
)

var testDebugIpniChunks = &cli.Command{
Name: "ipni-piece-chunks",
Usage: "generate ipni chunks from a file",
Usage: translations.T("generate ipni chunks from a file"),
Action: func(c *cli.Context) error {
ck := chunker.NewInitialChunker()

Expand Down
40 changes: 2 additions & 38 deletions cmd/curio/guidedsetup/guidedsetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/samber/lo"
"github.com/snadrus/must"
"github.com/urfave/cli/v2"
"golang.org/x/text/language"
"golang.org/x/text/message"

"github.com/filecoin-project/go-address"
Expand All @@ -37,6 +36,7 @@ import (

"github.com/filecoin-project/curio/api"
"github.com/filecoin-project/curio/build"
"github.com/filecoin-project/curio/cmd/curio/internal/translations"
_ "github.com/filecoin-project/curio/cmd/curio/internal/translations"
"github.com/filecoin-project/curio/deps"
"github.com/filecoin-project/curio/deps/config"
Expand Down Expand Up @@ -64,7 +64,7 @@ var GuidedsetupCmd = &cli.Command{
},
},
Action: func(cctx *cli.Context) (err error) {
T, say := SetupLanguage()
T, say := translations.SetupLanguage()
setupCtrlC(say)

// Run the migration steps
Expand Down Expand Up @@ -144,42 +144,6 @@ var (
Background(lipgloss.Color("#f8f9fa"))
)

func SetupLanguage() (func(key message.Reference, a ...interface{}) string, func(style lipgloss.Style, key message.Reference, a ...interface{})) {
langText := "en"
problem := false
if len(os.Getenv("LANG")) > 1 {
langText = os.Getenv("LANG")[:2]
} else {
problem = true
}

lang, err := language.Parse(langText)
if err != nil {
lang = language.English
problem = true
fmt.Println("Error parsing language")
}

langs := message.DefaultCatalog.Languages()
have := lo.SliceToMap(langs, func(t language.Tag) (string, bool) { return t.String(), true })
if _, ok := have[lang.String()]; !ok {
lang = language.English
problem = true
}
if problem {
_ = os.Setenv("LANG", "en-US") // for later users of this function
notice.Copy().AlignHorizontal(lipgloss.Right).
Render("$LANG=" + langText + " unsupported. Available: " + strings.Join(lo.Keys(have), ", "))
fmt.Println("Defaulting to English. Please reach out to the Curio team if you would like to have additional language support.")
}
return func(key message.Reference, a ...interface{}) string {
return message.NewPrinter(lang).Sprintf(key, a...)
}, func(sty lipgloss.Style, key message.Reference, a ...interface{}) {
msg := message.NewPrinter(lang).Sprintf(key, a...)
fmt.Println(sty.Render(msg))
}
}

func newOrMigrate(d *MigrationData) {
i, _, err := (&promptui.Select{
Label: d.T("I want to:"),
Expand Down
3 changes: 2 additions & 1 deletion cmd/curio/guidedsetup/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-statestore"

"github.com/filecoin-project/curio/cmd/curio/internal/translations"
"github.com/filecoin-project/curio/deps"
"github.com/filecoin-project/curio/deps/config"
"github.com/filecoin-project/curio/harmony/harmonydb"
Expand Down Expand Up @@ -69,7 +70,7 @@ func (storageMiner) APIInfoEnvVars() (primary string, fallbacks []string, deprec
}

func SaveConfigToLayerMigrateSectors(db *harmonydb.DB, minerRepoPath, chainApiInfo string, unmigSectorShouldFail func() bool) (minerAddress address.Address, err error) {
_, say := SetupLanguage()
_, say := translations.SetupLanguage()
ctx := context.Background()

r, err := repo.NewFS(minerRepoPath)
Expand Down
Loading

0 comments on commit 1418afb

Please sign in to comment.