Skip to content

Commit

Permalink
commands,lfs*: remove most newlines from messages
Browse files Browse the repository at this point in the history
In general, we can make the translation task somewhat
easier for translators, and less prone to error, if we
remove non-language-specific newlines from the text strings
to be translated.

To do this we can in some cases simply drop newlines (e.g.,
in panic messages), or break multi-line text strings into
several separate messages where that makes sense.  For the
most part we simply append the necessary trailing or
intermediate newlines using the formatting tools available,
especially those provided in the commands/commands.go file.

Note that those tools (i.e., Print(), Exit(), etc.) always
append a newline, but some messages are intended to have
two final newlines, such as those from the "git lfs status"
command.

We also add a note to translators regarding some specific
spacing required by a message output by the "git lfs dedup"
command.
  • Loading branch information
chrisd8088 committed Jan 30, 2022
1 parent 2830d39 commit b5a9eae
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 18 deletions.
4 changes: 2 additions & 2 deletions commands/command_clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ func clean(gf *lfs.GitFilter, to io.Writer, from io.Reader, fileName string, fil

if stat, _ := os.Stat(mediafile); stat != nil {
if stat.Size() != cleaned.Size && len(cleaned.Pointer.Extensions) == 0 {
Exit(tr.Tr.Get("Files don't match:\n%s\n%s", mediafile, tmpfile))
Exit("%s\n%s\n%s", tr.Tr.Get("Files don't match:"), mediafile, tmpfile)
}
Debug("%s exists", mediafile)
} else {
if err := os.Rename(tmpfile, mediafile); err != nil {
Panic(err, tr.Tr.Get("Unable to move %s to %s\n", tmpfile, mediafile))
Panic(err, tr.Tr.Get("Unable to move %s to %s", tmpfile, mediafile))
}

Debug(tr.Tr.Get("Writing %s", mediafile))
Expand Down
2 changes: 1 addition & 1 deletion commands/command_clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ speeds to 'git lfs clone'.
// We pass all args to git clone
err := git.CloneWithoutFilters(cloneFlags, args)
if err != nil {
Exit(tr.Tr.Get("Error(s) during clone:\n%v", err))
Exit("%s\n%v", tr.Tr.Get("Error(s) during clone:"), err)
}

// now execute pull (need to be inside dir)
Expand Down
3 changes: 3 additions & 0 deletions commands/command_dedup.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ func dedupCommand(cmd *cobra.Command, args []string) {
}

if success, err := dedup(p); err != nil {
// TRANSLATORS: Leading spaces should be included on
// the second line so the format specifier aligns with
// with the first format specifier on the first line.
Error(tr.Tr.Get("Skipped: %s (Size: %d)\n %s", p.Name, p.Size, err))
} else if !success {
Error(tr.Tr.Get("Skipped: %s (Size: %d)", p.Name, p.Size))
Expand Down
3 changes: 2 additions & 1 deletion commands/command_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ var (

func installCommand(cmd *cobra.Command, args []string) {
if err := cmdInstallOptions().Install(); err != nil {
Print(tr.Tr.Get("warning: %s\nRun `git lfs install --force` to reset Git configuration.", err.Error()))
Print(tr.Tr.Get("warning: %s", err.Error()))
Print(tr.Tr.Get("Run `git lfs install --force` to reset Git configuration."))
os.Exit(2)
}

Expand Down
2 changes: 1 addition & 1 deletion commands/command_post_checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func postCheckoutRevChange(client *locking.Client, pre, post string) {
files, err := git.GetFilesChanged(pre, post)

if err != nil {
LoggedError(err, tr.Tr.Get("Warning: post-checkout rev diff %v:%v failed: %v\nFalling back on full scan.", pre, post, err))
LoggedError(err, "%s\n%s", tr.Tr.Get("Warning: post-checkout rev diff %v:%v failed: %v", pre, post, err), tr.Tr.Get("Falling back on full scan."))
postCheckoutFileChange(client)
}
tracerx.Printf("post-checkout: checking write flags on %v", files)
Expand Down
8 changes: 5 additions & 3 deletions commands/command_prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func pruneCheckVerified(prunableObjects []string, reachableObjects, verifiedObje
// deleted but that's incorrect; bad state has occurred somehow, might need
// push --all to resolve
if problems.Len() > 0 {
Exit(tr.Tr.Get("These objects to be pruned are missing on remote:\n%v", problems.String()))
Exit("%s\n%v", tr.Tr.Get("These objects to be pruned are missing on remote:"), problems.String())
}
}

Expand Down Expand Up @@ -313,15 +313,17 @@ func pruneDeleteFiles(prunableObjects []string, logger *tasklog.Logger) {
for _, oid := range prunableObjects {
mediaFile, err := cfg.Filesystem().ObjectPath(oid)
if err != nil {
problems.WriteString(tr.Tr.Get("Unable to find media path for %v: %v\n", oid, err))
problems.WriteString(tr.Tr.Get("Unable to find media path for %v: %v", oid, err))
problems.WriteRune('\n')
continue
}
if mediaFile == os.DevNull {
continue
}
err = os.Remove(mediaFile)
if err != nil {
problems.WriteString(tr.Tr.Get("Failed to remove file %v: %v\n", mediaFile, err))
problems.WriteString(tr.Tr.Get("Failed to remove file %v: %v", mediaFile, err))
problems.WriteRune('\n')
continue
}
deletedFiles++
Expand Down
6 changes: 3 additions & 3 deletions commands/command_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func statusCommand(cmd *cobra.Command, args []string) {

wd = tools.ResolveSymlinks(wd)

Print(tr.Tr.Get("\nObjects to be committed:\n"))
Print("\n%s\n", tr.Tr.Get("Objects to be committed:"))
for _, entry := range staged {
// Find a path from the current working directory to the
// absolute path of each side of the entry.
Expand All @@ -72,7 +72,7 @@ func statusCommand(cmd *cobra.Command, args []string) {
}
}

Print(tr.Tr.Get("\nObjects not staged for commit:\n"))
Print("\n%s\n", tr.Tr.Get("Objects not staged for commit:"))
for _, entry := range unstaged {
src := relativize(wd, filepath.Join(repo, entry.SrcName))

Expand Down Expand Up @@ -243,7 +243,7 @@ func statusScanRefRange(ref *git.Ref) {
})
defer gitscanner.Close()

Print(tr.Tr.Get("Objects to be pushed to %s:\n", remoteRef.Name))
Print("%s\n", tr.Tr.Get("Objects to be pushed to %s:", remoteRef.Name))
if err := gitscanner.ScanRefRange(ref.Sha, remoteRef.Sha, nil); err != nil {
Panic(err, tr.Tr.Get("Could not scan for Git LFS objects"))
}
Expand Down
5 changes: 4 additions & 1 deletion commands/command_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ func updateCommand(cmd *cobra.Command, args []string) {
} else {
if err := installHooks(updateForce); err != nil {
Error(err.Error())
Exit(tr.Tr.Get("To resolve this, either:\n 1: run `git lfs update --manual` for instructions on how to merge hooks.\n 2: run `git lfs update --force` to overwrite your hook."))
Exit("%s\n 1: %s\n 2: %s",
tr.Tr.Get("To resolve this, either:"),
tr.Tr.Get("run `git lfs update --manual` for instructions on how to merge hooks."),
tr.Tr.Get("run `git lfs update --force` to overwrite your hook."))
} else {
Print(tr.Tr.Get("Updated Git hooks."))
}
Expand Down
2 changes: 1 addition & 1 deletion commands/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (c *singleCheckout) RunToPath(p *lfs.WrappedPointer, path string) error {

func (c *singleCheckout) Close() {
if err := c.gitIndexer.Close(); err != nil {
LoggedError(err, tr.Tr.Get("Error updating the Git index:\n%s", c.gitIndexer.Output()))
LoggedError(err, "%s\n%s", tr.Tr.Get("Error updating the Git index:"), c.gitIndexer.Output())
}
}

Expand Down
2 changes: 1 addition & 1 deletion commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Simply type ` + root.Name() + ` help [path to command] for full details.`,
cmd, _, e = c.Root().Find([]string{"help"})
}
if cmd == nil || e != nil {
c.Print(tr.Tr.Get("Unknown help topic %#q\n", args))
c.Println(tr.Tr.Get("Unknown help topic %#q", args))
c.Root().Usage()
} else {
c.HelpFunc()(cmd, args)
Expand Down
4 changes: 2 additions & 2 deletions config/git_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func readGitConfig(configs ...*git.ConfigurationSource) (gf *GitFetcher, extensi

if origKey, ok := uniqKeys[key]; ok {
if ShowConfigWarnings && len(vals[key]) > 0 && vals[key][len(vals[key])-1] != val && strings.HasPrefix(key, gitConfigWarningPrefix) {
fmt.Fprint(os.Stderr, tr.Tr.Get("warning: These git config values clash:\n"))
fmt.Fprintln(os.Stderr, tr.Tr.Get("warning: These git config values clash:"))
fmt.Fprintf(os.Stderr, " git config %q = %q\n", origKey, vals[key])
fmt.Fprintf(os.Stderr, " git config %q = %q\n", pieces[0], val)
}
Expand Down Expand Up @@ -102,7 +102,7 @@ func readGitConfig(configs ...*git.ConfigurationSource) (gf *GitFetcher, extensi
}

if len(ignored) > 0 {
fmt.Fprintf(os.Stderr, tr.Tr.Get("warning: These unsafe lfsconfig keys were ignored:\n\n"))
fmt.Fprint(os.Stderr, tr.Tr.Get("warning: These unsafe lfsconfig keys were ignored:"), "\n\n")
for _, key := range ignored {
fmt.Fprintf(os.Stderr, " %s\n", key)
}
Expand Down
2 changes: 1 addition & 1 deletion lfs/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,5 @@ func (h *Hook) matchesCurrent() (bool, error) {
}
}

return false, errors.New(tr.Tr.Get("Hook already exists: %s\n\n%s\n", string(h.Type), tools.Indent(contents)))
return false, errors.New(fmt.Sprintf("%s\n\n%s\n", tr.Tr.Get("Hook already exists: %s", string(h.Type)), tools.Indent(contents)))
}
2 changes: 1 addition & 1 deletion lfsapi/endpoint_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func storeAlias(aliases map[string]string, key string, values []string, suffix s
for _, value := range values {
url := key[len(aliasPrefix) : len(key)-len(suffix)]
if v, ok := aliases[value]; ok && v != url {
fmt.Fprintf(os.Stderr, tr.Tr.Get("warning: Multiple 'url.*.%s' keys with the same alias: %q\n", suffix, value))
fmt.Fprintln(os.Stderr, tr.Tr.Get("warning: Multiple 'url.*.%s' keys with the same alias: %q", suffix, value))
}
aliases[value] = url
}
Expand Down

0 comments on commit b5a9eae

Please sign in to comment.