Skip to content

Expand i18n coverage to all relevant strings #1370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions arduino/builder/compilation_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ func LoadCompilationDatabase(file *paths.Path) (*CompilationDatabase, error) {
// see https://clang.llvm.org/docs/JSONCompilationDatabase.html
func (db *CompilationDatabase) SaveToFile() {
if jsonContents, err := json.MarshalIndent(db.Contents, "", " "); err != nil {
fmt.Printf("Error serializing compilation database: %s", err)
fmt.Printf(tr("Error serializing compilation database: %s"), err)
return
} else if err := db.File.WriteFile(jsonContents); err != nil {
fmt.Printf("Error writing compilation database: %s", err)
fmt.Printf(tr("Error writing compilation database: %s"), err)
}
}

Expand All @@ -75,7 +75,7 @@ func dirForCommand(command *exec.Cmd) string {
}
dir, err := os.Getwd()
if err != nil {
fmt.Printf("Error getting current directory for compilation database: %s", err)
fmt.Printf(tr("Error getting current directory for compilation database: %s"), err)
return ""
}
return dir
Expand Down
26 changes: 15 additions & 11 deletions arduino/builder/sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ import (
"strings"

"github.com/arduino/arduino-cli/arduino/sketch"
"github.com/arduino/arduino-cli/i18n"
"github.com/arduino/go-paths-helper"

"github.com/pkg/errors"
)

var includesArduinoH = regexp.MustCompile(`(?m)^\s*#\s*include\s*[<\"]Arduino\.h[>\"]`)
var (
includesArduinoH = regexp.MustCompile(`(?m)^\s*#\s*include\s*[<\"]Arduino\.h[>\"]`)
tr = i18n.Tr
)

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

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

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

