parent
60495174a4
commit
12d75a765b
@ -0,0 +1,8 @@
|
|||||||
|
locale = {
|
||||||
|
name = 'en-us',
|
||||||
|
|
||||||
|
-- Translations not needed. en-us is already default.
|
||||||
|
translation = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
Locales.installLocale(locale)
|
@ -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
|
@ -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()
|
@ -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)
|
Loading…
Reference in new issue