Skip to content

[breaking] Pass user locale preference directly to i18n package #1365

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
Jul 28, 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
15 changes: 15 additions & 0 deletions docs/UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ Here you can find a list of migration guides to handle breaking changes between

### Change public library interface

#### `github.com/arduino/arduino-cli/i18n` package

The behavior of the `Init` function has changed. The user specified locale code is no longer read from the
`github.com/arduino/arduino-cli/configuration` package and now must be passed directly to `Init` as a string:

```go
i18n.Init("it")
```

Omit the argument for automated locale detection:

```go
i18n.Init()
```

#### `github.com/arduino/arduino-cli/arduino/builder` package

`GenBuildPath()` function has been moved to `github.com/arduino/arduino-cli/arduino/sketch` package. The signature is
Expand Down
14 changes: 8 additions & 6 deletions i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@

package i18n

import "github.com/arduino/arduino-cli/configuration"

// Init initializes the i18n module, setting the locale according to this order of preference:
// 1. Configuration set in arduino-cli.yaml
// 1. Locale specified via the function call
// 2. OS Locale
// 3. en (default)
func Init() {
func Init(configLocale ...string) {
initRiceBox()
locales := supportedLocales()

if configLocale := configuration.Settings.GetString("locale"); configLocale != "" {
if locale := findMatchingLocale(configLocale, locales); locale != "" {
if len(configLocale) > 1 {
panic("Multiple arguments not supported")
}

if len(configLocale) > 0 && configLocale[0] != "" {
if locale := findMatchingLocale(configLocale[0], locales); locale != "" {
setLocale(locale)
return
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

func main() {
configuration.Settings = configuration.Init(configuration.FindConfigFileInArgsOrWorkingDirectory(os.Args))
i18n.Init()
i18n.Init(configuration.Settings.GetString("locale"))
arduinoCmd := cli.NewCommand()
if err := arduinoCmd.Execute(); err != nil {
os.Exit(errorcodes.ErrGeneric)
Expand Down