lang: update translation system
This commit is contained in:
parent
37b6613c4a
commit
b801c59a62
1 changed files with 42 additions and 0 deletions
|
@ -76,4 +76,46 @@ function LanguageManager:getCurrentLangName()
|
|||
return self:getLangName(self.data.current)
|
||||
end
|
||||
|
||||
-- TRANSLATION FUNCTIONS
|
||||
-- get the translation of a string
|
||||
|
||||
function LanguageManager:getTranslationStringList(lang, library)
|
||||
local _path = self.data.path .. lang .. "/" .. library
|
||||
local fileinfo = love.filesystem.getInfo(_path .. ".lua")
|
||||
local list = nil
|
||||
|
||||
if fileinfo ~= nil then
|
||||
list = require(_path)
|
||||
else
|
||||
print("WARNING: file " .. _path .. " do not exists")
|
||||
end
|
||||
|
||||
return list
|
||||
end
|
||||
|
||||
function LanguageManager:translateFromLang(lang, library, stringToTranslate)
|
||||
local _stringlist = self:getTranslationStringList(lang, library)
|
||||
|
||||
if _stringlist == nil then
|
||||
return nil
|
||||
else
|
||||
return _stringlist[stringToTranslate]
|
||||
end
|
||||
end
|
||||
|
||||
function LanguageManager:translate(library, string)
|
||||
local translation = self:translateFromLang(self.data.current, library, string)
|
||||
|
||||
if (translation == nil) then
|
||||
translation = self:translateFromLang(self.data.default, library, string)
|
||||
end
|
||||
|
||||
if (translation == nil) then
|
||||
translation = string
|
||||
print("WARNING: no translation path found for " .. string .. " in " .. library)
|
||||
end
|
||||
|
||||
return translation
|
||||
end
|
||||
|
||||
return LanguageManager
|
||||
|
|
Loading…
Reference in a new issue