From 547dc4ad2ce13bc064f34a6223d07e866b69eb7e Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 13 Dec 2021 18:36:54 +0000 Subject: [PATCH] commands/lock: make strings translatable Move the string for lockRemoteHelp variable into the actual help output. We cannot translate a global variable because at initialization time the locale string won't have been loaded and we won't be able to load the proper string. --- commands/command_lock.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/commands/command_lock.go b/commands/command_lock.go index f125f80a..ad6f80dd 100644 --- a/commands/command_lock.go +++ b/commands/command_lock.go @@ -11,6 +11,7 @@ import ( "github.com/git-lfs/git-lfs/v3/git" "github.com/git-lfs/git-lfs/v3/locking" "github.com/git-lfs/git-lfs/v3/tools" + "github.com/git-lfs/git-lfs/v3/tr" "github.com/spf13/cobra" ) @@ -41,7 +42,7 @@ func lockCommand(cmd *cobra.Command, args []string) { lock, err := lockClient.LockFile(path) if err != nil { - Error("Locking %s failed: %v", path, errors.Cause(err)) + Error(tr.Tr.Get("Locking %s failed: %v", path, errors.Cause(err))) success = false continue } @@ -52,7 +53,7 @@ func lockCommand(cmd *cobra.Command, args []string) { continue } - Print("Locked %s", path) + Print(tr.Tr.Get("Locked %s", path)) } if locksCmdFlags.JSON { @@ -97,14 +98,14 @@ func lockPath(file string) (string, error) { wd, err = tools.CanonicalizeSystemPath(wd) if err != nil { return "", errors.Wrapf(err, - "could not follow symlinks for %s", wd) + tr.Tr.Get("could not follow symlinks for %s", wd)) } var abs string if filepath.IsAbs(file) { abs, err = tools.CanonicalizeSystemPath(file) if err != nil { - return "", fmt.Errorf("lfs: unable to canonicalize path %q: %v", file, err) + return "", fmt.Errorf(tr.Tr.Get("lfs: unable to canonicalize path %q: %v", file, err)) } } else { abs = filepath.Join(wd, file) @@ -116,11 +117,11 @@ func lockPath(file string) (string, error) { path = filepath.ToSlash(path) if strings.HasPrefix(path, "../") { - return "", fmt.Errorf("lfs: unable to canonicalize path %q", path) + return "", fmt.Errorf(tr.Tr.Get("lfs: unable to canonicalize path %q", path)) } if stat, err := os.Stat(abs); err == nil && stat.IsDir() { - return path, fmt.Errorf("lfs: cannot lock directory: %s", file) + return path, fmt.Errorf(tr.Tr.Get("lfs: cannot lock directory: %s", file)) } return filepath.ToSlash(path), nil @@ -128,7 +129,7 @@ func lockPath(file string) (string, error) { func init() { RegisterCommand("lock", lockCommand, func(cmd *cobra.Command) { - cmd.Flags().StringVarP(&lockRemote, "remote", "r", "", lockRemoteHelp) + cmd.Flags().StringVarP(&lockRemote, "remote", "r", "", "specify which remote to use when interacting with locks") cmd.Flags().BoolVarP(&locksCmdFlags.JSON, "json", "", false, "print output in json") }) }