diff --git a/docs/UPGRADING.md b/docs/UPGRADING.md index 39729a1c592..a6cfad9a5f9 100644 --- a/docs/UPGRADING.md +++ b/docs/UPGRADING.md @@ -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 diff --git a/i18n/i18n.go b/i18n/i18n.go index 6881922b96a..9a0ffead925 100644 --- a/i18n/i18n.go +++ b/i18n/i18n.go @@ -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 } diff --git a/main.go b/main.go index fd691f526c9..2405f612188 100644 --- a/main.go +++ b/main.go @@ -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)