The language selection is remembered.
Added a setting for changing the language.
This commit is contained in:
parent
5025807b14
commit
6358d5d8cc
@ -17,6 +17,9 @@ type ViewContract interface {
|
|||||||
Main(
|
Main(
|
||||||
runConvert func(setting HandleConvertSetting, progressbar *widget.ProgressBar) error,
|
runConvert func(setting HandleConvertSetting, progressbar *widget.ProgressBar) error,
|
||||||
)
|
)
|
||||||
|
SelectFFPath(
|
||||||
|
func(ffmpegPath string, ffprobePath string) error,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
type View struct {
|
type View struct {
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package setting
|
package convertor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"ffmpegGui/helper"
|
"ffmpegGui/helper"
|
||||||
"ffmpegGui/localizer"
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/canvas"
|
"fyne.io/fyne/v2/canvas"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
@ -13,22 +12,6 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ViewContract interface {
|
|
||||||
SelectFFPath(func(ffmpegPath string, ffprobePath string) error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type View struct {
|
|
||||||
w fyne.Window
|
|
||||||
localizerService localizer.ServiceContract
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewView(w fyne.Window, localizerService localizer.ServiceContract) *View {
|
|
||||||
return &View{
|
|
||||||
w: w,
|
|
||||||
localizerService: localizerService,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v View) SelectFFPath(save func(ffmpegPath string, ffprobePath string) error) {
|
func (v View) SelectFFPath(save func(ffmpegPath string, ffprobePath string) error) {
|
||||||
errorMessage := canvas.NewText("", color.RGBA{255, 0, 0, 255})
|
errorMessage := canvas.NewText("", color.RGBA{255, 0, 0, 255})
|
||||||
errorMessage.TextSize = 16
|
errorMessage.TextSize = 16
|
||||||
@ -124,13 +107,3 @@ func (v View) getButtonSelectFile() (filePath *string, button *widget.Button, bu
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func setStringErrorStyle(text *canvas.Text) {
|
|
||||||
text.Color = color.RGBA{255, 0, 0, 255}
|
|
||||||
text.Refresh()
|
|
||||||
}
|
|
||||||
|
|
||||||
func setStringSuccessStyle(text *canvas.Text) {
|
|
||||||
text.Color = color.RGBA{49, 127, 114, 255}
|
|
||||||
text.Refresh()
|
|
||||||
}
|
|
@ -15,11 +15,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ConvertorHandlerContract interface {
|
||||||
|
MainConvertor()
|
||||||
|
}
|
||||||
|
|
||||||
type ConvertorHandler struct {
|
type ConvertorHandler struct {
|
||||||
convertorService convertor.ServiceContract
|
convertorService convertor.ServiceContract
|
||||||
convertorView convertor.ViewContract
|
convertorView convertor.ViewContract
|
||||||
settingView setting.ViewContract
|
|
||||||
localizerView localizer.ViewContract
|
|
||||||
settingRepository setting.RepositoryContract
|
settingRepository setting.RepositoryContract
|
||||||
localizerService localizer.ServiceContract
|
localizerService localizer.ServiceContract
|
||||||
}
|
}
|
||||||
@ -27,33 +29,23 @@ type ConvertorHandler struct {
|
|||||||
func NewConvertorHandler(
|
func NewConvertorHandler(
|
||||||
convertorService convertor.ServiceContract,
|
convertorService convertor.ServiceContract,
|
||||||
convertorView convertor.ViewContract,
|
convertorView convertor.ViewContract,
|
||||||
settingView setting.ViewContract,
|
|
||||||
localizerView localizer.ViewContract,
|
|
||||||
settingRepository setting.RepositoryContract,
|
settingRepository setting.RepositoryContract,
|
||||||
localizerService localizer.ServiceContract,
|
localizerService localizer.ServiceContract,
|
||||||
) *ConvertorHandler {
|
) *ConvertorHandler {
|
||||||
return &ConvertorHandler{
|
return &ConvertorHandler{
|
||||||
convertorService: convertorService,
|
convertorService: convertorService,
|
||||||
convertorView: convertorView,
|
convertorView: convertorView,
|
||||||
settingView: settingView,
|
|
||||||
localizerView: localizerView,
|
|
||||||
settingRepository: settingRepository,
|
settingRepository: settingRepository,
|
||||||
localizerService: localizerService,
|
localizerService: localizerService,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h ConvertorHandler) LanguageSelection() {
|
func (h ConvertorHandler) MainConvertor() {
|
||||||
h.localizerView.LanguageSelection(func(lang localizer.Lang) {
|
|
||||||
h.GetConvertor()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h ConvertorHandler) GetConvertor() {
|
|
||||||
if h.checkingFFPathUtilities() == true {
|
if h.checkingFFPathUtilities() == true {
|
||||||
h.convertorView.Main(h.runConvert)
|
h.convertorView.Main(h.runConvert)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
h.settingView.SelectFFPath(h.saveSettingFFPath)
|
h.convertorView.SelectFFPath(h.saveSettingFFPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h ConvertorHandler) runConvert(setting convertor.HandleConvertSetting, progressbar *widget.ProgressBar) error {
|
func (h ConvertorHandler) runConvert(setting convertor.HandleConvertSetting, progressbar *widget.ProgressBar) error {
|
||||||
@ -124,7 +116,7 @@ func (h ConvertorHandler) saveSettingFFPath(ffmpegPath string, ffprobePath strin
|
|||||||
ffprobeEntity := setting.Setting{Code: "ffprobe", Value: ffprobePath}
|
ffprobeEntity := setting.Setting{Code: "ffprobe", Value: ffprobePath}
|
||||||
_, _ = h.settingRepository.Create(ffprobeEntity)
|
_, _ = h.settingRepository.Create(ffprobeEntity)
|
||||||
|
|
||||||
h.GetConvertor()
|
h.MainConvertor()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
37
src/handler/main.go
Normal file
37
src/handler/main.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ffmpegGui/localizer"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MainHandler struct {
|
||||||
|
convertorHandler ConvertorHandlerContract
|
||||||
|
menuHandler MenuHandlerContract
|
||||||
|
localizerRepository localizer.RepositoryContract
|
||||||
|
localizerService localizer.ServiceContract
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMainHandler(
|
||||||
|
convertorHandler ConvertorHandlerContract,
|
||||||
|
menuHandler MenuHandlerContract,
|
||||||
|
localizerRepository localizer.RepositoryContract,
|
||||||
|
localizerService localizer.ServiceContract,
|
||||||
|
) *MainHandler {
|
||||||
|
return &MainHandler{
|
||||||
|
convertorHandler: convertorHandler,
|
||||||
|
menuHandler: menuHandler,
|
||||||
|
localizerRepository: localizerRepository,
|
||||||
|
localizerService: localizerService,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h MainHandler) Start() {
|
||||||
|
language, err := h.localizerRepository.GetCode()
|
||||||
|
if err != nil {
|
||||||
|
h.menuHandler.LanguageSelection()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_ = h.localizerService.SetCurrentLanguageByCode(language)
|
||||||
|
|
||||||
|
h.convertorHandler.MainConvertor()
|
||||||
|
}
|
78
src/handler/menu.go
Normal file
78
src/handler/menu.go
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ffmpegGui/localizer"
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MenuHandlerContract interface {
|
||||||
|
GetMainMenu() *fyne.MainMenu
|
||||||
|
LanguageSelection()
|
||||||
|
}
|
||||||
|
|
||||||
|
type menuItems struct {
|
||||||
|
menuItem map[string]*fyne.MenuItem
|
||||||
|
menu map[string]*fyne.Menu
|
||||||
|
}
|
||||||
|
|
||||||
|
type MenuHandler struct {
|
||||||
|
convertorHandler ConvertorHandlerContract
|
||||||
|
localizerService localizer.ServiceContract
|
||||||
|
localizerView localizer.ViewContract
|
||||||
|
localizerRepository localizer.RepositoryContract
|
||||||
|
menuItems *menuItems
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMenuHandler(
|
||||||
|
convertorHandler ConvertorHandlerContract,
|
||||||
|
localizerService localizer.ServiceContract,
|
||||||
|
localizerView localizer.ViewContract,
|
||||||
|
localizerRepository localizer.RepositoryContract,
|
||||||
|
) *MenuHandler {
|
||||||
|
return &MenuHandler{
|
||||||
|
convertorHandler: convertorHandler,
|
||||||
|
localizerService: localizerService,
|
||||||
|
localizerView: localizerView,
|
||||||
|
localizerRepository: localizerRepository,
|
||||||
|
menuItems: &menuItems{menuItem: map[string]*fyne.MenuItem{}, menu: map[string]*fyne.Menu{}},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h MenuHandler) GetMainMenu() *fyne.MainMenu {
|
||||||
|
quit := fyne.NewMenuItem(h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||||
|
MessageID: "exit",
|
||||||
|
}), nil)
|
||||||
|
quit.IsQuit = true
|
||||||
|
h.menuItems.menuItem["exit"] = quit
|
||||||
|
|
||||||
|
languageSelection := fyne.NewMenuItem(h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||||
|
MessageID: "changeLanguage",
|
||||||
|
}), h.LanguageSelection)
|
||||||
|
h.menuItems.menuItem["changeLanguage"] = languageSelection
|
||||||
|
|
||||||
|
settings := fyne.NewMenu(h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||||
|
MessageID: "settings",
|
||||||
|
}), languageSelection, quit)
|
||||||
|
h.menuItems.menu["settings"] = settings
|
||||||
|
|
||||||
|
return fyne.NewMainMenu(settings)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h MenuHandler) LanguageSelection() {
|
||||||
|
h.localizerView.LanguageSelection(func(lang localizer.Lang) {
|
||||||
|
h.localizerRepository.Save(lang.Code)
|
||||||
|
h.menuMessageReload()
|
||||||
|
h.convertorHandler.MainConvertor()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h MenuHandler) menuMessageReload() {
|
||||||
|
for messageID, menu := range h.menuItems.menuItem {
|
||||||
|
menu.Label = h.localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: messageID})
|
||||||
|
}
|
||||||
|
for messageID, menu := range h.menuItems.menu {
|
||||||
|
menu.Label = h.localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: messageID})
|
||||||
|
menu.Refresh()
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,10 @@
|
|||||||
hash = "sha1-52b13f1b13e82d22e8c4102332db5d4ec551247b"
|
hash = "sha1-52b13f1b13e82d22e8c4102332db5d4ec551247b"
|
||||||
other = "Folder where it will be saved:"
|
other = "Folder where it will be saved:"
|
||||||
|
|
||||||
|
[changeLanguage]
|
||||||
|
hash = "sha1-8b276eaf378d485c769fb3d5dcc06dfc25b0c01b"
|
||||||
|
other = "Change language"
|
||||||
|
|
||||||
[checkboxOverwriteOutputFilesTitle]
|
[checkboxOverwriteOutputFilesTitle]
|
||||||
hash = "sha1-5860124bb781e7ef680f573fa93977e96328d4e7"
|
hash = "sha1-5860124bb781e7ef680f573fa93977e96328d4e7"
|
||||||
other = "Allow file to be overwritten"
|
other = "Allow file to be overwritten"
|
||||||
@ -42,6 +46,10 @@ other = "this is not FFprobe"
|
|||||||
hash = "sha1-83da899677cdc90e4344e3b94ee03c46b51bee4c"
|
hash = "sha1-83da899677cdc90e4344e3b94ee03c46b51bee4c"
|
||||||
other = "You haven't selected a folder to save!"
|
other = "You haven't selected a folder to save!"
|
||||||
|
|
||||||
|
[exit]
|
||||||
|
hash = "sha1-c42457057d1ab7950cea00719cbe0b078891775f"
|
||||||
|
other = "Exit"
|
||||||
|
|
||||||
[fileVideoForConversionTitle]
|
[fileVideoForConversionTitle]
|
||||||
hash = "sha1-5e727d4a2ff3f21080e51e81641595b2e668f3be"
|
hash = "sha1-5e727d4a2ff3f21080e51e81641595b2e668f3be"
|
||||||
other = "File for conversion:"
|
other = "File for conversion:"
|
||||||
@ -70,6 +78,10 @@ other = "Save"
|
|||||||
hash = "sha1-95581446a28d968ff1a027c623159a7eb08654cf"
|
hash = "sha1-95581446a28d968ff1a027c623159a7eb08654cf"
|
||||||
other = "Specify the path to FFmpeg and FFprobe"
|
other = "Specify the path to FFmpeg and FFprobe"
|
||||||
|
|
||||||
|
[settings]
|
||||||
|
hash = "sha1-7f17c7c62a7fd8d1a508481f4778688927734c2f"
|
||||||
|
other = "Settings"
|
||||||
|
|
||||||
[titleDownloadLink]
|
[titleDownloadLink]
|
||||||
hash = "sha1-92df86371f6c3a06ca1e4754f113142776a32d49"
|
hash = "sha1-92df86371f6c3a06ca1e4754f113142776a32d49"
|
||||||
other = "You can download it from here"
|
other = "You can download it from here"
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
hash = "sha1-52b13f1b13e82d22e8c4102332db5d4ec551247b"
|
hash = "sha1-52b13f1b13e82d22e8c4102332db5d4ec551247b"
|
||||||
other = "Файлды сақтауға арналған каталог:"
|
other = "Файлды сақтауға арналған каталог:"
|
||||||
|
|
||||||
|
[changeLanguage]
|
||||||
|
hash = "sha1-8b276eaf378d485c769fb3d5dcc06dfc25b0c01b"
|
||||||
|
other = "Тілді өзгерту"
|
||||||
|
|
||||||
[checkboxOverwriteOutputFilesTitle]
|
[checkboxOverwriteOutputFilesTitle]
|
||||||
hash = "sha1-5860124bb781e7ef680f573fa93977e96328d4e7"
|
hash = "sha1-5860124bb781e7ef680f573fa93977e96328d4e7"
|
||||||
other = "Файлды қайта жазуға рұқсат беріңіз"
|
other = "Файлды қайта жазуға рұқсат беріңіз"
|
||||||
@ -42,6 +46,10 @@ other = "бұл FFprobe емес"
|
|||||||
hash = "sha1-83da899677cdc90e4344e3b94ee03c46b51bee4c"
|
hash = "sha1-83da899677cdc90e4344e3b94ee03c46b51bee4c"
|
||||||
other = "Сіз сақталатын қалтаны таңдамадыңыз!"
|
other = "Сіз сақталатын қалтаны таңдамадыңыз!"
|
||||||
|
|
||||||
|
[exit]
|
||||||
|
hash = "sha1-c42457057d1ab7950cea00719cbe0b078891775f"
|
||||||
|
other = "Шығу"
|
||||||
|
|
||||||
[fileVideoForConversionTitle]
|
[fileVideoForConversionTitle]
|
||||||
hash = "sha1-5e727d4a2ff3f21080e51e81641595b2e668f3be"
|
hash = "sha1-5e727d4a2ff3f21080e51e81641595b2e668f3be"
|
||||||
other = "Түрлендіруге арналған файл:"
|
other = "Түрлендіруге арналған файл:"
|
||||||
@ -70,6 +78,10 @@ other = "Сақтау"
|
|||||||
hash = "sha1-95581446a28d968ff1a027c623159a7eb08654cf"
|
hash = "sha1-95581446a28d968ff1a027c623159a7eb08654cf"
|
||||||
other = "FFmpeg және FFprobe жолын көрсетіңіз"
|
other = "FFmpeg және FFprobe жолын көрсетіңіз"
|
||||||
|
|
||||||
|
[settings]
|
||||||
|
hash = "sha1-7f17c7c62a7fd8d1a508481f4778688927734c2f"
|
||||||
|
other = "Параметрлер"
|
||||||
|
|
||||||
[titleDownloadLink]
|
[titleDownloadLink]
|
||||||
hash = "sha1-92df86371f6c3a06ca1e4754f113142776a32d49"
|
hash = "sha1-92df86371f6c3a06ca1e4754f113142776a32d49"
|
||||||
other = "Сіз оны осы жерден жүктей аласыз"
|
other = "Сіз оны осы жерден жүктей аласыз"
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
buttonForSelectedDirTitle = "Папка куда будет сохраняться:"
|
buttonForSelectedDirTitle = "Папка куда будет сохраняться:"
|
||||||
|
changeLanguage = "Поменять язык"
|
||||||
checkboxOverwriteOutputFilesTitle = "Разрешить перезаписать файл"
|
checkboxOverwriteOutputFilesTitle = "Разрешить перезаписать файл"
|
||||||
choose = "выбрать"
|
choose = "выбрать"
|
||||||
converterVideoFilesSubmitTitle = "Конвертировать"
|
converterVideoFilesSubmitTitle = "Конвертировать"
|
||||||
@ -9,6 +10,7 @@ errorDatabase = "не смогли создать файл 'database' в пап
|
|||||||
errorFFmpeg = "это не FFmpeg"
|
errorFFmpeg = "это не FFmpeg"
|
||||||
errorFFprobe = "это не FFprobe"
|
errorFFprobe = "это не FFprobe"
|
||||||
errorSelectedFolderSave = "Не выбрали папку для сохранения!"
|
errorSelectedFolderSave = "Не выбрали папку для сохранения!"
|
||||||
|
exit = "Выход"
|
||||||
fileVideoForConversionTitle = "Файл для ковертации:"
|
fileVideoForConversionTitle = "Файл для ковертации:"
|
||||||
languageSelectionFormHead = "Переключить язык"
|
languageSelectionFormHead = "Переключить язык"
|
||||||
languageSelectionHead = "Выберите язык"
|
languageSelectionHead = "Выберите язык"
|
||||||
@ -16,4 +18,5 @@ pathToFfmpeg = "Путь к ffmpeg:"
|
|||||||
pathToFfprobe = "Путь к ffprobe:"
|
pathToFfprobe = "Путь к ffprobe:"
|
||||||
save = "Сохранить"
|
save = "Сохранить"
|
||||||
selectFFPathTitle = "Укажите путь к FFmpeg и к FFprobe"
|
selectFFPathTitle = "Укажите путь к FFmpeg и к FFprobe"
|
||||||
|
settings = "Настройки"
|
||||||
titleDownloadLink = "Скачать можно от сюда"
|
titleDownloadLink = "Скачать можно от сюда"
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
[changeLanguage]
|
||||||
|
hash = "sha1-8b276eaf378d485c769fb3d5dcc06dfc25b0c01b"
|
||||||
|
other = "Change language"
|
||||||
|
|
||||||
|
[exit]
|
||||||
|
hash = "sha1-c42457057d1ab7950cea00719cbe0b078891775f"
|
||||||
|
other = "Exit"
|
||||||
|
|
||||||
|
[settings]
|
||||||
|
hash = "sha1-7f17c7c62a7fd8d1a508481f4778688927734c2f"
|
||||||
|
other = "Settings"
|
@ -0,0 +1,11 @@
|
|||||||
|
[changeLanguage]
|
||||||
|
hash = "sha1-8b276eaf378d485c769fb3d5dcc06dfc25b0c01b"
|
||||||
|
other = "Тілді өзгерту"
|
||||||
|
|
||||||
|
[exit]
|
||||||
|
hash = "sha1-c42457057d1ab7950cea00719cbe0b078891775f"
|
||||||
|
other = "Шығу"
|
||||||
|
|
||||||
|
[settings]
|
||||||
|
hash = "sha1-7f17c7c62a7fd8d1a508481f4778688927734c2f"
|
||||||
|
other = "Параметрлер"
|
26
src/localizer/repository.go
Normal file
26
src/localizer/repository.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package localizer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ffmpegGui/setting"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RepositoryContract interface {
|
||||||
|
GetCode() (string, error)
|
||||||
|
Save(code string) (setting.Setting, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Repository struct {
|
||||||
|
settingRepository setting.RepositoryContract
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRepository(settingRepository setting.RepositoryContract) *Repository {
|
||||||
|
return &Repository{settingRepository: settingRepository}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Repository) GetCode() (string, error) {
|
||||||
|
return r.settingRepository.GetValue("language")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Repository) Save(code string) (setting.Setting, error) {
|
||||||
|
return r.settingRepository.CreateOrUpdate("language", code)
|
||||||
|
}
|
@ -14,6 +14,7 @@ type ServiceContract interface {
|
|||||||
GetLanguages() []Lang
|
GetLanguages() []Lang
|
||||||
GetMessage(localizeConfig *i18n.LocalizeConfig) string
|
GetMessage(localizeConfig *i18n.LocalizeConfig) string
|
||||||
SetCurrentLanguage(lang Lang) error
|
SetCurrentLanguage(lang Lang) error
|
||||||
|
SetCurrentLanguageByCode(code string) error
|
||||||
GetCurrentLanguage() *CurrentLanguage
|
GetCurrentLanguage() *CurrentLanguage
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,6 +102,16 @@ func (s Service) SetCurrentLanguage(lang Lang) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s Service) SetCurrentLanguageByCode(code string) error {
|
||||||
|
language, err := language.Parse(code)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
title := cases.Title(language).String(display.Self.Name(language))
|
||||||
|
lang := Lang{Code: language.String(), Title: title}
|
||||||
|
return s.SetCurrentLanguage(lang)
|
||||||
|
}
|
||||||
|
|
||||||
func (s Service) GetCurrentLanguage() *CurrentLanguage {
|
func (s Service) GetCurrentLanguage() *CurrentLanguage {
|
||||||
return s.currentLanguage
|
return s.currentLanguage
|
||||||
}
|
}
|
||||||
|
11
src/main.go
11
src/main.go
@ -79,12 +79,17 @@ func main() {
|
|||||||
|
|
||||||
localizerView := localizer.NewView(w, localizerService)
|
localizerView := localizer.NewView(w, localizerService)
|
||||||
convertorView := convertor.NewView(w, localizerService)
|
convertorView := convertor.NewView(w, localizerService)
|
||||||
settingView := setting.NewView(w, localizerService)
|
|
||||||
convertorService := convertor.NewService(ffPathUtilities)
|
convertorService := convertor.NewService(ffPathUtilities)
|
||||||
defer appCloseWithConvert(convertorService)
|
defer appCloseWithConvert(convertorService)
|
||||||
mainHandler := handler.NewConvertorHandler(convertorService, convertorView, settingView, localizerView, settingRepository, localizerService)
|
convertorHandler := handler.NewConvertorHandler(convertorService, convertorView, settingRepository, localizerService)
|
||||||
|
|
||||||
mainHandler.LanguageSelection()
|
localizerRepository := localizer.NewRepository(settingRepository)
|
||||||
|
mainMenu := handler.NewMenuHandler(convertorHandler, localizerService, localizerView, localizerRepository)
|
||||||
|
|
||||||
|
mainHandler := handler.NewMainHandler(convertorHandler, mainMenu, localizerRepository, localizerService)
|
||||||
|
mainHandler.Start()
|
||||||
|
|
||||||
|
w.SetMainMenu(mainMenu.GetMainMenu())
|
||||||
|
|
||||||
w.ShowAndRun()
|
w.ShowAndRun()
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package setting
|
package setting
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RepositoryContract interface {
|
type RepositoryContract interface {
|
||||||
Create(setting Setting) (Setting, error)
|
Create(setting Setting) (Setting, error)
|
||||||
|
CreateOrUpdate(code string, value string) (Setting, error)
|
||||||
GetValue(code string) (value string, err error)
|
GetValue(code string) (value string, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,3 +35,21 @@ func (r Repository) Create(setting Setting) (Setting, error) {
|
|||||||
}
|
}
|
||||||
return setting, err
|
return setting, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r Repository) CreateOrUpdate(code string, value string) (Setting, error) {
|
||||||
|
var setting Setting
|
||||||
|
err := r.db.Where("code = ?", code).First(&setting).Error
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) == true {
|
||||||
|
setting = Setting{Code: code, Value: value}
|
||||||
|
return r.Create(setting)
|
||||||
|
} else {
|
||||||
|
return setting, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = r.db.Model(&setting).UpdateColumn("value", value).Error
|
||||||
|
if err != nil {
|
||||||
|
return setting, err
|
||||||
|
}
|
||||||
|
return setting, err
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user