-
Hi guys, I am pretty much new to Fyne, and not an expert in Golang (not a pure beginner, thought). If this is not a good place to ask a question like this, my apologize. I wrote a simple implementation for my app to support multiple languages, but application require restart to change everything. This is not a problem for users, because they will mostly set it once, but would be great to restart app automatically. Is there any way to achieve that? Whatever I try, I can close it, but never start again. Here is what I did: I defined a new package called package translation
import (
"fyne.io/fyne/v2"
)
type Translation struct {
Home string
Settings string
Timer string
Pwm string
} Now I have methods func (t *Translation) Initialize() {
language :=
fyne.CurrentApp().Preferences().StringWithFallback("LANGUAGE", "English")
t.Set(language)
}
func (t *Translation) Set(l string) {
fyne.CurrentApp().Preferences().SetString("LANGUAGE", l)
switch l {
case "English":
t.English()
case "Serbian":
t.Serbian()
}
} At the end, there are methods to add strings based on selected language: func (t *Translation) English() {
t.Home = "Home"
t.Settings = "Settings"
t.Timer = "Time "
t.PWM = "PWM"
}
func (t *Translation) Serbian() {
t.Home = "Насловна"
t.Settings = "Подешавања"
t.Timer = "Време"
t.PWM = "Пулс "
} To use it, I put everything inside a struct: type MyAPP struct {
APP fyne.APP
WIN fyne.Window
TR translation.Translation
}
func StartApp() *MyApp {
a := app.NewWithID('some-id')
w := a.NewWindow('title')
myapp := &MyApp{APP: a WIN: w}
myapp.TR := translations.Translation{}
myapp.TR.Initialize()
return myapp
} Now in other methods I pass func doSomething(m *MyApp) {
T := m.TR
msgTab := container.NewTabItem(T.Home, container.NewPadded(some_function(f)))
...
...
} Is there anything wrong with setup like this, and is there a way to restart app after selecting language? Language is selected from dropdown menu. Edit: I will upload full source code tomorrow and update question with link, just in case someone want to take a look. Edit 2: Link to the repository: https://github.com/alx3dev/Wireless-UV-Station |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hi there. Welcome. There is nothing wrong with asking here. You are more than welcome to do so :) I think asking the application to restart itself is going to be quite hard to get working across platforms; or will at least require platform specific solutions for most of them. I suppose https://stackoverflow.com/questions/41376092/golang-how-to-auto-restart-process-when-binary-updated could be a useful place to start. TranslationsAs for if it is a good solution for translation, I don’t really have any huge input to give. It generally seems quite clean and well designed. I guess it probably could be useful as an external package for other Fyne application developers to use until we provide a built-in solution that integrates better into the toolkit. The only thing that I could think of is that it might be easier for translators to implement translations by loading from files and not having to set fields individually. Both have their drawbacks though. Yours seems like it could be quite fast and avoid all the trouble of bundling files into the binary. |
Beta Was this translation helpful? Give feedback.
-
I would add to the answer above that you don't have to restart an application - you can add a listener to the preferences and each widget can update when the language changes. This is much faster for the end-user as restarting software is very slow in comparison to just updating the widgets on screen. |
Beta Was this translation helpful? Give feedback.
Hi there. Welcome. There is nothing wrong with asking here. You are more than welcome to do so :)
I think asking the application to restart itself is going to be quite hard to get working across platforms; or will at least require platform specific solutions for most of them. I suppose https://stackoverflow.com/questions/41376092/golang-how-to-auto-restart-process-when-binary-updated could be a useful place to start.
Translations
As for if it is a good solution for translation, I don’t really have any huge input to give. It generally seems quite clean and well designed. I guess it probably could be useful as an external package for other Fyne application developers to use until we provide…