Skip to content

Commit 5559b86

Browse files
authored
[skip changelog] Internationalize strings added for pluggable discovery support (#1384)
1 parent 7147d44 commit 5559b86

File tree

12 files changed

+164
-48
lines changed

12 files changed

+164
-48
lines changed

Diff for: arduino/cores/packagemanager/loader.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -645,18 +645,18 @@ func (pm *PackageManager) loadDiscoveries(release *cores.PlatformRelease) []*sta
645645
for _, id := range discoveryProperties.ExtractSubIndexLists("required") {
646646
tool := pm.GetTool(id)
647647
if tool == nil {
648-
statuses = append(statuses, status.Newf(codes.FailedPrecondition, "discovery not found: %s", id))
648+
statuses = append(statuses, status.Newf(codes.FailedPrecondition, tr("discovery not found: %s"), id))
649649
continue
650650
}
651651
toolRelease := tool.GetLatestInstalled()
652652
if toolRelease == nil {
653-
statuses = append(statuses, status.Newf(codes.FailedPrecondition, "discovery not installed: %s", id))
653+
statuses = append(statuses, status.Newf(codes.FailedPrecondition, tr("discovery not installed: %s"), id))
654654
continue
655655
}
656656
discoveryPath := toolRelease.InstallDir.Join(tool.Name).String()
657657
d, err := discovery.New(id, discoveryPath)
658658
if err != nil {
659-
statuses = append(statuses, status.Newf(codes.FailedPrecondition, "creating discovery: %s", err))
659+
statuses = append(statuses, status.Newf(codes.FailedPrecondition, tr("creating discovery: %s"), err))
660660
continue
661661
}
662662
pm.discoveryManager.Add(d)
@@ -684,7 +684,7 @@ func (pm *PackageManager) loadDiscoveries(release *cores.PlatformRelease) []*sta
684684
for discoveryID, props := range discoveryIDs {
685685
pattern, ok := props.GetOk("pattern")
686686
if !ok {
687-
statuses = append(statuses, status.Newf(codes.FailedPrecondition, "can't find pattern for discovery with id %s", discoveryID))
687+
statuses = append(statuses, status.Newf(codes.FailedPrecondition, tr("can't find pattern for discovery with id %s"), discoveryID))
688688
continue
689689
}
690690
configuration := release.Properties.Clone()

Diff for: arduino/cores/packagemanager/package_manager.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ func (pm *PackageManager) FindToolsRequiredFromPlatformRelease(platform *cores.P
464464
pm.Log.WithField("tool", toolDep).Infof("Required tool")
465465
tool := pm.FindToolDependency(toolDep)
466466
if tool == nil {
467-
return nil, fmt.Errorf("tool release not found: %s", toolDep)
467+
return nil, fmt.Errorf(tr("tool release not found: %s"), toolDep)
468468
}
469469
requiredTools = append(requiredTools, tool)
470470
delete(foundTools, tool.Tool.Name)
@@ -475,7 +475,7 @@ func (pm *PackageManager) FindToolsRequiredFromPlatformRelease(platform *cores.P
475475
pm.Log.WithField("discovery", discoveryDep).Infof("Required discovery")
476476
tool := pm.FindDiscoveryDependency(discoveryDep)
477477
if tool == nil {
478-
return nil, fmt.Errorf("discovery release not found: %s", discoveryDep)
478+
return nil, fmt.Errorf(tr("discovery release not found: %s"), discoveryDep)
479479
}
480480
requiredTools = append(requiredTools, tool)
481481
delete(foundTools, tool.Tool.Name)

Diff for: arduino/discovery/discovery.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ type discoveryMessage struct {
7171
func (msg discoveryMessage) String() string {
7272
s := fmt.Sprintf("type: %s", msg.EventType)
7373
if msg.Message != "" {
74-
s = fmt.Sprintf("%s, message: %s", s, msg.Message)
74+
s = fmt.Sprintf(tr("%[1]s, message: %[2]s"), s, msg.Message)
7575
}
7676
if msg.ProtocolVersion != 0 {
77-
s = fmt.Sprintf("%s, protocol version: %d", s, msg.ProtocolVersion)
77+
s = fmt.Sprintf(tr("%[1]s, protocol version: %[2]d"), s, msg.ProtocolVersion)
7878
}
7979
if len(msg.Ports) > 0 {
80-
s = fmt.Sprintf("%s, ports: %s", s, msg.Ports)
80+
s = fmt.Sprintf(tr("%[1]s, ports: %[2]s"), s, msg.Ports)
8181
}
8282
if msg.Port != nil {
83-
s = fmt.Sprintf("%s, port: %s", s, msg.Port)
83+
s = fmt.Sprintf(tr("%[1]s, port: %[2]s"), s, msg.Port)
8484
}
8585
return s
8686
}
@@ -225,7 +225,7 @@ func (disc *PluggableDiscovery) waitMessage(timeout time.Duration) (*discoveryMe
225225
}
226226
return msg, nil
227227
case <-time.After(timeout):
228-
return nil, fmt.Errorf("timeout waiting for message from %s", disc.id)
228+
return nil, fmt.Errorf(tr("timeout waiting for message from %s"), disc.id)
229229
}
230230
}
231231

@@ -294,7 +294,7 @@ func (disc *PluggableDiscovery) Run() (err error) {
294294
return err
295295
}
296296
if msg, err := disc.waitMessage(time.Second * 10); err != nil {
297-
return fmt.Errorf("calling HELLO: %w", err)
297+
return fmt.Errorf(tr("calling %[1]s: %[2]w"), "HELLO", err)
298298
} else if msg.EventType != "hello" {
299299
return errors.Errorf(tr("communication out of sync, expected 'hello', received '%s'"), msg.EventType)
300300
} else if msg.Message != "OK" || msg.Error {
@@ -315,7 +315,7 @@ func (disc *PluggableDiscovery) Start() error {
315315
return err
316316
}
317317
if msg, err := disc.waitMessage(time.Second * 10); err != nil {
318-
return fmt.Errorf("calling START: %w", err)
318+
return fmt.Errorf(tr("calling %[1]s: %[2]w"), "START", err)
319319
} else if msg.EventType != "start" {
320320
return errors.Errorf(tr("communication out of sync, expected 'start', received '%s'"), msg.EventType)
321321
} else if msg.Message != "OK" || msg.Error {
@@ -335,7 +335,7 @@ func (disc *PluggableDiscovery) Stop() error {
335335
return err
336336
}
337337
if msg, err := disc.waitMessage(time.Second * 10); err != nil {
338-
return fmt.Errorf("calling STOP: %w", err)
338+
return fmt.Errorf(tr("calling %[1]s: %[2]w"), "STOP", err)
339339
} else if msg.EventType != "stop" {
340340
return errors.Errorf(tr("communication out of sync, expected 'stop', received '%s'"), msg.EventType)
341341
} else if msg.Message != "OK" || msg.Error {
@@ -358,7 +358,7 @@ func (disc *PluggableDiscovery) Quit() error {
358358
return err
359359
}
360360
if msg, err := disc.waitMessage(time.Second * 10); err != nil {
361-
return fmt.Errorf("calling QUIT: %w", err)
361+
return fmt.Errorf(tr("calling %[1]s: %[2]w"), "QUIT", err)
362362
} else if msg.EventType != "quit" {
363363
return errors.Errorf(tr("communication out of sync, expected 'quit', received '%s'"), msg.EventType)
364364
} else if msg.Message != "OK" || msg.Error {
@@ -381,7 +381,7 @@ func (disc *PluggableDiscovery) List() ([]*Port, error) {
381381
return nil, err
382382
}
383383
if msg, err := disc.waitMessage(time.Second * 10); err != nil {
384-
return nil, fmt.Errorf("calling LIST: %w", err)
384+
return nil, fmt.Errorf(tr("calling %[1]s: %[2]w"), "LIST", err)
385385
} else if msg.EventType != "list" {
386386
return nil, errors.Errorf(tr("communication out of sync, expected 'list', received '%s'"), msg.EventType)
387387
} else if msg.Error {
@@ -404,7 +404,7 @@ func (disc *PluggableDiscovery) StartSync(size int) (<-chan *Event, error) {
404404
}
405405

406406
if msg, err := disc.waitMessage(time.Second * 10); err != nil {
407-
return nil, fmt.Errorf("calling START_SYNC: %w", err)
407+
return nil, fmt.Errorf(tr("calling %[1]s: %[2]w"), "START_SYNC", err)
408408
} else if msg.EventType != "start_sync" {
409409
return nil, errors.Errorf(tr("communication out of sync, expected 'start_sync', received '%s'"), msg.EventType)
410410
} else if msg.Message != "OK" || msg.Error {

Diff for: arduino/discovery/discoverymanager/discoverymanager.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"sync"
2121

2222
"github.com/arduino/arduino-cli/arduino/discovery"
23+
"github.com/arduino/arduino-cli/i18n"
2324
"github.com/pkg/errors"
2425
)
2526

@@ -30,6 +31,8 @@ type DiscoveryManager struct {
3031
globalEventCh chan *discovery.Event
3132
}
3233

34+
var tr = i18n.Tr
35+
3336
// New creates a new DiscoveryManager
3437
func New() *DiscoveryManager {
3538
return &DiscoveryManager{
@@ -61,7 +64,7 @@ func (dm *DiscoveryManager) IDs() []string {
6164
func (dm *DiscoveryManager) Add(disc *discovery.PluggableDiscovery) error {
6265
id := disc.GetID()
6366
if _, has := dm.discoveries[id]; has {
64-
return errors.Errorf("pluggable discovery already added: %s", id)
67+
return errors.Errorf(tr("pluggable discovery already added: %s"), id)
6568
}
6669
dm.discoveries[id] = disc
6770
return nil
@@ -106,7 +109,7 @@ func (dm *DiscoveryManager) RunAll() []error {
106109
}
107110

108111
if err := d.Run(); err != nil {
109-
return fmt.Errorf("discovery %s process not started: %w", d.GetID(), err)
112+
return fmt.Errorf(tr("discovery %[1]s process not started: %[2]w"), d.GetID(), err)
110113
}
111114
return nil
112115
})
@@ -122,7 +125,7 @@ func (dm *DiscoveryManager) StartAll() []error {
122125
return nil
123126
}
124127
if err := d.Start(); err != nil {
125-
return fmt.Errorf("starting discovery %s: %w", d.GetID(), err)
128+
return fmt.Errorf(tr("starting discovery %[1]s: %[2]w"), d.GetID(), err)
126129
}
127130
return nil
128131
})
@@ -143,7 +146,7 @@ func (dm *DiscoveryManager) StartSyncAll() (<-chan *discovery.Event, []error) {
143146

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

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

184187
if err := d.Quit(); err != nil {
185-
return fmt.Errorf("quitting discovery %s: %w", d.GetID(), err)
188+
return fmt.Errorf(tr("quitting discovery %[1]s: %[2]w"), d.GetID(), err)
186189
}
187190
return nil
188191
})
@@ -216,7 +219,7 @@ func (dm *DiscoveryManager) List() ([]*discovery.Port, []error) {
216219
}
217220
ports, err := d.List()
218221
if err != nil {
219-
msgChan <- listMsg{Err: fmt.Errorf("listing ports from discovery %s: %w", d.GetID(), err)}
222+
msgChan <- listMsg{Err: fmt.Errorf(tr("listing ports from discovery %[1]s: %[2]w"), d.GetID(), err)}
220223
}
221224
for _, p := range ports {
222225
msgChan <- listMsg{Port: p}

Diff for: cli/arguments/port.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (p *Port) GetPort(instance *rpc.Instance, sk *sketch.Sketch) (*discovery.Po
119119
Protocol: "serial",
120120
}, nil
121121
}
122-
return nil, fmt.Errorf("port not found: %s %s", address, protocol)
122+
return nil, fmt.Errorf(tr("port not found: %[1]s %[2]s"), address, protocol)
123123
}
124124
}
125125
}

Diff for: cli/burnbootloader/burnbootloader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func run(command *cobra.Command, args []string) {
6767
// We don't need a Sketch to upload a board's bootloader
6868
discoveryPort, err := port.GetPort(instance, nil)
6969
if err != nil {
70-
feedback.Errorf("Error during Upload: %v", err)
70+
feedback.Errorf(tr("Error during Upload: %v"), err)
7171
os.Exit(errorcodes.ErrGeneric)
7272
}
7373

Diff for: cli/compile/compile.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,13 @@ func run(cmd *cobra.Command, args []string) {
193193
var sk *sketch.Sketch
194194
sk, err = sketch.New(sketchPath)
195195
if err != nil {
196-
feedback.Errorf("Error during Upload: %v", err)
196+
feedback.Errorf(tr("Error during Upload: %v"), err)
197197
os.Exit(errorcodes.ErrGeneric)
198198
}
199199
var discoveryPort *discovery.Port
200200
discoveryPort, err = port.GetPort(inst, sk)
201201
if err != nil {
202-
feedback.Errorf("Error during Upload: %v", err)
202+
feedback.Errorf(tr("Error during Upload: %v"), err)
203203
os.Exit(errorcodes.ErrGeneric)
204204
}
205205

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

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

Diff for: cli/upload/upload.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ func run(command *cobra.Command, args []string) {
9393

9494
sk, err := sketch.New(sketchPath)
9595
if err != nil {
96-
feedback.Errorf("Error during Upload: %v", err)
96+
feedback.Errorf(tr("Error during Upload: %v"), err)
9797
os.Exit(errorcodes.ErrGeneric)
9898
}
9999
discoveryPort, err := port.GetPort(instance, sk)
100100
if err != nil {
101-
feedback.Errorf("Error during Upload: %v", err)
101+
feedback.Errorf(tr("Error during Upload: %v"), err)
102102
os.Exit(errorcodes.ErrGeneric)
103103
}
104104

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

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

Diff for: commands/board/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func Watch(instanceID int32, interrupt <-chan bool) (<-chan *rpc.BoardListWatchR
276276
if err != nil {
277277
outChan <- &rpc.BoardListWatchResponse{
278278
EventType: "error",
279-
Error: fmt.Sprintf("stopping discoveries: %s", err),
279+
Error: fmt.Sprintf(tr("stopping discoveries: %s"), err),
280280
}
281281
// Don't close the channel if quitting all discoveries
282282
// failed, otherwise some processes might be left running.

Diff for: commands/upload/upload.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@ var tr = i18n.Tr
4444
// by the upload tools needed by the board using the protocol specified in SupportedUserFieldsRequest.
4545
func SupportedUserFields(ctx context.Context, req *rpc.SupportedUserFieldsRequest) (*rpc.SupportedUserFieldsResponse, error) {
4646
if req.Protocol == "" {
47-
return nil, fmt.Errorf("missing protocol")
47+
return nil, fmt.Errorf(tr("missing protocol"))
4848
}
4949

5050
pm := commands.GetPackageManager(req.GetInstance().GetId())
5151
if pm == nil {
52-
return nil, fmt.Errorf("invalid instance")
52+
return nil, fmt.Errorf(tr("invalid instance"))
5353
}
5454

5555
fqbn, err := cores.ParseFQBN(req.GetFqbn())
5656
if err != nil {
57-
return nil, fmt.Errorf("parsing fqbn: %s", err)
57+
return nil, fmt.Errorf(tr("parsing fqbn: %s"), err)
5858
}
5959

6060
_, platformRelease, board, _, _, err := pm.ResolveFQBN(fqbn)
6161
if err != nil {
62-
return nil, fmt.Errorf("loading board data: %s", err)
62+
return nil, fmt.Errorf(tr("loading board data: %s"), err)
6363
}
6464

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

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

0 commit comments

Comments
 (0)