Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,45 @@ func NewProgressCallback(win fyne.Window)
func NewExitCallback(app fyne.App, win fyne.Window)
```

## Localization

`fyneselfupdate` uses Fyne's standard [`lang`](https://docs.fyne.io/api/v2/lang/pkg/) package to
translate the text shown in its dialogs (update confirmation, restart confirmation and the
download progress window). No text is hardcoded to English only, everything goes through
`lang.L`, so it will follow whatever locale your application has configured.

Ready-made translation bundles for `fyneselfupdate`'s own strings are provided in the
[`translations`](./translations) folder, named `fyneselfupdate.<lang>.json` (for example
`fyneselfupdate.de.json`). Copy the ones you need into your own application and load them
alongside your own translations:

```go
//go:embed translations/*.json
var translationsFS embed.FS

func main() {
a := app.New()
w := a.NewWindow("My App")

// Load fyneselfupdate's translations together with your own app's translations.
if err := lang.AddTranslationsFS(translationsFS, "translations"); err != nil {
log.Println("Failed to load translations:", err)
}

...
}
```

The `<prefix>.` in the file name avoids collisions if your own application already has a
`de.json`, `fr.json`, etc. in the same `translations` folder, just keep both files side by side.

If a translation for the current locale is missing, `fyneselfupdate` falls back to the original
English text, so adding localization support is entirely optional and backward compatible.

Contributions of new language bundles for `fyneselfupdate` are welcome - please open a pull
request adding a `fyneselfupdate.<lang>.json` file under `translations/`.


## API Compatibility Promises
The main branch of `fyneselfupdate` is *not* guaranteed to have a stable API over time. Still we will try hard to not break its API unecessarily and will follow a proper versioning of our release. We will also keep it in sync and up to date with `fynelabs/selfupate`.

Expand Down
13 changes: 11 additions & 2 deletions confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/lang"
"golang.org/x/net/context"
)

Expand Down Expand Up @@ -34,7 +35,11 @@ func NewUpgradeConfirmCallbackWithTimeout(win fyne.Window, timeout time.Duration
d.Hide()
}()
}
d = dialog.NewConfirm("Application Update", info+"\n\nDo you wish to update?\n", func(ok bool) {
// info comes from the selfupdate package (e.g. "New version found) and is looked
// up as its own translation key via lang.L, with itself as fallback if no
// translation is found
message := lang.L(info) + "\n\n" + lang.L("Do you wish to update?") + "\n"
d = dialog.NewConfirm(lang.L("Application Update"), message, func(ok bool) {
if atomic.LoadInt32(&timedout) == 1 {
ok = true
}
Expand Down Expand Up @@ -74,7 +79,11 @@ func NewRestartConfirmCallbackWithTimeout(win fyne.Window, timeout time.Duration
d.Hide()
}()
}
d = dialog.NewConfirm("Application Update", "The application was updated.\nDo you wish to restart it?\n", func(ok bool) {

message := lang.L("The application was updated.") + "\n" +
lang.L("Do you wish to restart it?") + "\n"

d = dialog.NewConfirm(lang.L("Application Update"),message, func(ok bool) {
if atomic.LoadInt32(&timedout) == 1 {
ok = true
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/fynelabs/fyneselfupdate
module github.com/olegmlsn/fyneselfupdate

go 1.17

Expand Down
5 changes: 3 additions & 2 deletions progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/lang"
"fyne.io/fyne/v2/widget"
)

Expand All @@ -20,8 +21,8 @@ func NewProgressCallback(win fyne.Window) func(float64, error) {
} else {
progress = widget.NewProgressBar()
}
content := container.NewVBox(widget.NewLabel("Downloading update"), progress)
d = dialog.NewCustomWithoutButtons("Application update", content, win)
content := container.NewVBox(widget.NewLabel(lang.L("Downloading update")), progress)
d = dialog.NewCustomWithoutButtons(lang.L("Application update"), content, win)
fyne.Do(d.Show)
}

Expand Down
8 changes: 8 additions & 0 deletions translations/fyneselfupdate.de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"New version found": "Neue Version gefunden",
"Do you wish to update?": "Möchten Sie aktualisieren?",
"Application Update": "Anwendungsaktualisierung",
"The application was updated.": "Die Anwendung wurde aktualisiert.",
"Do you wish to restart it?": "Möchten Sie sie neu starten?",
"Downloading update": "Update wird heruntergeladen"
}