2024-01-28 22:01:16 +06:00
|
|
|
package localizer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fyne.io/fyne/v2"
|
|
|
|
"fyne.io/fyne/v2/widget"
|
2024-02-17 19:08:58 +06:00
|
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
2024-01-28 22:01:16 +06:00
|
|
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ViewContract interface {
|
2024-02-17 19:08:58 +06:00
|
|
|
LanguageSelection(funcSelected func(lang kernel.Lang))
|
2024-01-28 22:01:16 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
type View struct {
|
2024-02-17 19:08:58 +06:00
|
|
|
app kernel.AppContract
|
2024-01-28 22:01:16 +06:00
|
|
|
}
|
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
func NewView(app kernel.AppContract) *View {
|
2024-01-28 22:01:16 +06:00
|
|
|
return &View{
|
2024-02-17 19:08:58 +06:00
|
|
|
app: app,
|
2024-01-28 22:01:16 +06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
func (v View) LanguageSelection(funcSelected func(lang kernel.Lang)) {
|
|
|
|
languages := v.app.GetLocalizerService().GetLanguages()
|
2024-01-28 22:01:16 +06:00
|
|
|
listView := widget.NewList(
|
|
|
|
func() int {
|
|
|
|
return len(languages)
|
|
|
|
},
|
|
|
|
func() fyne.CanvasObject {
|
|
|
|
return widget.NewLabel("template")
|
|
|
|
},
|
|
|
|
func(i widget.ListItemID, o fyne.CanvasObject) {
|
|
|
|
block := o.(*widget.Label)
|
|
|
|
block.SetText(languages[i].Title)
|
|
|
|
})
|
|
|
|
listView.OnSelected = func(id widget.ListItemID) {
|
2024-02-17 19:08:58 +06:00
|
|
|
_ = v.app.GetLocalizerService().SetCurrentLanguage(languages[id])
|
2024-01-28 22:01:16 +06:00
|
|
|
funcSelected(languages[id])
|
|
|
|
}
|
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
messageHead := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
2024-01-28 22:01:16 +06:00
|
|
|
MessageID: "languageSelectionHead",
|
|
|
|
})
|
2024-02-17 19:08:58 +06:00
|
|
|
v.app.GetWindow().SetContent(widget.NewCard(messageHead, "", listView))
|
2024-01-28 22:01:16 +06:00
|
|
|
}
|
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
func LanguageSelectionForm(localizerService kernel.LocalizerContract, funcSelected func(lang kernel.Lang)) fyne.CanvasObject {
|
2024-01-28 22:01:16 +06:00
|
|
|
languages := localizerService.GetLanguages()
|
|
|
|
currentLanguage := localizerService.GetCurrentLanguage()
|
|
|
|
listView := widget.NewList(
|
|
|
|
func() int {
|
|
|
|
return len(languages)
|
|
|
|
},
|
|
|
|
func() fyne.CanvasObject {
|
|
|
|
return widget.NewLabel("template")
|
|
|
|
},
|
|
|
|
func(i widget.ListItemID, o fyne.CanvasObject) {
|
|
|
|
block := o.(*widget.Label)
|
|
|
|
block.SetText(languages[i].Title)
|
|
|
|
if languages[i].Code == currentLanguage.Lang.Code {
|
|
|
|
block.TextStyle = fyne.TextStyle{Bold: true}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
listView.OnSelected = func(id widget.ListItemID) {
|
|
|
|
_ = localizerService.SetCurrentLanguage(languages[id])
|
|
|
|
funcSelected(languages[id])
|
|
|
|
}
|
|
|
|
|
|
|
|
messageHead := localizerService.GetMessage(&i18n.LocalizeConfig{
|
|
|
|
MessageID: "languageSelectionFormHead",
|
|
|
|
})
|
|
|
|
return widget.NewCard(messageHead, "", listView)
|
|
|
|
}
|