diff --git a/gamecore/lang.lua b/gamecore/lang.lua index 95cfd85..519ad21 100644 --- a/gamecore/lang.lua +++ b/gamecore/lang.lua @@ -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