The Wayback Machine - https://web.archive.org/web/20211231043434/https://github.com/arduino/arduino-cli/commit/7b68b48d250f7cae0daf989b8afa76b4260fa960
Skip to content
Permalink
Browse files
[breaking] Pass user locale preference directly to i18n package (#1365)
The user can configure their locale preference via the `locale` configuration key. This information is given priority by
the `github.com/arduino/arduino-cli/configuration` package over the automatically detected locale.

Previously, the `i18n` package got the configuration setting from the `github.com/arduino/arduino-cli/configuration`
package, but this will result in an import cycle when the `i18n` package is used to enable translation of the output
strings of the `configuration` package.

To avoid this, the caller now reads the configuration and passes the locale code to the `i18n` package via its `Init`
function:

i18n.Init("it")

The argument can be omitted if only automated locale detection is needed:

i18n.Init()
  • Loading branch information
per1234 committed Jul 28, 2021
1 parent fc367b7 commit 7b68b48d250f7cae0daf989b8afa76b4260fa960
Showing with 24 additions and 7 deletions.
  1. +15 −0 docs/UPGRADING.md
  2. +8 −6 i18n/i18n.go
  3. +1 −1 main.go
@@ -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
@@ -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
}
@@ -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)

0 comments on commit 7b68b48

Please sign in to comment.