diff --git a/modules/client/client.otmod b/modules/client/client.otmod index 30f9501c..903f38fd 100644 --- a/modules/client/client.otmod +++ b/modules/client/client.otmod @@ -9,6 +9,7 @@ Module load-later: - client_topmenu + - client_locales - client_background //- client_about - client_options diff --git a/modules/client_entergame/entergame.otui b/modules/client_entergame/entergame.otui index 756786d6..a3e93ee1 100644 --- a/modules/client_entergame/entergame.otui +++ b/modules/client_entergame/entergame.otui @@ -9,6 +9,7 @@ MainWindow text: Account name anchors.left: parent.left anchors.top: parent.top + text-auto-resize: true TextEdit id: accountNameTextEdit @@ -22,6 +23,7 @@ MainWindow anchors.left: prev.left anchors.top: prev.bottom margin-top: 8 + text-auto-resize: true PasswordTextEdit id: accountPasswordTextEdit @@ -32,11 +34,11 @@ MainWindow Label id: serverLabel - width: 140 text: Server anchors.left: prev.left anchors.top: prev.bottom margin-top: 8 + text-auto-resize: true TextEdit id: serverHostTextEdit @@ -44,25 +46,25 @@ MainWindow Make sure that your client uses the correct game protocol version anchors.left: serverLabel.left - anchors.right: serverLabel.right anchors.top: serverLabel.bottom margin-top: 2 + width: 140 Label id: portLabel text: Port - width: 50 - anchors.left: serverLabel.right + anchors.left: serverHostTextEdit.right anchors.top: serverLabel.top margin-left: 10 + text-auto-resize: true TextEdit id: serverPortTextEdit text: 7171 anchors.left: portLabel.left - anchors.right: portLabel.right anchors.top: portLabel.bottom margin-top: 2 + width: 55 CheckBox id: rememberPasswordBox diff --git a/modules/client_locales/en-us.lua b/modules/client_locales/en-us.lua new file mode 100644 index 00000000..374ac6d0 --- /dev/null +++ b/modules/client_locales/en-us.lua @@ -0,0 +1,8 @@ +locale = { + name = 'en-us', + + -- Translations not needed. en-us is already default. + translation = {} +} + +Locales.installLocale(locale) \ No newline at end of file diff --git a/modules/client_locales/locales.lua b/modules/client_locales/locales.lua new file mode 100644 index 00000000..ab833d92 --- /dev/null +++ b/modules/client_locales/locales.lua @@ -0,0 +1,81 @@ +Locales = { } + +-- private variables +local defaultLocaleName = 'en-us' +local installedLocales +local currentLocale + +-- hooked functions +function UIWidget:onTextChange(text, oldText) + local translation = tr(text) + if translation ~= text then + self:setText(translation) + end +end + +-- public functions +function Locales.init() + installedLocales = {} + + dofile('en-us') + dofile('pt-br') + + local userLocaleName = Settings.get('locale') + if not userLocaleName or not Locales.setLocale(userLocaleName) then + print('Locale ' .. userLocaleName .. ' is not loaded. Using default. ' .. defaultLocaleName) + if not Locales.setLocale(defaultLocaleName) then + fatal('Default locale could not be loaded. Re-install the program.') + return + end + Settings.set('locale', defaultLocaleName) + end + + -- create combobox + --for key,value in pairs(installedLocales) do + -- add elements + --end +end + +function Locales.terminate() + installedLocales = nil + currentLocale = nil +end + +function Locales.installLocale(locale) + if not locale then + print('Coult not install locale.') + return false + end + + if not locale.name then + printf('Coult not install locale.') + return false + end + + installedLocales[locale.name] = locale +end + +function Locales.setLocale(name) + local locale = installedLocales[name] + if locale then + currentLocale = locale + return true + end + + print("Locale " .. name .. ' does not exist.') + return false +end + +function tr(text, ...) + if currentLocale then + if tonumber(text) then + -- todo: add some dots etc + elseif tostring(text) then + local translation = currentLocale.translation[text] + if translation then + return string.format(translation, ...) + end + end + end + return text +end \ No newline at end of file diff --git a/modules/client_locales/locales.otmod b/modules/client_locales/locales.otmod new file mode 100644 index 00000000..bd6cccb2 --- /dev/null +++ b/modules/client_locales/locales.otmod @@ -0,0 +1,15 @@ +Module + name: client_locales + description: Translates texts to selected language + author: OTClient team + website: https://github.com/edubart/otclient + + dependencies: + - client_topmenu + + @onLoad: | + dofile 'locales' + Locales.init() + + @onUnload: | + Locales.terminate() diff --git a/modules/client_locales/pt-br.lua b/modules/client_locales/pt-br.lua new file mode 100644 index 00000000..8713796d --- /dev/null +++ b/modules/client_locales/pt-br.lua @@ -0,0 +1,20 @@ +locale = { + name = 'pt-br', + + -- As traduções devem vir sempre em ordem alfabética. + translation = { + ['Account name'] = 'Nome da conta', + ['Auto login'] = 'Entrar automaticamente', + ['Cancel'] = 'Cancelar', + ['Enter Game'] = 'Entrar no Jogo', + ['Options'] = 'Opções', + ['Password'] = 'Senha', + ['Port'] = 'Porta', + ['Remember password'] = 'Lembrar senha', + ['Server'] = 'Servidor' + } + + -- Adicionar informações de números. 1.000 100,00 1.000,00 etc. +} + +Locales.installLocale(locale) \ No newline at end of file diff --git a/modules/client_options/options.lua b/modules/client_options/options.lua index 866ed752..21da8ae2 100644 --- a/modules/client_options/options.lua +++ b/modules/client_options/options.lua @@ -28,7 +28,7 @@ function Options.init() optionsWindow = displayUI('options.otui') optionsWindow:hide() - optionsButton = TopMenu.addLeftButton('optionsButton', 'Options (Ctrl+O)', 'options.png', Options.toggle) + optionsButton = TopMenu.addLeftButton('optionsButton', tr('Options') .. ' (Ctrl+O)', 'options.png', Options.toggle) optionsTabBar = optionsWindow:getChildById('optionsTabBar') optionsTabBar:setContentWidget(optionsWindow:getChildById('optionsTabContent')) optionsTabBar:addTab('General', loadUI('general.otui'))