Skip to content

Commit e31a717

Browse files
Expand i18n coverage to all relevant strings (#1370)
* Bring Go code formatting into compliance * Expand i18n coverage to all relevant strings This provides internationalization of the strings of the Arduino CLI code base. It will now be possible to completely translate the primary Arduino CLI user interface. We decided that the log messages would be excluded from the internationalization scope for now. The reason is that the addition of these strings would significantly increase the workload on the community translators, while generally being of less visibility and/or importance to the users. Even though on an individual basis there are surely specific log messages of higher importance than specific non-log strings that were internationalized, the log/non-log dichotomy provided an objective criterion for determining which strings were in scope for this initial effort. Perhaps we will expand the i18n coverage at some time in the future after there has been good progress on the initial translation effort. Some techniques were employed to facilitate translation: - Code references were moved out of strings in cases where a translator might mistake them for prose and translate them. - Indices were added to printf verbs when multiple were present in a string. This allows the translator to easily insert them at the appropriate location in the sentence structure without being required to understand the Go printf syntax and without being restricted to their relative order in the English language source string. Co-authored-by: Silvano Cerza <[email protected]>
1 parent 92a4c3a commit e31a717

File tree

143 files changed

+4376
-1026
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+4376
-1026
lines changed

arduino/builder/compilation_database.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ func LoadCompilationDatabase(file *paths.Path) (*CompilationDatabase, error) {
6060
// see https://clang.llvm.org/docs/JSONCompilationDatabase.html
6161
func (db *CompilationDatabase) SaveToFile() {
6262
if jsonContents, err := json.MarshalIndent(db.Contents, "", " "); err != nil {
63-
fmt.Printf("Error serializing compilation database: %s", err)
63+
fmt.Printf(tr("Error serializing compilation database: %s"), err)
6464
return
6565
} else if err := db.File.WriteFile(jsonContents); err != nil {
66-
fmt.Printf("Error writing compilation database: %s", err)
66+
fmt.Printf(tr("Error writing compilation database: %s"), err)
6767
}
6868
}
6969

@@ -75,7 +75,7 @@ func dirForCommand(command *exec.Cmd) string {
7575
}
7676
dir, err := os.Getwd()
7777
if err != nil {
78-
fmt.Printf("Error getting current directory for compilation database: %s", err)
78+
fmt.Printf(tr("Error getting current directory for compilation database: %s"), err)
7979
return ""
8080
}
8181
return dir

arduino/builder/sketch.go

+15-11
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ import (
2222
"strings"
2323

2424
"github.com/arduino/arduino-cli/arduino/sketch"
25+
"github.com/arduino/arduino-cli/i18n"
2526
"github.com/arduino/go-paths-helper"
2627

2728
"github.com/pkg/errors"
2829
)
2930

30-
var includesArduinoH = regexp.MustCompile(`(?m)^\s*#\s*include\s*[<\"]Arduino\.h[>\"]`)
31+
var (
32+
includesArduinoH = regexp.MustCompile(`(?m)^\s*#\s*include\s*[<\"]Arduino\.h[>\"]`)
33+
tr = i18n.Tr
34+
)
3135

3236
// QuoteCppString returns the given string as a quoted string for use with the C
3337
// preprocessor. This adds double quotes around it and escapes any
@@ -42,13 +46,13 @@ func QuoteCppString(str string) string {
4246
func SketchSaveItemCpp(path *paths.Path, contents []byte, destPath *paths.Path) error {
4347
sketchName := path.Base()
4448
if err := destPath.MkdirAll(); err != nil {
45-
return errors.Wrap(err, "unable to create a folder to save the sketch")
49+
return errors.Wrap(err, tr("unable to create a folder to save the sketch"))
4650
}
4751

4852
destFile := destPath.Join(fmt.Sprintf("%s.cpp", sketchName))
4953

5054
if err := destFile.WriteFile(contents); err != nil {
51-
return errors.Wrap(err, "unable to save the sketch on disk")
55+
return errors.Wrap(err, tr("unable to save the sketch on disk"))
5256
}
5357

5458
return nil
@@ -62,14 +66,14 @@ func SketchMergeSources(sk *sketch.Sketch, overrides map[string]string) (int, st
6266
getSource := func(f *paths.Path) (string, error) {
6367
path, err := sk.FullPath.RelTo(f)
6468
if err != nil {
65-
return "", errors.Wrap(err, "unable to compute relative path to the sketch for the item")
69+
return "", errors.Wrap(err, tr("unable to compute relative path to the sketch for the item"))
6670
}
6771
if override, ok := overrides[path.String()]; ok {
6872
return override, nil
6973
}
7074
data, err := f.ReadFile()
7175
if err != nil {
72-
return "", fmt.Errorf("reading file %s: %s", f, err)
76+
return "", fmt.Errorf(tr("reading file %[1]s: %[2]s"), f, err)
7377
}
7478
return string(data), nil
7579
}
@@ -104,19 +108,19 @@ func SketchMergeSources(sk *sketch.Sketch, overrides map[string]string) (int, st
104108
// specified destination directory.
105109
func SketchCopyAdditionalFiles(sketch *sketch.Sketch, destPath *paths.Path, overrides map[string]string) error {
106110
if err := destPath.MkdirAll(); err != nil {
107-
return errors.Wrap(err, "unable to create a folder to save the sketch files")
111+
return errors.Wrap(err, tr("unable to create a folder to save the sketch files"))
108112
}
109113

110114
for _, file := range sketch.AdditionalFiles {
111115
relpath, err := sketch.FullPath.RelTo(file)
112116
if err != nil {
113-
return errors.Wrap(err, "unable to compute relative path to the sketch for the item")
117+
return errors.Wrap(err, tr("unable to compute relative path to the sketch for the item"))
114118
}
115119

116120
targetPath := destPath.JoinPath(relpath)
117121
// create the directory containing the target
118122
if err = targetPath.Parent().MkdirAll(); err != nil {
119-
return errors.Wrap(err, "unable to create the folder containing the item")
123+
return errors.Wrap(err, tr("unable to create the folder containing the item"))
120124
}
121125

122126
var sourceBytes []byte
@@ -127,7 +131,7 @@ func SketchCopyAdditionalFiles(sketch *sketch.Sketch, destPath *paths.Path, over
127131
// read the source file
128132
s, err := file.ReadFile()
129133
if err != nil {
130-
return errors.Wrap(err, "unable to read contents of the source item")
134+
return errors.Wrap(err, tr("unable to read contents of the source item"))
131135
}
132136
sourceBytes = s
133137
}
@@ -137,7 +141,7 @@ func SketchCopyAdditionalFiles(sketch *sketch.Sketch, destPath *paths.Path, over
137141

138142
err = writeIfDifferent(sourceBytes, targetPath)
139143
if err != nil {
140-
return errors.Wrap(err, "unable to write to destination file")
144+
return errors.Wrap(err, tr("unable to write to destination file"))
141145
}
142146
}
143147

@@ -154,7 +158,7 @@ func writeIfDifferent(source []byte, destPath *paths.Path) error {
154158
// Read the destination file if it exists
155159
existingBytes, err := destPath.ReadFile()
156160
if err != nil {
157-
return errors.Wrap(err, "unable to read contents of the destination item")
161+
return errors.Wrap(err, tr("unable to read contents of the destination item"))
158162
}
159163

160164
// Overwrite if contents are different

arduino/cores/board.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (b *Board) GetBuildProperties(userConfigs *properties.Map) (*properties.Map
106106
if haveUserValue {
107107
userConfigs.Remove(option)
108108
if !optionMenu.ContainsKey(userValue) {
109-
return nil, fmt.Errorf("invalid value '%s' for option '%s'", userValue, option)
109+
return nil, fmt.Errorf(tr("invalid value '%[1]s' for option '%[2]s'"), userValue, option)
110110
}
111111
} else {
112112
// apply default
@@ -120,9 +120,9 @@ func (b *Board) GetBuildProperties(userConfigs *properties.Map) (*properties.Map
120120
// Check for residual invalid options...
121121
for _, invalidOption := range userConfigs.Keys() {
122122
if invalidOption == "" {
123-
return nil, fmt.Errorf("invalid empty option found")
123+
return nil, fmt.Errorf(tr("invalid empty option found"))
124124
}
125-
return nil, fmt.Errorf("invalid option '%s'", invalidOption)
125+
return nil, fmt.Errorf(tr("invalid option '%s'"), invalidOption)
126126
}
127127

128128
return buildProperties, nil
@@ -136,7 +136,7 @@ func (b *Board) GetBuildProperties(userConfigs *properties.Map) (*properties.Map
136136
func (b *Board) GeneratePropertiesForConfiguration(config string) (*properties.Map, error) {
137137
fqbn, err := ParseFQBN(b.String() + ":" + config)
138138
if err != nil {
139-
return nil, fmt.Errorf("parsing fqbn: %s", err)
139+
return nil, fmt.Errorf(tr("parsing fqbn: %s"), err)
140140
}
141141
return b.GetBuildProperties(fqbn.Configs)
142142
}

arduino/cores/cores.go

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strings"
2323

2424
"github.com/arduino/arduino-cli/arduino/resources"
25+
"github.com/arduino/arduino-cli/i18n"
2526
paths "github.com/arduino/go-paths-helper"
2627
properties "github.com/arduino/go-properties-orderedmap"
2728
semver "go.bug.st/relaxed-semver"
@@ -75,6 +76,8 @@ type BoardManifestID struct {
7576
USB string `json:"-"`
7677
}
7778

79+
var tr = i18n.Tr
80+
7881
// HasUsbID returns true if the BoardManifes contains the specified USB id as
7982
// identification for this board. usbID should be in the format "0000:0000"
8083
func (bm *BoardManifest) HasUsbID(vid, pid string) bool {

arduino/cores/fqbn.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ func ParseFQBN(fqbnIn string) (*FQBN, error) {
4545
Configs: properties.NewMap(),
4646
}
4747
if fqbn.BoardID == "" {
48-
return nil, fmt.Errorf("invalid fqbn: empty board identifier")
48+
return nil, fmt.Errorf(tr("invalid fqbn: empty board identifier"))
4949
}
5050
if len(fqbnParts) > 3 {
5151
for _, pair := range strings.Split(fqbnParts[3], ",") {
5252
parts := strings.SplitN(pair, "=", 2)
5353
if len(parts) != 2 {
54-
return nil, fmt.Errorf("invalid fqbn config: %s", pair)
54+
return nil, fmt.Errorf(tr("invalid fqbn config: %s"), pair)
5555
}
5656
k := strings.TrimSpace(parts[0])
5757
v := strings.TrimSpace(parts[1])
5858
if k == "" {
59-
return nil, fmt.Errorf("invalid fqbn config: %s", pair)
59+
return nil, fmt.Errorf(tr("invalid fqbn config: %s"), pair)
6060
}
6161
fqbn.Configs.Set(k, v)
6262
}

arduino/cores/packageindex/index.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/arduino/arduino-cli/arduino/cores"
2323
"github.com/arduino/arduino-cli/arduino/resources"
2424
"github.com/arduino/arduino-cli/arduino/security"
25+
"github.com/arduino/arduino-cli/i18n"
2526
"github.com/arduino/go-paths-helper"
2627
"github.com/sirupsen/logrus"
2728
semver "go.bug.st/relaxed-semver"
@@ -107,6 +108,8 @@ type indexHelp struct {
107108
Online string `json:"online,omitempty"`
108109
}
109110

111+
var tr = i18n.Tr
112+
110113
// MergeIntoPackages converts the Index data into a cores.Packages and merge them
111114
// with the existing contents of the cores.Packages passed as parameter.
112115
func (index Index) MergeIntoPackages(outPackages cores.Packages) {
@@ -233,7 +236,7 @@ func (inPlatformRelease indexPlatformRelease) extractPlatformIn(outPackage *core
233236

234237
size, err := inPlatformRelease.Size.Int64()
235238
if err != nil {
236-
return fmt.Errorf("invalid platform archive size: %s", err)
239+
return fmt.Errorf(tr("invalid platform archive size: %s"), err)
237240
}
238241
outPlatformRelease := outPlatform.GetOrCreateRelease(inPlatformRelease.Version)
239242
outPlatformRelease.IsTrusted = trusted

arduino/cores/packagemanager/download.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -70,37 +70,37 @@ func (pm *PackageManager) FindPlatformRelease(ref *PlatformReference) *cores.Pla
7070
func (pm *PackageManager) FindPlatformReleaseDependencies(item *PlatformReference) (*cores.PlatformRelease, []*cores.ToolRelease, error) {
7171
targetPackage, exists := pm.Packages[item.Package]
7272
if !exists {
73-
return nil, nil, fmt.Errorf("package %s not found", item.Package)
73+
return nil, nil, fmt.Errorf(tr("package %s not found"), item.Package)
7474
}
7575
platform, exists := targetPackage.Platforms[item.PlatformArchitecture]
7676
if !exists {
77-
return nil, nil, fmt.Errorf("platform %s not found in package %s", item.PlatformArchitecture, targetPackage.String())
77+
return nil, nil, fmt.Errorf(tr("platform %[1]s not found in package %[2]s"), item.PlatformArchitecture, targetPackage.String())
7878
}
7979

8080
var release *cores.PlatformRelease
8181
if item.PlatformVersion != nil {
8282
release = platform.FindReleaseWithVersion(item.PlatformVersion)
8383
if release == nil {
84-
return nil, nil, fmt.Errorf("required version %s not found for platform %s", item.PlatformVersion, platform.String())
84+
return nil, nil, fmt.Errorf(tr("required version %[1]s not found for platform %[2]s"), item.PlatformVersion, platform.String())
8585
}
8686
} else {
8787
release = platform.GetLatestRelease()
8888
if release == nil {
89-
return nil, nil, fmt.Errorf("platform %s has no available releases", platform.String())
89+
return nil, nil, fmt.Errorf(tr("platform %s has no available releases"), platform.String())
9090
}
9191
}
9292

9393
// replaces "latest" with latest version too
9494
toolDeps, err := pm.Packages.GetPlatformReleaseToolDependencies(release)
9595
if err != nil {
96-
return nil, nil, fmt.Errorf("getting tool dependencies for platform %s: %s", release.String(), err)
96+
return nil, nil, fmt.Errorf(tr("getting tool dependencies for platform %[1]s: %[2]s"), release.String(), err)
9797
}
9898

9999
// discovery dependencies differ from normal tool since we always want to use the latest \
100100
// available version for the platform package
101101
discoveryDependencies, err := pm.Packages.GetPlatformReleaseDiscoveryDependencies(release)
102102
if err != nil {
103-
return nil, nil, fmt.Errorf("getting discovery dependencies for platform %s: %s", release.String(), err)
103+
return nil, nil, fmt.Errorf(tr("getting discovery dependencies for platform %[1]s: %[2]s"), release.String(), err)
104104
}
105105

106106
return release, append(toolDeps, discoveryDependencies...), nil
@@ -111,7 +111,7 @@ func (pm *PackageManager) FindPlatformReleaseDependencies(item *PlatformReferenc
111111
func (pm *PackageManager) DownloadToolRelease(tool *cores.ToolRelease, config *downloader.Config) (*downloader.Downloader, error) {
112112
resource := tool.GetCompatibleFlavour()
113113
if resource == nil {
114-
return nil, fmt.Errorf("tool not available for your OS")
114+
return nil, fmt.Errorf(tr("tool not available for your OS"))
115115
}
116116
return resource.Download(pm.DownloadDir, config)
117117
}

arduino/cores/packagemanager/install_uninstall.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ func (pm *PackageManager) InstallPlatform(platformRelease *cores.PlatformRelease
3434
platformRelease.Platform.Architecture,
3535
platformRelease.Version.String())
3636
if err := platformRelease.Resource.Install(pm.DownloadDir, pm.TempDir, destDir); err != nil {
37-
return errors.Errorf("installing platform %s: %s", platformRelease, err)
37+
return errors.Errorf(tr("installing platform %[1]s: %[2]s"), platformRelease, err)
3838
}
3939
if d, err := destDir.Abs(); err == nil {
4040
platformRelease.InstallDir = d
4141
} else {
4242
return err
4343
}
4444
if err := pm.cacheInstalledJSON(platformRelease); err != nil {
45-
return errors.Errorf("creating installed.json in %s: %s", platformRelease.InstallDir, err)
45+
return errors.Errorf(tr("creating installed.json in %[1]s: %[2]s"), platformRelease.InstallDir, err)
4646
}
4747
return nil
4848
}
@@ -62,7 +62,7 @@ func (pm *PackageManager) cacheInstalledJSON(platformRelease *cores.PlatformRele
6262
// specified platformRelease.
6363
func (pm *PackageManager) RunPostInstallScript(platformRelease *cores.PlatformRelease) error {
6464
if !platformRelease.IsInstalled() {
65-
return errors.New("platform not installed")
65+
return errors.New(tr("platform not installed"))
6666
}
6767
postInstallFilename := "post_install.sh"
6868
if runtime.GOOS == "windows" {
@@ -105,16 +105,16 @@ func (pm *PackageManager) IsManagedPlatformRelease(platformRelease *cores.Platfo
105105
// UninstallPlatform remove a PlatformRelease.
106106
func (pm *PackageManager) UninstallPlatform(platformRelease *cores.PlatformRelease) error {
107107
if platformRelease.InstallDir == nil {
108-
return fmt.Errorf("platform not installed")
108+
return fmt.Errorf(tr("platform not installed"))
109109
}
110110

111111
// Safety measure
112112
if !pm.IsManagedPlatformRelease(platformRelease) {
113-
return fmt.Errorf("%s is not managed by package manager", platformRelease)
113+
return fmt.Errorf(tr("%s is not managed by package manager"), platformRelease)
114114
}
115115

116116
if err := platformRelease.InstallDir.RemoveAll(); err != nil {
117-
return fmt.Errorf("removing platform files: %s", err)
117+
return fmt.Errorf(tr("removing platform files: %s"), err)
118118
}
119119
platformRelease.InstallDir = nil
120120
return nil
@@ -124,7 +124,7 @@ func (pm *PackageManager) UninstallPlatform(platformRelease *cores.PlatformRelea
124124
func (pm *PackageManager) InstallTool(toolRelease *cores.ToolRelease) error {
125125
toolResource := toolRelease.GetCompatibleFlavour()
126126
if toolResource == nil {
127-
return fmt.Errorf("no compatible version of %s tools found for the current os", toolRelease.Tool.Name)
127+
return fmt.Errorf(tr("no compatible version of %s tools found for the current os"), toolRelease.Tool.Name)
128128
}
129129
destDir := pm.PackagesDir.Join(
130130
toolRelease.Tool.Package.Name,
@@ -157,16 +157,16 @@ func (pm *PackageManager) IsManagedToolRelease(toolRelease *cores.ToolRelease) b
157157
// UninstallTool remove a ToolRelease.
158158
func (pm *PackageManager) UninstallTool(toolRelease *cores.ToolRelease) error {
159159
if toolRelease.InstallDir == nil {
160-
return fmt.Errorf("tool not installed")
160+
return fmt.Errorf(tr("tool not installed"))
161161
}
162162

163163
// Safety measure
164164
if !pm.IsManagedToolRelease(toolRelease) {
165-
return fmt.Errorf("tool %s is not managed by package manager", toolRelease)
165+
return fmt.Errorf(tr("tool %s is not managed by package manager"), toolRelease)
166166
}
167167

168168
if err := toolRelease.InstallDir.RemoveAll(); err != nil {
169-
return fmt.Errorf("removing tool files: %s", err)
169+
return fmt.Errorf(tr("removing tool files: %s"), err)
170170
}
171171
toolRelease.InstallDir = nil
172172
return nil

0 commit comments

Comments
 (0)