return nil
Expand All @@ -62,14 +66,14 @@ func SketchMergeSources(sk *sketch.Sketch, overrides map[string]string) (int, st
getSource := func(f *paths.Path) (string, error) {
path, err := sk.FullPath.RelTo(f)
if err != nil {
return "", errors.Wrap(err, "unable to compute relative path to the sketch for the item")
return "", errors.Wrap(err, tr("unable to compute relative path to the sketch for the item"))
}
if override, ok := overrides[path.String()]; ok {
return override, nil
}
data, err := f.ReadFile()
if err != nil {
return "", fmt.Errorf("reading file %s: %s", f, err)
return "", fmt.Errorf(tr("reading file %[1]s: %[2]s"), f, err)
}
return string(data), nil
}
Expand Down Expand Up @@ -104,19 +108,19 @@ func SketchMergeSources(sk *sketch.Sketch, overrides map[string]string) (int, st
// specified destination directory.
func SketchCopyAdditionalFiles(sketch *sketch.Sketch, destPath *paths.Path, overrides map[string]string) error {
if err := destPath.MkdirAll(); err != nil {
return errors.Wrap(err, "unable to create a folder to save the sketch files")
return errors.Wrap(err, tr("unable to create a folder to save the sketch files"))
}

for _, file := range sketch.AdditionalFiles {
relpath, err := sketch.FullPath.RelTo(file)
if err != nil {
return errors.Wrap(err, "unable to compute relative path to the sketch for the item")
return errors.Wrap(err, tr("unable to compute relative path to the sketch for the item"))
}

targetPath := destPath.JoinPath(relpath)
// create the directory containing the target
if err = targetPath.Parent().MkdirAll(); err != nil {
return errors.Wrap(err, "unable to create the folder containing the item")
return errors.Wrap(err, tr("unable to create the folder containing the item"))
}

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

err = writeIfDifferent(sourceBytes, targetPath)
if err != nil {
return errors.Wrap(err, "unable to write to destination file")
return errors.Wrap(err, tr("unable to write to destination file"))
}
}

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

// Overwrite if contents are different
Expand Down
8 changes: 4 additions & 4 deletions arduino/cores/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (b *Board) GetBuildProperties(userConfigs *properties.Map) (*properties.Map
if haveUserValue {
userConfigs.Remove(option)
if !optionMenu.ContainsKey(userValue) {
return nil, fmt.Errorf("invalid value '%s' for option '%s'", userValue, option)
return nil, fmt.Errorf(tr("invalid value '%[1]s' for option '%[2]s'"), userValue, option)
}
} else {
// apply default
Expand All @@ -120,9 +120,9 @@ func (b *Board) GetBuildProperties(userConfigs *properties.Map) (*properties.Map
// Check for residual invalid options...
for _, invalidOption := range userConfigs.Keys() {
if invalidOption == "" {
return nil, fmt.Errorf("invalid empty option found")
return nil, fmt.Errorf(tr("invalid empty option found"))
}
return nil, fmt.Errorf("invalid option '%s'", invalidOption)
return nil, fmt.Errorf(tr("invalid option '%s'"), invalidOption)
}

return buildProperties, nil
Expand All @@ -136,7 +136,7 @@ func (b *Board) GetBuildProperties(userConfigs *properties.Map) (*properties.Map
func (b *Board) GeneratePropertiesForConfiguration(config string) (*properties.Map, error) {
fqbn, err := ParseFQBN(b.String() + ":" + config)
if err != nil {
return nil, fmt.Errorf("parsing fqbn: %s", err)
return nil, fmt.Errorf(tr("parsing fqbn: %s"), err)
}
return b.GetBuildProperties(fqbn.Configs)
}
Expand Down
3 changes: 3 additions & 0 deletions arduino/cores/cores.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"

"github.com/arduino/arduino-cli/arduino/resources"
"github.com/arduino/arduino-cli/i18n"
paths "github.com/arduino/go-paths-helper"
properties "github.com/arduino/go-properties-orderedmap"
semver "go.bug.st/relaxed-semver"
Expand Down Expand Up @@ -75,6 +76,8 @@ type BoardManifestID struct {
USB string `json:"-"`
}

var tr = i18n.Tr

// HasUsbID returns true if the BoardManifes contains the specified USB id as
// identification for this board. usbID should be in the format "0000:0000"
func (bm *BoardManifest) HasUsbID(vid, pid string) bool {
Expand Down
6 changes: 3 additions & 3 deletions arduino/cores/fqbn.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ func ParseFQBN(fqbnIn string) (*FQBN, error) {
Configs: properties.NewMap(),
}
if fqbn.BoardID == "" {
return nil, fmt.Errorf("invalid fqbn: empty board identifier")
return nil, fmt.Errorf(tr("invalid fqbn: empty board identifier"))
}
if len(fqbnParts) > 3 {
for _, pair := range strings.Split(fqbnParts[3], ",") {
parts := strings.SplitN(pair, "=", 2)
if len(parts) != 2 {
return nil, fmt.Errorf("invalid fqbn config: %s", pair)
return nil, fmt.Errorf(tr("invalid fqbn config: %s"), pair)
}
k := strings.TrimSpace(parts[0])
v := strings.TrimSpace(parts[1])
if k == "" {
return nil, fmt.Errorf("invalid fqbn config: %s", pair)
return nil, fmt.Errorf(tr("invalid fqbn config: %s"), pair)
}
fqbn.Configs.Set(k, v)
}
Expand Down
5 changes: 4 additions & 1 deletion arduino/cores/packageindex/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/resources"
"github.com/arduino/arduino-cli/arduino/security"
"github.com/arduino/arduino-cli/i18n"
"github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
semver "go.bug.st/relaxed-semver"
Expand Down Expand Up @@ -107,6 +108,8 @@ type indexHelp struct {
Online string `json:"online,omitempty"`
}

var tr = i18n.Tr

// MergeIntoPackages converts the Index data into a cores.Packages and merge them
// with the existing contents of the cores.Packages passed as parameter.
func (index Index) MergeIntoPackages(outPackages cores.Packages) {
Expand Down Expand Up @@ -233,7 +236,7 @@ func (inPlatformRelease indexPlatformRelease) extractPlatformIn(outPackage *core

size, err := inPlatformRelease.Size.Int64()
if err != nil {
return fmt.Errorf("invalid platform archive size: %s", err)
return fmt.Errorf(tr("invalid platform archive size: %s"), err)
}
outPlatformRelease := outPlatform.GetOrCreateRelease(inPlatformRelease.Version)
outPlatformRelease.IsTrusted = trusted
Expand Down
14 changes: 7 additions & 7 deletions arduino/cores/packagemanager/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,37 @@ func (pm *PackageManager) FindPlatformRelease(ref *PlatformReference) *cores.Pla
func (pm *PackageManager) FindPlatformReleaseDependencies(item *PlatformReference) (*cores.PlatformRelease, []*cores.ToolRelease, error) {
targetPackage, exists := pm.Packages[item.Package]
if !exists {
return nil, nil, fmt.Errorf("package %s not found", item.Package)
return nil, nil, fmt.Errorf(tr("package %s not found"), item.Package)
}
platform, exists := targetPackage.Platforms[item.PlatformArchitecture]
if !exists {
return nil, nil, fmt.Errorf("platform %s not found in package %s", item.PlatformArchitecture, targetPackage.String())
return nil, nil, fmt.Errorf(tr("platform %[1]s not found in package %[2]s"), item.PlatformArchitecture, targetPackage.String())
}

var release *cores.PlatformRelease
if item.PlatformVersion != nil {
release = platform.FindReleaseWithVersion(item.PlatformVersion)
if release == nil {
return nil, nil, fmt.Errorf("required version %s not found for platform %s", item.PlatformVersion, platform.String())
return nil, nil, fmt.Errorf(tr("required version %[1]s not found for platform %[2]s"), item.PlatformVersion, platform.String())
}
} else {
release = platform.GetLatestRelease()
if release == nil {
return nil, nil, fmt.Errorf("platform %s has no available releases", platform.String())
return nil, nil, fmt.Errorf(tr("platform %s has no available releases"), platform.String())
}
}

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

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

return release, append(toolDeps, discoveryDependencies...), nil
Expand All @@ -111,7 +111,7 @@ func (pm *PackageManager) FindPlatformReleaseDependencies(item *PlatformReferenc
func (pm *PackageManager) DownloadToolRelease(tool *cores.ToolRelease, config *downloader.Config) (*downloader.Downloader, error) {
resource := tool.GetCompatibleFlavour()
if resource == nil {
return nil, fmt.Errorf("tool not available for your OS")
return nil, fmt.Errorf(tr("tool not available for your OS"))
}
return resource.Download(pm.DownloadDir, config)
}
Expand Down
20 changes: 10 additions & 10 deletions arduino/cores/packagemanager/install_uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ func (pm *PackageManager) InstallPlatform(platformRelease *cores.PlatformRelease
platformRelease.Platform.Architecture,
platformRelease.Version.String())
if err := platformRelease.Resource.Install(pm.DownloadDir, pm.TempDir, destDir); err != nil {
return errors.Errorf("installing platform %s: %s", platformRelease, err)
return errors.Errorf(tr("installing platform %[1]s: %[2]s"), platformRelease, err)
}
if d, err := destDir.Abs(); err == nil {
platformRelease.InstallDir = d
} else {
return err
}
if err := pm.cacheInstalledJSON(platformRelease); err != nil {
return errors.Errorf("creating installed.json in %s: %s", platformRelease.InstallDir, err)
return errors.Errorf(tr("creating installed.json in %[1]s: %[2]s"), platformRelease.InstallDir, err)
}
return nil
}
Expand All @@ -62,7 +62,7 @@ func (pm *PackageManager) cacheInstalledJSON(platformRelease *cores.PlatformRele
// specified platformRelease.
func (pm *PackageManager) RunPostInstallScript(platformRelease *cores.PlatformRelease) error {
if !platformRelease.IsInstalled() {
return errors.New("platform not installed")
return errors.New(tr("platform not installed"))
}
postInstallFilename := "post_install.sh"
if runtime.GOOS == "windows" {
Expand Down Expand Up @@ -105,16 +105,16 @@ func (pm *PackageManager) IsManagedPlatformRelease(platformRelease *cores.Platfo
// UninstallPlatform remove a PlatformRelease.
func (pm *PackageManager) UninstallPlatform(platformRelease *cores.PlatformRelease) error {
if platformRelease.InstallDir == nil {
return fmt.Errorf("platform not installed")
return fmt.Errorf(tr("platform not installed"))
}

// Safety measure
if !pm.IsManagedPlatformRelease(platformRelease) {
return fmt.Errorf("%s is not managed by package manager", platformRelease)
return fmt.Errorf(tr("%s is not managed by package manager"), platformRelease)
}

if err := platformRelease.InstallDir.RemoveAll(); err != nil {
return fmt.Errorf("removing platform files: %s", err)
return fmt.Errorf(tr("removing platform files: %s"), err)
}
platformRelease.InstallDir = nil
return nil
Expand All @@ -124,7 +124,7 @@ func (pm *PackageManager) UninstallPlatform(platformRelease *cores.PlatformRelea
func (pm *PackageManager) InstallTool(toolRelease *cores.ToolRelease) error {
toolResource := toolRelease.GetCompatibleFlavour()
if toolResource == nil {
return fmt.Errorf("no compatible version of %s tools found for the current os", toolRelease.Tool.Name)
return fmt.Errorf(tr("no compatible version of %s tools found for the current os"), toolRelease.Tool.Name)
}
destDir := pm.PackagesDir.Join(
toolRelease.Tool.Package.Name,
Expand Down Expand Up @@ -157,16 +157,16 @@ func (pm *PackageManager) IsManagedToolRelease(toolRelease *cores.ToolRelease) b
// UninstallTool remove a ToolRelease.
func (pm *PackageManager) UninstallTool(toolRelease *cores.ToolRelease) error {
if toolRelease.InstallDir == nil {
return fmt.Errorf("tool not installed")
return fmt.Errorf(tr("tool not installed"))
}

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

if err := toolRelease.InstallDir.RemoveAll(); err != nil {
return fmt.Errorf("removing tool files: %s", err)
return fmt.Errorf(tr("removing tool files: %s"), err)
}
toolRelease.InstallDir = nil
return nil
Expand Down
Loading