more locales changes

This commit is contained in:
Henrique Santiago 2012-04-26 13:45:25 -03:00
parent fae2cc6481
commit ca0e1bd38b
7 changed files with 76 additions and 71 deletions

View File

@ -10,7 +10,7 @@ CharacterListLabel < Label
MainWindow MainWindow
id: charactersWindow id: charactersWindow
text: Character List !text: tr('Character List')
size: 250 248 size: 250 248
@onEnter: CharacterList.doLogin() @onEnter: CharacterList.doLogin()
@onEscape: CharacterList.destroy() @onEscape: CharacterList.destroy()
@ -34,9 +34,7 @@ MainWindow
Label Label
id: accountStatusLabel id: accountStatusLabel
text: |- !text: tr('Account Status:\nFree Account')
Account Status:
Free Account
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.bottom: separator.top anchors.bottom: separator.top
@ -52,7 +50,7 @@ MainWindow
//CheckBox //CheckBox
// id: charAutoLoginBox // id: charAutoLoginBox
// text: Auto login // !text: tr('Auto login')
// tooltip: Auto login selected character on next charlist load // tooltip: Auto login selected character on next charlist load
// anchors.left: parent.left // anchors.left: parent.left
// anchors.right: parent.right // anchors.right: parent.right
@ -63,7 +61,7 @@ MainWindow
Button Button
id: buttonOk id: buttonOk
text: Ok !text: tr('Ok')
width: 64 width: 64
anchors.right: next.left anchors.right: next.left
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
@ -72,7 +70,7 @@ MainWindow
Button Button
id: buttonCancel id: buttonCancel
text: Cancel !text: tr('Cancel')
width: 64 width: 64
anchors.right: parent.right anchors.right: parent.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom

View File

@ -1,12 +1,12 @@
MainWindow MainWindow
id: enterGame id: enterGame
text: Enter Game !text: tr('Enter Game')
size: 236 240 size: 236 240
@onEnter: EnterGame.doLogin() @onEnter: EnterGame.doLogin()
@onEscape: EnterGame.hide() @onEscape: EnterGame.hide()
Label Label
text: Account name !text: tr('Account name')
anchors.left: parent.left anchors.left: parent.left
anchors.top: parent.top anchors.top: parent.top
text-auto-resize: true text-auto-resize: true
@ -19,7 +19,7 @@ MainWindow
margin-top: 2 margin-top: 2
Label Label
text: Password !text: tr('Password')
anchors.left: prev.left anchors.left: prev.left
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 8 margin-top: 8
@ -34,7 +34,7 @@ MainWindow
Label Label
id: serverLabel id: serverLabel
text: Server !text: tr('Server')
anchors.left: prev.left anchors.left: prev.left
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 8 margin-top: 8
@ -42,9 +42,7 @@ MainWindow
TextEdit TextEdit
id: serverHostTextEdit id: serverHostTextEdit
tooltip: |- !tooltip: tr('Make sure that your client uses\nthe correct game protocol version')
Make sure that your client uses
the correct game protocol version
anchors.left: serverLabel.left anchors.left: serverLabel.left
anchors.top: serverLabel.bottom anchors.top: serverLabel.bottom
margin-top: 2 margin-top: 2
@ -52,7 +50,7 @@ MainWindow
Label Label
id: portLabel id: portLabel
text: Port !text: tr('Port')
anchors.left: serverHostTextEdit.right anchors.left: serverHostTextEdit.right
anchors.top: serverLabel.top anchors.top: serverLabel.top
margin-left: 10 margin-left: 10
@ -68,8 +66,8 @@ MainWindow
CheckBox CheckBox
id: rememberPasswordBox id: rememberPasswordBox
text: Remember password !text: tr('Remember password')
tooltip: Remember account and password when starts otclient !tooltip: tr('Remember account and password when starts otclient')
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.top: prev.bottom anchors.top: prev.bottom
@ -79,15 +77,15 @@ MainWindow
CheckBox CheckBox
id: autoLoginBox id: autoLoginBox
enabled: false enabled: false
text: Auto login !text: tr('Auto login')
tooltip: Open charlist automatically when starting otclient !tooltip: tr('Open charlist automatically when starting otclient')
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 2 margin-top: 2
Button Button
text: Ok !text: tr('Ok')
width: 64 width: 64
anchors.right: next.left anchors.right: next.left
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
@ -95,7 +93,7 @@ MainWindow
@onClick: EnterGame.doLogin() @onClick: EnterGame.doLogin()
Button Button
text: Cancel !text: tr('Cancel')
width: 64 width: 64
anchors.right: parent.right anchors.right: parent.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom

