From ca0e1bd38b4cb4458baafc149a153e01227cecec Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Thu, 26 Apr 2012 13:45:25 -0300 Subject: [PATCH] more locales changes --- modules/client_entergame/characterlist.otui | 12 +++--- modules/client_entergame/entergame.otui | 26 ++++++------ modules/client_locales/locales.lua | 42 +++++++++++++------ .../client_locales/{ => locales}/en-us.lua | 0 modules/client_locales/locales/pt-br.lua | 26 ++++++++++++ modules/client_locales/pt-br.lua | 20 --------- modules/game_skills/skills.lua | 21 ++-------- 7 files changed, 76 insertions(+), 71 deletions(-) rename modules/client_locales/{ => locales}/en-us.lua (100%) create mode 100644 modules/client_locales/locales/pt-br.lua delete mode 100644 modules/client_locales/pt-br.lua diff --git a/modules/client_entergame/characterlist.otui b/modules/client_entergame/characterlist.otui index 237e8e5e..71009b6d 100644 --- a/modules/client_entergame/characterlist.otui +++ b/modules/client_entergame/characterlist.otui @@ -10,7 +10,7 @@ CharacterListLabel < Label MainWindow id: charactersWindow - text: Character List + !text: tr('Character List') size: 250 248 @onEnter: CharacterList.doLogin() @onEscape: CharacterList.destroy() @@ -34,9 +34,7 @@ MainWindow Label id: accountStatusLabel - text: |- - Account Status: - Free Account + !text: tr('Account Status:\nFree Account') anchors.left: parent.left anchors.right: parent.right anchors.bottom: separator.top @@ -52,7 +50,7 @@ MainWindow //CheckBox // id: charAutoLoginBox - // text: Auto login + // !text: tr('Auto login') // tooltip: Auto login selected character on next charlist load // anchors.left: parent.left // anchors.right: parent.right @@ -63,7 +61,7 @@ MainWindow Button id: buttonOk - text: Ok + !text: tr('Ok') width: 64 anchors.right: next.left anchors.bottom: parent.bottom @@ -72,7 +70,7 @@ MainWindow Button id: buttonCancel - text: Cancel + !text: tr('Cancel') width: 64 anchors.right: parent.right anchors.bottom: parent.bottom diff --git a/modules/client_entergame/entergame.otui b/modules/client_entergame/entergame.otui index a3e93ee1..a204b7a3 100644 --- a/modules/client_entergame/entergame.otui +++ b/modules/client_entergame/entergame.otui @@ -1,12 +1,12 @@ MainWindow id: enterGame - text: Enter Game + !text: tr('Enter Game') size: 236 240 @onEnter: EnterGame.doLogin() @onEscape: EnterGame.hide() Label - text: Account name + !text: tr('Account name') anchors.left: parent.left anchors.top: parent.top text-auto-resize: true @@ -19,7 +19,7 @@ MainWindow margin-top: 2 Label - text: Password + !text: tr('Password') anchors.left: prev.left anchors.top: prev.bottom margin-top: 8 @@ -34,7 +34,7 @@ MainWindow Label id: serverLabel - text: Server + !text: tr('Server') anchors.left: prev.left anchors.top: prev.bottom margin-top: 8 @@ -42,9 +42,7 @@ MainWindow TextEdit id: serverHostTextEdit - tooltip: |- - Make sure that your client uses - the correct game protocol version + !tooltip: tr('Make sure that your client uses\nthe correct game protocol version') anchors.left: serverLabel.left anchors.top: serverLabel.bottom margin-top: 2 @@ -52,7 +50,7 @@ MainWindow Label id: portLabel - text: Port + !text: tr('Port') anchors.left: serverHostTextEdit.right anchors.top: serverLabel.top margin-left: 10 @@ -68,8 +66,8 @@ MainWindow CheckBox id: rememberPasswordBox - text: Remember password - tooltip: Remember account and password when starts otclient + !text: tr('Remember password') + !tooltip: tr('Remember account and password when starts otclient') anchors.left: parent.left anchors.right: parent.right anchors.top: prev.bottom @@ -79,15 +77,15 @@ MainWindow CheckBox id: autoLoginBox enabled: false - text: Auto login - tooltip: Open charlist automatically when starting otclient + !text: tr('Auto login') + !tooltip: tr('Open charlist automatically when starting otclient') anchors.left: parent.left anchors.right: parent.right anchors.top: prev.bottom margin-top: 2 Button - text: Ok + !text: tr('Ok') width: 64 anchors.right: next.left anchors.bottom: parent.bottom @@ -95,7 +93,7 @@ MainWindow @onClick: EnterGame.doLogin() Button - text: Cancel + !text: tr('Cancel') width: 64 anchors.right: parent.right anchors.bottom: parent.bottom diff --git a/modules/client_locales/locales.lua b/modules/client_locales/locales.lua index ab833d92..c45cf9e0 100644 --- a/modules/client_locales/locales.lua +++ b/modules/client_locales/locales.lua @@ -5,20 +5,11 @@ 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') + Locales.installLocales('locales') local userLocaleName = Settings.get('locale') if not userLocaleName or not Locales.setLocale(userLocaleName) then @@ -30,7 +21,7 @@ function Locales.init() Settings.set('locale', defaultLocaleName) end - -- create combobox + -- add event for creating combobox --for key,value in pairs(installedLocales) do -- add elements --end @@ -52,7 +43,21 @@ function Locales.installLocale(locale) return false end - installedLocales[locale.name] = locale + local installedLocale = installedLocales[locale.name] + if installedLocale then + -- combine translations replacing with new if already exists + for word,translation in pairs(locale.translation) do + installedLocale.translation[word] = translation + end + else + installedLocales[locale.name] = locale + + -- update combobox + end +end + +function Locales.installLocales(directory) + dofiles(directory) end function Locales.setLocale(name) @@ -69,11 +74,22 @@ end function tr(text, ...) if currentLocale then if tonumber(text) then - -- todo: add some dots etc + -- todo: use locale information to calculate this. also detect floating numbers + local out = '' + local number = tostring(text):reverse() + for i=1,#number do + out = out .. number:sub(i, i) + if i % 3 == 0 and i ~= #number then + out = out .. ',' + end + end + return out:reverse() elseif tostring(text) then local translation = currentLocale.translation[text] if translation then return string.format(translation, ...) + elseif currentLocale.name ~= defaultLocaleName then + print('WARNING: \"' .. text .. '\" could not be translated.') end end end diff --git a/modules/client_locales/en-us.lua b/modules/client_locales/locales/en-us.lua similarity index 100% rename from modules/client_locales/en-us.lua rename to modules/client_locales/locales/en-us.lua diff --git a/modules/client_locales/locales/pt-br.lua b/modules/client_locales/locales/pt-br.lua new file mode 100644 index 00000000..8dc8bfd9 --- /dev/null +++ b/modules/client_locales/locales/pt-br.lua @@ -0,0 +1,26 @@ +locale = { + name = 'pt-br', + + -- As traduções devem vir sempre em ordem alfabética. + translation = { + ['Account name'] = 'Nome da conta', + ['Account Status:\nFree Account'] = 'Estado da Conta:\nGrátis', + ['Auto login'] = 'Entrar automaticamente', + ['Cancel'] = 'Cancelar', + ['Character List'] = 'Lista de Personagens', + ['Enter Game'] = 'Entrar no Jogo', + ['Make sure that your client uses\nthe correct game protocol version'] = 'Tenha certeza de que o cliente usa\na versão correta do protocolo do jogo', + ['Ok'] = 'Ok', + ['Open charlist automatically when starting otclient'] = 'Abrir a lista de personagens automaticamente ao iniciar o otclient', + ['Options'] = 'Opções', + ['Password'] = 'Senha', + ['Port'] = 'Porta', + ['Remember account and password when starts otclient'] = 'Lembrar conta e senha ao iniciar o otclient', + ['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_locales/pt-br.lua b/modules/client_locales/pt-br.lua deleted file mode 100644 index 8713796d..00000000 --- a/modules/client_locales/pt-br.lua +++ /dev/null @@ -1,20 +0,0 @@ -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/game_skills/skills.lua b/modules/game_skills/skills.lua index 0c99d39a..4ec6ff59 100644 --- a/modules/game_skills/skills.lua +++ b/modules/game_skills/skills.lua @@ -5,19 +5,6 @@ local skillsWindow local skillsButton -- private functions -local function getNumberString(number) - local out = '' - number = tostring(number):reverse() - for i=1,#number do - out = out .. number:sub(i, i) - if i % 3 == 0 and i ~= #number then - out = out .. ',' - end - end - out = out:reverse() - return out -end - local function setSkillValue(id, value) local skill = skillsWindow:recursiveGetChildById(id) local widget = skill:getChildById('value') @@ -94,20 +81,20 @@ end -- hooked events function Skills.onExperienceChange(localPlayer, value) - setSkillValue('experience', getNumberString(value)) + setSkillValue('experience', tr(value)) end function Skills.onLevelChange(localPlayer, value, percent) - setSkillValue('level', getNumberString(value)) + setSkillValue('level', tr(value)) setSkillPercent('level', percent, 'You have ' .. (100 - percent) .. ' percent to go') end function Skills.onHealthChange(localPlayer, health, maxHealth) - setSkillValue('health', getNumberString(health)) + setSkillValue('health', tr(health)) end function Skills.onManaChange(localPlayer, mana, maxMana) - setSkillValue('mana', getNumberString(mana)) + setSkillValue('mana', tr(mana)) end function Skills.onSoulChange(localPlayer, soul)