diff --git a/cmd/fyne/internal/commands/init.go b/cmd/fyne/internal/commands/init.go index 32b8ea4..a1a9043 100644 --- a/cmd/fyne/internal/commands/init.go +++ b/cmd/fyne/internal/commands/init.go @@ -152,6 +152,20 @@ func initAction(ctx *cli.Context) error { return fmt.Errorf("failed to run command: %v", err) } + if err := os.Mkdir("translations", 0o755); err != nil { + return err + } + + args := []string{ctx.App.Name, "translate"} + if verbose { + args = append(args, "-v") + } + args = append(args, "translations/en.json") + args = append(args, "main.go") + if err := ctx.App.Run(args); err != nil { + return fmt.Errorf("failed to run command: %v", err) + } + fmt.Println("Your new app is ready. Run it directly with: go run .") return nil diff --git a/cmd/fyne/internal/mobile/binres/binres_test.go b/cmd/fyne/internal/mobile/binres/binres_test.go index b167301..02728ee 100644 --- a/cmd/fyne/internal/mobile/binres/binres_test.go +++ b/cmd/fyne/internal/mobile/binres/binres_test.go @@ -266,9 +266,10 @@ func compareNamespaces(have, want *Namespace) error { return nil } -func rtou(a []TableRef) (b []uint32) { - for _, x := range a { - b = append(b, uint32(x)) +func rtou(a []TableRef) []uint32 { + b := make([]uint32, len(a)) + for i, x := range a { + b[i] = uint32(x) } return b } diff --git a/cmd/fyne/internal/mobile/build.go b/cmd/fyne/internal/mobile/build.go index 2ce82cc..7dcbe20 100644 --- a/cmd/fyne/internal/mobile/build.go +++ b/cmd/fyne/internal/mobile/build.go @@ -33,8 +33,8 @@ const ( minAndroidAPI = 15 ) -func runBuild(cmd *command) (err error) { - _, err = runBuildImpl(cmd) +func runBuild(cmd *command) error { + _, err := runBuildImpl(cmd) return err } diff --git a/cmd/fyne/internal/templates/data/hello_world.got b/cmd/fyne/internal/templates/data/hello_world.got index 115d690..ef3642d 100644 --- a/cmd/fyne/internal/templates/data/hello_world.got +++ b/cmd/fyne/internal/templates/data/hello_world.got @@ -1,14 +1,25 @@ package main import ( + "embed" + + "fyne.io/fyne/v2" "fyne.io/fyne/v2/app" + "fyne.io/fyne/v2/lang" "fyne.io/fyne/v2/widget" ) +//go:embed translations/*.json +var translationsFS embed.FS + func main() { a := app.NewWithID({{ printf "%q" .Details.ID }}) w := a.NewWindow({{ printf "%q" .Details.Name }}) - w.SetContent(widget.NewLabel("Hello World!")) + if err := lang.AddTranslationsFS(translationsFS, "translations"); err != nil { + fyne.LogError("failed to load translations", err) + } + + w.SetContent(widget.NewLabel(lang.L("Hello World!"))) w.ShowAndRun() }