From 81891a06a04dc1118a4dc5d67a53ff0da1eefc0c Mon Sep 17 00:00:00 2001 From: Simon Dassow Date: Fri, 12 Sep 2025 17:42:45 +0200 Subject: [PATCH 1/6] Add translations to hello world app/init command --- cmd/fyne/internal/commands/init.go | 14 ++++++++++++++ cmd/fyne/internal/templates/data/hello_world.got | 12 +++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cmd/fyne/internal/commands/init.go b/cmd/fyne/internal/commands/init.go index 32b8ea4..47d4954 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", 0755); 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/templates/data/hello_world.got b/cmd/fyne/internal/templates/data/hello_world.got index 115d690..9b8d68c 100644 --- a/cmd/fyne/internal/templates/data/hello_world.got +++ b/cmd/fyne/internal/templates/data/hello_world.got @@ -1,14 +1,24 @@ package main import ( + "embed" + "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.X("hello", "Hello World!"))) w.ShowAndRun() } From d6321b42ca8ac8d99f1ac688c312da7570fc8f10 Mon Sep 17 00:00:00 2001 From: Simon Dassow Date: Fri, 12 Sep 2025 17:45:03 +0200 Subject: [PATCH 2/6] Adjust permission format --- cmd/fyne/internal/commands/init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/fyne/internal/commands/init.go b/cmd/fyne/internal/commands/init.go index 47d4954..a1a9043 100644 --- a/cmd/fyne/internal/commands/init.go +++ b/cmd/fyne/internal/commands/init.go @@ -152,7 +152,7 @@ func initAction(ctx *cli.Context) error { return fmt.Errorf("failed to run command: %v", err) } - if err := os.Mkdir("translations", 0755); err != nil { + if err := os.Mkdir("translations", 0o755); err != nil { return err } From b75bb49cceabf9cf9e7a582e3859775f4b653d02 Mon Sep 17 00:00:00 2001 From: Simon Dassow Date: Fri, 12 Sep 2025 17:46:33 +0200 Subject: [PATCH 3/6] Change to please stricter linter --- cmd/fyne/internal/mobile/binres/binres_test.go | 5 +++-- cmd/fyne/internal/mobile/build.go | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/fyne/internal/mobile/binres/binres_test.go b/cmd/fyne/internal/mobile/binres/binres_test.go index 4a41088..40aca53 100644 --- a/cmd/fyne/internal/mobile/binres/binres_test.go +++ b/cmd/fyne/internal/mobile/binres/binres_test.go @@ -266,11 +266,12 @@ func compareNamespaces(have, want *Namespace) error { return nil } -func rtou(a []TableRef) (b []uint32) { +func rtou(a []TableRef) []uint32 { + var b []uint32 for _, x := range a { b = append(b, uint32(x)) } - return + return b } func compareUint32s(t *testing.T, a, b []uint32) error { diff --git a/cmd/fyne/internal/mobile/build.go b/cmd/fyne/internal/mobile/build.go index a78fc5e..7dcbe20 100644 --- a/cmd/fyne/internal/mobile/build.go +++ b/cmd/fyne/internal/mobile/build.go @@ -33,9 +33,9 @@ const ( minAndroidAPI = 15 ) -func runBuild(cmd *command) (err error) { - _, err = runBuildImpl(cmd) - return +func runBuild(cmd *command) error { + _, err := runBuildImpl(cmd) + return err } // AppOutputName provides the name of a build resource for a given os - "ios" or "android". From 25ef1cf06c079dcb19169e9572d08dc21824c4bc Mon Sep 17 00:00:00 2001 From: Simon Dassow Date: Fri, 12 Sep 2025 20:40:15 +0200 Subject: [PATCH 4/6] Add missing import --- cmd/fyne/internal/templates/data/hello_world.got | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/fyne/internal/templates/data/hello_world.got b/cmd/fyne/internal/templates/data/hello_world.got index 9b8d68c..b0e857f 100644 --- a/cmd/fyne/internal/templates/data/hello_world.got +++ b/cmd/fyne/internal/templates/data/hello_world.got @@ -3,6 +3,7 @@ package main import ( "embed" + "fyne.io/fyne/v2" "fyne.io/fyne/v2/app" "fyne.io/fyne/v2/lang" "fyne.io/fyne/v2/widget" From ece89f98f899af7bc83ddef6099efd4e32b0f946 Mon Sep 17 00:00:00 2001 From: Simon Dassow Date: Fri, 12 Sep 2025 20:45:23 +0200 Subject: [PATCH 5/6] Allocate full slice at once --- cmd/fyne/internal/mobile/binres/binres_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/fyne/internal/mobile/binres/binres_test.go b/cmd/fyne/internal/mobile/binres/binres_test.go index 40aca53..02728ee 100644 --- a/cmd/fyne/internal/mobile/binres/binres_test.go +++ b/cmd/fyne/internal/mobile/binres/binres_test.go @@ -267,9 +267,9 @@ func compareNamespaces(have, want *Namespace) error { } func rtou(a []TableRef) []uint32 { - var b []uint32 - for _, x := range a { - b = append(b, uint32(x)) + b := make([]uint32, len(a)) + for i, x := range a { + b[i] = uint32(x) } return b } From 1de8340cc2d1d83bc5d6638da5c82102c65dfb44 Mon Sep 17 00:00:00 2001 From: Simon Dassow Date: Fri, 12 Sep 2025 23:35:58 +0200 Subject: [PATCH 6/6] Simplify a bit --- cmd/fyne/internal/templates/data/hello_world.got | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/fyne/internal/templates/data/hello_world.got b/cmd/fyne/internal/templates/data/hello_world.got index b0e857f..ef3642d 100644 --- a/cmd/fyne/internal/templates/data/hello_world.got +++ b/cmd/fyne/internal/templates/data/hello_world.got @@ -20,6 +20,6 @@ func main() { fyne.LogError("failed to load translations", err) } - w.SetContent(widget.NewLabel(lang.X("hello", "Hello World!"))) + w.SetContent(widget.NewLabel(lang.L("Hello World!"))) w.ShowAndRun() }