lang: update translation system

This commit is contained in:
Kazhnuz 2019-04-14 11:48:05 +02:00
parent 37b6613c4a
commit b801c59a62

View file

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