View File

@ -5,20 +5,11 @@ local defaultLocaleName = 'en-us'
local installedLocales local installedLocales
local currentLocale local currentLocale
-- hooked functions
function UIWidget:onTextChange(text, oldText)
local translation = tr(text)
if translation ~= text then
self:setText(translation)
end
end
-- public functions -- public functions
function Locales.init() function Locales.init()
installedLocales = {} installedLocales = {}
dofile('en-us') Locales.installLocales('locales')
dofile('pt-br')
local userLocaleName = Settings.get('locale') local userLocaleName = Settings.get('locale')
if not userLocaleName or not Locales.setLocale(userLocaleName) then if not userLocaleName or not Locales.setLocale(userLocaleName) then
@ -30,7 +21,7 @@ function Locales.init()
Settings.set('locale', defaultLocaleName) Settings.set('locale', defaultLocaleName)
end end
-- create combobox -- add event for creating combobox
--for key,value in pairs(installedLocales) do --for key,value in pairs(installedLocales) do
-- add elements -- add elements
--end --end
@ -52,7 +43,21 @@ function Locales.installLocale(locale)
return false return false
end end
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 installedLocales[locale.name] = locale
-- update combobox
end
end
function Locales.installLocales(directory)
dofiles(directory)
end end
function Locales.setLocale(name) function Locales.setLocale(name)
@ -69,11 +74,22 @@ end
function tr(text, ...) function tr(text, ...)
if currentLocale then if currentLocale then
if tonumber(text) 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 elseif tostring(text) then
local translation = currentLocale.translation[text] local translation = currentLocale.translation[text]
if translation then if translation then
return string.format(translation, ...) return string.format(translation, ...)
elseif currentLocale.name ~= defaultLocaleName then
print('WARNING: \"' .. text .. '\" could not be translated.')
end end
end end
end end

View File

@ -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)

View File

@ -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)

View File

@ -5,19 +5,6 @@ local skillsWindow
local skillsButton local skillsButton
-- private functions -- 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 function setSkillValue(id, value)
local skill = skillsWindow:recursiveGetChildById(id) local skill = skillsWindow:recursiveGetChildById(id)
local widget = skill:getChildById('value') local widget = skill:getChildById('value')
@ -94,20 +81,20 @@ end
-- hooked events -- hooked events
function Skills.onExperienceChange(localPlayer, value) function Skills.onExperienceChange(localPlayer, value)
setSkillValue('experience', getNumberString(value)) setSkillValue('experience', tr(value))
end end
function Skills.onLevelChange(localPlayer, value, percent) function Skills.onLevelChange(localPlayer, value, percent)
setSkillValue('level', getNumberString(value)) setSkillValue('level', tr(value))
setSkillPercent('level', percent, 'You have ' .. (100 - percent) .. ' percent to go') setSkillPercent('level', percent, 'You have ' .. (100 - percent) .. ' percent to go')
end end
function Skills.onHealthChange(localPlayer, health, maxHealth) function Skills.onHealthChange(localPlayer, health, maxHealth)
setSkillValue('health', getNumberString(health)) setSkillValue('health', tr(health))
end end
function Skills.onManaChange(localPlayer, mana, maxMana) function Skills.onManaChange(localPlayer, mana, maxMana)
setSkillValue('mana', getNumberString(mana)) setSkillValue('mana', tr(mana))
end end
function Skills.onSoulChange(localPlayer, soul) function Skills.onSoulChange(localPlayer, soul)