Skip to content

[skip changelog] Internationalize strings added for pluggable discovery support #1384

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 1 commit into from
Aug 10, 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
8 changes: 4 additions & 4 deletions arduino/cores/packagemanager/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,18 +645,18 @@ func (pm *PackageManager) loadDiscoveries(release *cores.PlatformRelease) []*sta
for _, id := range discoveryProperties.ExtractSubIndexLists("required") {
tool := pm.GetTool(id)
if tool == nil {
statuses = append(statuses, status.Newf(codes.FailedPrecondition, "discovery not found: %s", id))
statuses = append(statuses, status.Newf(codes.FailedPrecondition, tr("discovery not found: %s"), id))
continue
}
toolRelease := tool.GetLatestInstalled()
if toolRelease == nil {
statuses = append(statuses, status.Newf(codes.FailedPrecondition, "discovery not installed: %s", id))
statuses = append(statuses, status.Newf(codes.FailedPrecondition, tr("discovery not installed: %s"), id))
continue
}
discoveryPath := toolRelease.InstallDir.Join(tool.Name).String()
d, err := discovery.New(id, discoveryPath)
if err != nil {
statuses = append(statuses, status.Newf(codes.FailedPrecondition, "creating discovery: %s", err))
statuses = append(statuses, status.Newf(codes.FailedPrecondition, tr("creating discovery: %s"), err))
continue
}
pm.discoveryManager.Add(d)
Expand Down Expand Up @@ -684,7 +684,7 @@ func (pm *PackageManager) loadDiscoveries(release *cores.PlatformRelease) []*sta
for discoveryID, props := range discoveryIDs {
pattern, ok := props.GetOk("pattern")
if !ok {
statuses = append(statuses, status.Newf(codes.FailedPrecondition, "can't find pattern for discovery with id %s", discoveryID))
statuses = append(statuses, status.Newf(codes.FailedPrecondition, tr("can't find pattern for discovery with id %s"), discoveryID))
continue
}
configuration := release.Properties.Clone()
Expand Down
4 changes: 2 additions & 2 deletions arduino/cores/packagemanager/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func (pm *PackageManager) FindToolsRequiredFromPlatformRelease(platform *cores.P
pm.Log.WithField("tool", toolDep).Infof("Required tool")
tool := pm.FindToolDependency(toolDep)
if tool == nil {
return nil, fmt.Errorf("tool release not found: %s", toolDep)
return nil, fmt.Errorf(tr("tool release not found: %s"), toolDep)
}
requiredTools = append(requiredTools, tool)
delete(foundTools, tool.Tool.Name)
Expand All @@ -475,7 +475,7 @@ func (pm *PackageManager) FindToolsRequiredFromPlatformRelease(platform *cores.P
pm.Log.WithField("discovery", discoveryDep).Infof("Required discovery")
tool := pm.FindDiscoveryDependency(discoveryDep)
if tool == nil {
return nil, fmt.Errorf("discovery release not found: %s", discoveryDep)
return nil, fmt.Errorf(tr("discovery release not found: %s"), discoveryDep)
}
requiredTools = append(requiredTools, tool)
delete(foundTools, tool.Tool.Name)
Expand Down
22 changes: 11 additions & 11 deletions arduino/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ type discoveryMessage struct {
func (msg discoveryMessage) String() string {
s := fmt.Sprintf("type: %s", msg.EventType)
if msg.Message != "" {
s = fmt.Sprintf("%s, message: %s", s, msg.Message)
s = fmt.Sprintf(tr("%[1]s, message: %[2]s"), s, msg.Message)
}
if msg.ProtocolVersion != 0 {
s = fmt.Sprintf("%s, protocol version: %d", s, msg.ProtocolVersion)
s = fmt.Sprintf(tr("%[1]s, protocol version: %[2]d"), s, msg.ProtocolVersion)
}
if len(msg.Ports) > 0 {
s = fmt.Sprintf("%s, ports: %s", s, msg.Ports)
s = fmt.Sprintf(tr("%[1]s, ports: %[2]s"), s, msg.Ports)
}
if msg.Port != nil {
s = fmt.Sprintf("%s, port: %s", s, msg.Port)
s = fmt.Sprintf(tr("%[1]s, port: %[2]s"), s, msg.Port)
}
return s
}
Expand Down Expand Up @@ -225,7 +225,7 @@ func (disc *PluggableDiscovery) waitMessage(timeout time.Duration) (*discoveryMe
}
return msg, nil
case <-time.After(timeout):
return nil, fmt.Errorf("timeout waiting for message from %s", disc.id)
return nil, fmt.Errorf(tr("timeout waiting for message from %s"), disc.id)
}
}

Expand Down Expand Up @@ -294,7 +294,7 @@ func (disc *PluggableDiscovery) Run() (err error) {
return err
}
if msg, err := disc.waitMessage(time.Second * 10); err != nil {
return fmt.Errorf("calling HELLO: %w", err)
return fmt.Errorf(tr("calling %[1]s: %[2]w"), "HELLO", err)
} else if msg.EventType != "hello" {
return errors.Errorf(tr("communication out of sync, expected 'hello', received '%s'"), msg.EventType)
} else if msg.Message != "OK" || msg.Error {
Expand All @@ -315,7 +315,7 @@ func (disc *PluggableDiscovery) Start() error {
return err
}
if msg, err := disc.waitMessage(time.Second * 10); err != nil {
return fmt.Errorf("calling START: %w", err)
return fmt.Errorf(tr("calling %[1]s: %[2]w"), "START", err)
} else if msg.EventType != "start" {
return errors.Errorf(tr("communication out of sync, expected 'start', received '%s'"), msg.EventType)
} else if msg.Message != "OK" || msg.Error {
Expand All @@ -335,7 +335,7 @@ func (disc *PluggableDiscovery) Stop() error {
return err
}
if msg, err := disc.waitMessage(time.Second * 10); err != nil {
return fmt.Errorf("calling STOP: %w", err)
return fmt.Errorf(tr("calling %[1]s: %[2]w"), "STOP", err)
} else if msg.EventType != "stop" {
return errors.Errorf(tr("communication out of sync, expected 'stop', received '%s'"), msg.EventType)
} else if msg.Message != "OK" || msg.Error {
Expand All @@ -358,7 +358,7 @@ func (disc *PluggableDiscovery) Quit() error {
return err
}
if msg, err := disc.waitMessage(time.Second * 10); err != nil {
return fmt.Errorf("calling QUIT: %w", err)
return fmt.Errorf(tr("calling %[1]s: %[2]w"), "QUIT", err)
} else if msg.EventType != "quit" {
return errors.Errorf(tr("communication out of sync, expected 'quit', received '%s'"), msg.EventType)
} else if msg.Message != "OK" || msg.Error {
Expand All @@ -381,7 +381,7 @@ func (disc *PluggableDiscovery) List() ([]*Port, error) {
return nil, err
}
if msg, err := disc.waitMessage(time.Second * 10); err != nil {
return nil, fmt.Errorf("calling LIST: %w", err)
return nil, fmt.Errorf(tr("calling %[1]s: %[2]w"), "LIST", err)
} else if msg.EventType != "list" {
return nil, errors.Errorf(tr("communication out of sync, expected 'list', received '%s'"), msg.EventType)
} else if msg.Error {
Expand All @@ -404,7 +404,7 @@ func (disc *PluggableDiscovery) StartSync(size int) (<-chan *Event, error) {
}

if msg, err := disc.waitMessage(time.Second * 10); err != nil {
return nil, fmt.Errorf("calling START_SYNC: %w", err)
return nil, fmt.Errorf(tr("calling %[1]s: %[2]w"), "START_SYNC", err)
} else if msg.EventType != "start_sync" {
return nil, errors.Errorf(tr("communication out of sync, expected 'start_sync', received '%s'"), msg.EventType)
} else if msg.Message != "OK" || msg.Error {
Expand Down
17 changes: 10 additions & 7 deletions arduino/discovery/discoverymanager/discoverymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"sync"

"github.com/arduino/arduino-cli/arduino/discovery"
"github.com/arduino/arduino-cli/i18n"
"github.com/pkg/errors"
)

Expand All @@ -30,6 +31,8 @@ type DiscoveryManager struct {
globalEventCh chan *discovery.Event
}

var tr = i18n.Tr

// New creates a new DiscoveryManager
func New() *DiscoveryManager {
return &DiscoveryManager{
Expand Down Expand Up @@ -61,7 +64,7 @@ func (dm *DiscoveryManager) IDs() []string {
func (dm *DiscoveryManager) Add(disc *discovery.PluggableDiscovery) error {
id := disc.GetID()
if _, has := dm.discoveries[id]; has {
return errors.Errorf("pluggable discovery already added: %s", id)
return errors.Errorf(tr("pluggable discovery already added: %s"), id)
}
dm.discoveries[id] = disc
return nil
Expand Down Expand Up @@ -106,7 +109,7 @@ func (dm *DiscoveryManager) RunAll() []error {
}

if err := d.Run(); err != nil {
return fmt.Errorf("discovery %s process not started: %w", d.GetID(), err)
return fmt.Errorf(tr("discovery %[1]s process not started: %[2]w"), d.GetID(), err)
}
return nil
})
Expand All @@ -122,7 +125,7 @@ func (dm *DiscoveryManager) StartAll() []error {
return nil
}
if err := d.Start(); err != nil {
return fmt.Errorf("starting discovery %s: %w", d.GetID(), err)
return fmt.Errorf(tr("starting discovery %[1]s: %[2]w"), d.GetID(), err)
}
return nil
})
Expand All @@ -143,7 +146,7 @@ func (dm *DiscoveryManager) StartSyncAll() (<-chan *discovery.Event, []error) {

eventCh, err := d.StartSync(5)
if err != nil {
return fmt.Errorf("start syncing discovery %s: %w", d.GetID(), err)
return fmt.Errorf(tr("start syncing discovery %[1]s: %[2]w"), d.GetID(), err)
}
go func() {
for ev := range eventCh {
Expand All @@ -166,7 +169,7 @@ func (dm *DiscoveryManager) StopAll() []error {
}

if err := d.Stop(); err != nil {
return fmt.Errorf("stopping discovery %s: %w", d.GetID(), err)
return fmt.Errorf(tr("stopping discovery %[1]s: %[2]w"), d.GetID(), err)
}
return nil
})
Expand All @@ -182,7 +185,7 @@ func (dm *DiscoveryManager) QuitAll() []error {
}

if err := d.Quit(); err != nil {
return fmt.Errorf("quitting discovery %s: %w", d.GetID(), err)
return fmt.Errorf(tr("quitting discovery %[1]s: %[2]w"), d.GetID(), err)
}
return nil
})
Expand Down Expand Up @@ -216,7 +219,7 @@ func (dm *DiscoveryManager) List() ([]*discovery.Port, []error) {
}
ports, err := d.List()
if err != nil {
msgChan <- listMsg{Err: fmt.Errorf("listing ports from discovery %s: %w", d.GetID(), err)}
msgChan <- listMsg{Err: fmt.Errorf(tr("listing ports from discovery %[1]s: %[2]w"), d.GetID(), err)}
}
for _, p := range ports {
msgChan <- listMsg{Port: p}
Expand Down
2 changes: 1 addition & 1 deletion cli/arguments/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (p *Port) GetPort(instance *rpc.Instance, sk *sketch.Sketch) (*discovery.Po
Protocol: "serial",
}, nil
}
return nil, fmt.Errorf("port not found: %s %s", address, protocol)
return nil, fmt.Errorf(tr("port not found: %[1]s %[2]s"), address, protocol)
}
}
}
2 changes: 1 addition & 1 deletion cli/burnbootloader/burnbootloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func run(command *cobra.Command, args []string) {
// We don't need a Sketch to upload a board's bootloader
discoveryPort, err := port.GetPort(instance, nil)
if err != nil {
feedback.Errorf("Error during Upload: %v", err)
feedback.Errorf(tr("Error during Upload: %v"), err)
os.Exit(errorcodes.ErrGeneric)
}

Expand Down
8 changes: 4 additions & 4 deletions cli/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ func run(cmd *cobra.Command, args []string) {
var sk *sketch.Sketch
sk, err = sketch.New(sketchPath)
if err != nil {
feedback.Errorf("Error during Upload: %v", err)
feedback.Errorf(tr("Error during Upload: %v"), err)
os.Exit(errorcodes.ErrGeneric)
}
var discoveryPort *discovery.Port
discoveryPort, err = port.GetPort(inst, sk)
if err != nil {
feedback.Errorf("Error during Upload: %v", err)
feedback.Errorf(tr("Error during Upload: %v"), err)
os.Exit(errorcodes.ErrGeneric)
}

Expand All @@ -209,13 +209,13 @@ func run(cmd *cobra.Command, args []string) {
Protocol: discoveryPort.Protocol,
})
if err != nil {
feedback.Errorf("Error during Upload: %v", err)
feedback.Errorf(tr("Error during Upload: %v"), err)
os.Exit(errorcodes.ErrGeneric)
}

fields := map[string]string{}
if len(userFieldRes.UserFields) > 0 {
feedback.Printf("Uploading to specified board using %s protocol requires the following info:", discoveryPort.Protocol)
feedback.Printf(tr("Uploading to specified board using %s protocol requires the following info:"), discoveryPort.Protocol)
fields = arguments.AskForUserFields(userFieldRes.UserFields)
}

Expand Down
8 changes: 4 additions & 4 deletions cli/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ func run(command *cobra.Command, args []string) {

sk, err := sketch.New(sketchPath)
if err != nil {
feedback.Errorf("Error during Upload: %v", err)
feedback.Errorf(tr("Error during Upload: %v"), err)
os.Exit(errorcodes.ErrGeneric)
}
discoveryPort, err := port.GetPort(instance, sk)
if err != nil {
feedback.Errorf("Error during Upload: %v", err)
feedback.Errorf(tr("Error during Upload: %v"), err)
os.Exit(errorcodes.ErrGeneric)
}

Expand All @@ -108,13 +108,13 @@ func run(command *cobra.Command, args []string) {
Protocol: discoveryPort.Protocol,
})
if err != nil {
feedback.Errorf("Error during Upload: %v", err)
feedback.Errorf(tr("Error during Upload: %v"), err)
os.Exit(errorcodes.ErrGeneric)
}

fields := map[string]string{}
if len(userFieldRes.UserFields) > 0 {
feedback.Printf("Uploading to specified board using %s protocol requires the following info:", discoveryPort.Protocol)
feedback.Printf(tr("Uploading to specified board using %s protocol requires the following info:"), discoveryPort.Protocol)
fields = arguments.AskForUserFields(userFieldRes.UserFields)
}

Expand Down
2 changes: 1 addition & 1 deletion commands/board/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func Watch(instanceID int32, interrupt <-chan bool) (<-chan *rpc.BoardListWatchR
if err != nil {
outChan <- &rpc.BoardListWatchResponse{
EventType: "error",
Error: fmt.Sprintf("stopping discoveries: %s", err),
Error: fmt.Sprintf(tr("stopping discoveries: %s"), err),
}
// Don't close the channel if quitting all discoveries
// failed, otherwise some processes might be left running.
Expand Down
12 changes: 6 additions & 6 deletions commands/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ var tr = i18n.Tr
// by the upload tools needed by the board using the protocol specified in SupportedUserFieldsRequest.
func SupportedUserFields(ctx context.Context, req *rpc.SupportedUserFieldsRequest) (*rpc.SupportedUserFieldsResponse, error) {
if req.Protocol == "" {
return nil, fmt.Errorf("missing protocol")
return nil, fmt.Errorf(tr("missing protocol"))
}

pm := commands.GetPackageManager(req.GetInstance().GetId())
if pm == nil {
return nil, fmt.Errorf("invalid instance")
return nil, fmt.Errorf(tr("invalid instance"))
}

fqbn, err := cores.ParseFQBN(req.GetFqbn())
if err != nil {
return nil, fmt.Errorf("parsing fqbn: %s", err)
return nil, fmt.Errorf(tr("parsing fqbn: %s"), err)
}

_, platformRelease, board, _, _, err := pm.ResolveFQBN(fqbn)
if err != nil {
return nil, fmt.Errorf("loading board data: %s", err)
return nil, fmt.Errorf(tr("loading board data: %s"), err)
}

toolID, err := getToolID(board.Properties, "upload", req.Protocol)
Expand Down Expand Up @@ -90,7 +90,7 @@ func getToolID(props *properties.Map, action, protocol string) (string, error) {
// https://arduino.github.io/arduino-cli/latest/platform-specification/#sketch-upload-configuration
return t, nil
}
return "", fmt.Errorf("cannot find tool: undefined '%s' property", toolProperty)
return "", fmt.Errorf(tr("cannot find tool: undefined '%s' property"), toolProperty)
}

// getUserFields return all user fields supported by the tools specified.
Expand All @@ -112,7 +112,7 @@ func getUserFields(toolID string, platformRelease *cores.PlatformRelease) ([]*rp
}
isSecret, err := strconv.ParseBool(secret)
if err != nil {
return nil, fmt.Errorf(`parsing "tools.%s.upload.field.%s.secret", property is not a boolean`, toolID, key)
return nil, fmt.Errorf(tr("parsing %s, property is not a boolean"), fmt.Sprintf(`"tools.%s.upload.field.%s.secret"`, toolID, key))
}
userFields = append(userFields, &rpc.UserField{
ToolId: toolID,
Expand Down
Loading