Skip to content

Commit

Permalink
simplification de la traduction de l'aide
Browse files Browse the repository at this point in the history
  • Loading branch information
kpym committed Oct 27, 2020
1 parent a28a7a0 commit 72e7bd2
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions translate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"io"
"strings"
)
Expand All @@ -10,19 +9,19 @@ type trad struct {
from, to string
}

var traductions = []trad{
{" (default [])", ""},
{"default", "par défaut"},
{" strings ", " "},
{" string ", " "},
{" uints ", " "},
{" int ", " "},
{"bad flag syntax:", "mauvaise syntaxe du paramètre :"},
{"unknown flag:", "paramètre inconnu :"},
{"unknown shorthand flag:", "paramètre court inconnu :"},
{"flag needs an argument:", "Le paramètre nécessite un argument :"},
{" in ", " dans "},
}
var traductions = strings.NewReplacer(
" (default [])", "",
"default", "par défaut",
" strings ", " ",
" string ", " ",
" uints ", " ",
" int ", " ",
"bad flag syntax:", "mauvaise syntaxe du paramètre :",
"unknown flag:", "paramètre inconnu :",
"unknown shorthand flag:", "paramètre court inconnu :",
"flag needs an argument:", "paramètre sans argument :",
" in ", " dans ",
)

// FrenchTranslator est un io.Writer qui traduit quelques phrases d'angalsi en français et
// renvoie le résultat au w
Expand All @@ -32,12 +31,5 @@ type FrenchTranslator struct {

// Write traduit le message p et renvoie la traduction à fw.w
func (fw FrenchTranslator) Write(p []byte) (n int, err error) {
out := string(p)

for _, tr := range traductions {
out = strings.ReplaceAll(out, tr.from, tr.to)
}

fmt.Fprintf(fw.w, out)
return len(p), nil
return traductions.WriteString(fw.w, string(p))
}

0 comments on commit 72e7bd2

Please sign in to comment.