Refactor localization system and migrate to Fyne's built-in support
Replaced the `i18n` and `toml` dependencies with Fyne's built-in language system for localization management. Updated the `Localizer` implementation to handle translations using JSON files and embed functionality. Simplified language selection and persisted settings via Fyne's preferences API.
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/helper"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/setting"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
)
|
||||
|
||||
type ConvertorHandlerContract interface {
|
||||
@@ -134,25 +133,19 @@ func (h ConvertorHandler) checkingFFPathUtilities() bool {
|
||||
func (h ConvertorHandler) saveSettingFFPath(ffmpegPath string, ffprobePath string, ffplayPath string) error {
|
||||
ffmpegChecking, _ := h.app.GetConvertorService().ChangeFFmpegPath(ffmpegPath)
|
||||
if ffmpegChecking == false {
|
||||
errorText := h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "errorFFmpeg",
|
||||
})
|
||||
errorText := h.app.GetLocalizerService().GetMessage("errorFFmpeg")
|
||||
return errors.New(errorText)
|
||||
}
|
||||
|
||||
ffprobeChecking, _ := h.app.GetConvertorService().ChangeFFprobePath(ffprobePath)
|
||||
if ffprobeChecking == false {
|
||||
errorText := h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "errorFFprobe",
|
||||
})
|
||||
errorText := h.app.GetLocalizerService().GetMessage("errorFFprobe")
|
||||
return errors.New(errorText)
|
||||
}
|
||||
|
||||
ffplayChecking, _ := h.app.GetConvertorService().ChangeFFplayPath(ffplayPath)
|
||||
if ffplayChecking == false {
|
||||
errorText := h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "errorFFplay",
|
||||
})
|
||||
errorText := h.app.GetLocalizerService().GetMessage("errorFFplay")
|
||||
return errors.New(errorText)
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,6 @@ import (
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"github.com/ulikunitz/xz"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -30,9 +29,7 @@ func (h ConvertorHandler) downloadFFmpeg(progressBar *widget.ProgressBar, progre
|
||||
return err
|
||||
}
|
||||
}
|
||||
progressMessage.Text = h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "downloadRun",
|
||||
})
|
||||
progressMessage.Text = h.app.GetLocalizerService().GetMessage("downloadRun")
|
||||
fyne.Do(func() {
|
||||
progressMessage.Refresh()
|
||||
})
|
||||
@@ -41,9 +38,7 @@ func (h ConvertorHandler) downloadFFmpeg(progressBar *widget.ProgressBar, progre
|
||||
return err
|
||||
}
|
||||
|
||||
progressMessage.Text = h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "unzipRun",
|
||||
})
|
||||
progressMessage.Text = h.app.GetLocalizerService().GetMessage("unzipRun")
|
||||
fyne.Do(func() {
|
||||
progressMessage.Refresh()
|
||||
})
|
||||
@@ -53,9 +48,7 @@ func (h ConvertorHandler) downloadFFmpeg(progressBar *widget.ProgressBar, progre
|
||||
}
|
||||
_ = os.Remove("ffmpeg/ffmpeg.tar.xz")
|
||||
|
||||
progressMessage.Text = h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "testFF",
|
||||
})
|
||||
progressMessage.Text = h.app.GetLocalizerService().GetMessage("testFF")
|
||||
fyne.Do(func() {
|
||||
progressMessage.Refresh()
|
||||
})
|
||||
@@ -69,9 +62,7 @@ func (h ConvertorHandler) downloadFFmpeg(progressBar *widget.ProgressBar, progre
|
||||
return err
|
||||
}
|
||||
|
||||
progressMessage.Text = h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "completedQueue",
|
||||
})
|
||||
progressMessage.Text = h.app.GetLocalizerService().GetMessage("completedQueue")
|
||||
fyne.Do(func() {
|
||||
progressMessage.Refresh()
|
||||
})
|
||||
|
@@ -10,7 +10,6 @@ import (
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -30,9 +29,7 @@ func (h ConvertorHandler) downloadFFmpeg(progressBar *widget.ProgressBar, progre
|
||||
return err
|
||||
}
|
||||
}
|
||||
progressMessage.Text = h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "downloadRun",
|
||||
})
|
||||
progressMessage.Text = h.app.GetLocalizerService().GetMessage("downloadRun")
|
||||
fyne.Do(func() {
|
||||
progressMessage.Refresh()
|
||||
})
|
||||
@@ -41,9 +38,7 @@ func (h ConvertorHandler) downloadFFmpeg(progressBar *widget.ProgressBar, progre
|
||||
return err
|
||||
}
|
||||
|
||||
progressMessage.Text = h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "unzipRun",
|
||||
})
|
||||
progressMessage.Text = h.app.GetLocalizerService().GetMessage("unzipRun")
|
||||
fyne.Do(func() {
|
||||
progressMessage.Refresh()
|
||||
})
|
||||
@@ -53,9 +48,7 @@ func (h ConvertorHandler) downloadFFmpeg(progressBar *widget.ProgressBar, progre
|
||||
}
|
||||
_ = os.Remove("ffmpeg/ffmpeg.zip")
|
||||
|
||||
progressMessage.Text = h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "testFF",
|
||||
})
|
||||
progressMessage.Text = h.app.GetLocalizerService().GetMessage("testFF")
|
||||
fyne.Do(func() {
|
||||
progressMessage.Refresh()
|
||||
})
|
||||
@@ -68,9 +61,7 @@ func (h ConvertorHandler) downloadFFmpeg(progressBar *widget.ProgressBar, progre
|
||||
return err
|
||||
}
|
||||
|
||||
progressMessage.Text = h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "completedQueue",
|
||||
})
|
||||
progressMessage.Text = h.app.GetLocalizerService().GetMessage("completedQueue")
|
||||
fyne.Do(func() {
|
||||
progressMessage.Refresh()
|
||||
})
|
||||
|
@@ -1,42 +1,32 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2/lang"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/localizer"
|
||||
)
|
||||
|
||||
type MainHandler struct {
|
||||
app kernel.AppContract
|
||||
convertorHandler ConvertorHandlerContract
|
||||
menuHandler MenuHandlerContract
|
||||
localizerRepository localizer.RepositoryContract
|
||||
app kernel.AppContract
|
||||
convertorHandler ConvertorHandlerContract
|
||||
menuHandler MenuHandlerContract
|
||||
}
|
||||
|
||||
func NewMainHandler(
|
||||
app kernel.AppContract,
|
||||
convertorHandler ConvertorHandlerContract,
|
||||
menuHandler MenuHandlerContract,
|
||||
localizerRepository localizer.RepositoryContract,
|
||||
) *MainHandler {
|
||||
return &MainHandler{
|
||||
app: app,
|
||||
convertorHandler: convertorHandler,
|
||||
menuHandler: menuHandler,
|
||||
localizerRepository: localizerRepository,
|
||||
app: app,
|
||||
convertorHandler: convertorHandler,
|
||||
menuHandler: menuHandler,
|
||||
}
|
||||
}
|
||||
|
||||
func (h MainHandler) Start() {
|
||||
language := h.localizerRepository.GetCode()
|
||||
if len(language) == 0 {
|
||||
err := h.app.GetLocalizerService().SetCurrentLanguageByCode(lang.SystemLocale().LanguageString())
|
||||
if err != nil {
|
||||
h.menuHandler.LanguageSelection()
|
||||
return
|
||||
}
|
||||
if h.app.GetLocalizerService().IsStartWithLanguageSelection() {
|
||||
h.menuHandler.LanguageSelection()
|
||||
return
|
||||
}
|
||||
_ = h.app.GetLocalizerService().SetCurrentLanguageByCode(language)
|
||||
|
||||
h.convertorHandler.MainConvertor()
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@ import (
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/localizer"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/menu"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/theme"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
)
|
||||
|
||||
type MenuHandlerContract interface {
|
||||
@@ -15,13 +14,12 @@ type MenuHandlerContract interface {
|
||||
}
|
||||
|
||||
type MenuHandler struct {
|
||||
app kernel.AppContract
|
||||
convertorHandler ConvertorHandlerContract
|
||||
menuView menu.ViewContract
|
||||
menuViewSetting menu.ViewSettingContract
|
||||
localizerView localizer.ViewContract
|
||||
localizerRepository localizer.RepositoryContract
|
||||
themeService theme.ThemeContract
|
||||
app kernel.AppContract
|
||||
convertorHandler ConvertorHandlerContract
|
||||
menuView menu.ViewContract
|
||||
menuViewSetting menu.ViewSettingContract
|
||||
localizerView localizer.ViewContract
|
||||
themeService theme.ThemeContract
|
||||
}
|
||||
|
||||
func NewMenuHandler(
|
||||
@@ -30,17 +28,15 @@ func NewMenuHandler(
|
||||
menuView menu.ViewContract,
|
||||
menuViewSetting menu.ViewSettingContract,
|
||||
localizerView localizer.ViewContract,
|
||||
localizerRepository localizer.RepositoryContract,
|
||||
themeService theme.ThemeContract,
|
||||
) *MenuHandler {
|
||||
return &MenuHandler{
|
||||
app: app,
|
||||
convertorHandler: convertorHandler,
|
||||
menuView: menuView,
|
||||
menuViewSetting: menuViewSetting,
|
||||
localizerView: localizerView,
|
||||
localizerRepository: localizerRepository,
|
||||
themeService: themeService,
|
||||
app: app,
|
||||
convertorHandler: convertorHandler,
|
||||
menuView: menuView,
|
||||
menuViewSetting: menuViewSetting,
|
||||
localizerView: localizerView,
|
||||
themeService: themeService,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,31 +48,23 @@ func (h MenuHandler) GetMainMenu() *fyne.MainMenu {
|
||||
}
|
||||
|
||||
func (h MenuHandler) getMenuSettings() *fyne.Menu {
|
||||
quit := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "exit",
|
||||
}), nil)
|
||||
quit := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage("exit"), nil)
|
||||
quit.IsQuit = true
|
||||
h.app.GetLocalizerService().AddChangeCallback("exit", func(text string) {
|
||||
quit.Label = text
|
||||
})
|
||||
|
||||
settingsSelection := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "settings",
|
||||
}), h.settingsSelection)
|
||||
settingsSelection := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage("settings"), h.settingsSelection)
|
||||
h.app.GetLocalizerService().AddChangeCallback("settings", func(text string) {
|
||||
settingsSelection.Label = text
|
||||
})
|
||||
|
||||
ffPathSelection := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "changeFFPath",
|
||||
}), h.convertorHandler.FfPathSelection)
|
||||
ffPathSelection := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage("changeFFPath"), h.convertorHandler.FfPathSelection)
|
||||
h.app.GetLocalizerService().AddChangeCallback("changeFFPath", func(text string) {
|
||||
ffPathSelection.Label = text
|
||||
})
|
||||
|
||||
settings := fyne.NewMenu(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "settings",
|
||||
}), settingsSelection, ffPathSelection, quit)
|
||||
settings := fyne.NewMenu(h.app.GetLocalizerService().GetMessage("settings"), settingsSelection, ffPathSelection, quit)
|
||||
h.app.GetLocalizerService().AddChangeCallback("settings", func(text string) {
|
||||
settings.Label = text
|
||||
settings.Refresh()
|
||||
@@ -86,30 +74,22 @@ func (h MenuHandler) getMenuSettings() *fyne.Menu {
|
||||
}
|
||||
|
||||
func (h MenuHandler) getMenuHelp() *fyne.Menu {
|
||||
about := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "about",
|
||||
}), h.openAbout)
|
||||
about := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage("about"), h.openAbout)
|
||||
h.app.GetLocalizerService().AddChangeCallback("about", func(text string) {
|
||||
about.Label = text
|
||||
})
|
||||
|
||||
gratitude := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "gratitude",
|
||||
}), h.menuView.Gratitude)
|
||||
gratitude := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage("gratitude"), h.menuView.Gratitude)
|
||||
h.app.GetLocalizerService().AddChangeCallback("gratitude", func(text string) {
|
||||
gratitude.Label = text
|
||||
})
|
||||
|
||||
helpFFplay := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "helpFFplay",
|
||||
}), h.menuView.HelpFFplay)
|
||||
helpFFplay := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage("helpFFplay"), h.menuView.HelpFFplay)
|
||||
h.app.GetLocalizerService().AddChangeCallback("helpFFplay", func(text string) {
|
||||
helpFFplay.Label = text
|
||||
})
|
||||
|
||||
help := fyne.NewMenu(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "help",
|
||||
}), helpFFplay, about, gratitude)
|
||||
help := fyne.NewMenu(h.app.GetLocalizerService().GetMessage("help"), helpFFplay, about, gratitude)
|
||||
h.app.GetLocalizerService().AddChangeCallback("help", func(text string) {
|
||||
help.Label = text
|
||||
help.Refresh()
|
||||
@@ -121,21 +101,15 @@ func (h MenuHandler) getMenuHelp() *fyne.Menu {
|
||||
func (h MenuHandler) openAbout() {
|
||||
ffmpeg, err := h.convertorHandler.GetFfmpegVersion()
|
||||
if err != nil {
|
||||
ffmpeg = h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "errorFFmpegVersion",
|
||||
})
|
||||
ffmpeg = h.app.GetLocalizerService().GetMessage("errorFFmpegVersion")
|
||||
}
|
||||
ffprobe, err := h.convertorHandler.GetFfprobeVersion()
|
||||
if err != nil {
|
||||
ffprobe = h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "errorFFprobeVersion",
|
||||
})
|
||||
ffprobe = h.app.GetLocalizerService().GetMessage("errorFFprobeVersion")
|
||||
}
|
||||
ffplay, err := h.convertorHandler.GetFfplayVersion()
|
||||
if err != nil {
|
||||
ffplay = h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "errorFFplayVersion",
|
||||
})
|
||||
ffplay = h.app.GetLocalizerService().GetMessage("errorFFplayVersion")
|
||||
}
|
||||
|
||||
h.menuView.About(ffmpeg, ffprobe, ffplay)
|
||||
@@ -143,18 +117,16 @@ func (h MenuHandler) openAbout() {
|
||||
|
||||
func (h MenuHandler) LanguageSelection() {
|
||||
h.localizerView.LanguageSelection(func(lang kernel.Lang) {
|
||||
_ = h.localizerRepository.Save(lang.Code)
|
||||
h.convertorHandler.MainConvertor()
|
||||
})
|
||||
}
|
||||
|
||||
func (h MenuHandler) settingsSelection() {
|
||||
save := func(setting *menu.SettingForm) error {
|
||||
err := h.app.GetLocalizerService().SetCurrentLanguage(setting.Language)
|
||||
err := h.app.GetLocalizerService().SetCurrentLanguage(setting.Language, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_ = h.localizerRepository.Save(setting.Language.Code)
|
||||
|
||||
err = h.themeService.SetCurrentTheme(setting.ThemeInfo)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user