Closed n00bsi closed 4 months ago
You need to put your code inside the main function.
package main
import (
"fmt"
"github.com/nicksnyder/go-i18n/v2/i18n"
"golang.org/x/text/language"
)
func main() {
fmt.Println("\nhello world!\n")
messageEn := i18n.Message{ //1
ID: "hello world!",
Other: "Hello!",
}
messageFr := i18n.Message{ //2
ID: "hello world!",
Other: "Bonjour le monde",
}
bundle := i18n.NewBundle(language.English) //1
bundle.AddMessages(language.English, &messageEn) //2
bundle.AddMessages(language.French, &messageFr) //3
localizer := i18n.NewLocalizer(bundle, //4
language.French.String(),
language.English.String())
localizeConfig := i18n.LocalizeConfig{ //5
MessageID: "hello world!",
}
localization, _ := localizer.Localize(&localizeConfig) //6
}
@nicksnyder
thanks - but...
$ go run hello_world_multilang.go
# command-line-arguments
./hello_world_multilang.go:32:2: localization declared and not used
this is this line: calization, _ := localizer.Localize(&localizeConfig) //6
I was just illustrating how to put your code inside of the main function, if your code didn't compile before, it isn't going to compile now.
There is plenty of documentation and working examples for you to look at to get started:
Hi, as golang noob - just tyed to get the hello world to run... but did not work.
go Version: 1.22.4
main.go
got error from the Codium IDE - "expected declaration, found messageEn"