src/core: add initial lang system
This commit is contained in:
parent
2fb7c4252d
commit
dbaf2614bd
7 changed files with 106 additions and 0 deletions
|
@ -30,6 +30,7 @@ local DebugSystem = require "core.debug"
|
|||
local Options = require "core.options"
|
||||
local Input = require "core.input"
|
||||
local Screen = require "core.screen"
|
||||
local Lang = require "core.lang"
|
||||
|
||||
function CoreSystem:new()
|
||||
self.debug = DebugSystem(self)
|
||||
|
|
55
sonic-radiance.love/core/lang.lua
Normal file
55
sonic-radiance.love/core/lang.lua
Normal file
|
@ -0,0 +1,55 @@
|
|||
-- core/langs.lua :: The translation system. Transform a string to another
|
||||
-- according to the translations files in the datas/ folder.
|
||||
|
||||
--[[
|
||||
Copyright © 2019 Kazhnuz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local LanguageManager = Object:extend()
|
||||
local langs = require "datas.lang"
|
||||
|
||||
function LanguageManager:new(controller)
|
||||
self.controller = controller
|
||||
self:setLang(self.controller.options.data.language)
|
||||
end
|
||||
|
||||
function LanguageManager:getStringList(library, file)
|
||||
return require(self.lang .. "." .. library .. "." .. file)
|
||||
end
|
||||
|
||||
function LanguageManager:getLangName(lang)
|
||||
local langnames = langs.names
|
||||
return langnames[lang]
|
||||
end
|
||||
|
||||
function LanguageManager:getCurrentLangName()
|
||||
return langnames[self.lang]
|
||||
end
|
||||
|
||||
function LanguageManager:setLang(lang)
|
||||
self.controller.options.data.language = lang
|
||||
self.lang = self.controller.options.data.language
|
||||
self.langfiles = langs.files
|
||||
self.currentLang = self.langfiles[self.lang]
|
||||
self.data = require(self.currentLang)
|
||||
self.fallback = require(self.langfiles["en"])
|
||||
end
|
||||
|
||||
return LanguageManager
|
|
@ -0,0 +1,4 @@
|
|||
return {
|
||||
['false'] = "False",
|
||||
['true'] = "True"
|
||||
}
|
18
sonic-radiance.love/datas/languages/en/options/menu.lua
Normal file
18
sonic-radiance.love/datas/languages/en/options/menu.lua
Normal file
|
@ -0,0 +1,18 @@
|
|||
return {
|
||||
["options"] = "OPTIONS",
|
||||
["video"] = "VIDEO",
|
||||
["audio"] = "AUDIO",
|
||||
["lang"] = "LANGUES",
|
||||
["input"] = "CONTROLES",
|
||||
["reset"] = "RESET",
|
||||
["exit"] = "EXIT",
|
||||
["back"] = "BACK",
|
||||
["sfx"] = "SFX",
|
||||
["music"] = "MUSIC",
|
||||
["keyboard"] = "Clavier",
|
||||
["inputtype"] = "SOURCE",
|
||||
["vsync"] = "VSYNC",
|
||||
["borders"] = "BORDURES",
|
||||
["fullscreen"] = "PLEIN ECRAN",
|
||||
["resolution"] = "RESOLUTION"
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
return {
|
||||
['false'] = "Faux",
|
||||
['true'] = "Vrai"
|
||||
}
|
18
sonic-radiance.love/datas/languages/fr/options/menu.lua
Normal file
18
sonic-radiance.love/datas/languages/fr/options/menu.lua
Normal file
|
@ -0,0 +1,18 @@
|
|||
return {
|
||||
["options"] = "SETTINGS",
|
||||
["video"] = "VIDEO",
|
||||
["audio"] = "AUDIO",
|
||||
["lang"] = "LANGUAGES",
|
||||
["input"] = "CONTROLS",
|
||||
["reset"] = "RESET",
|
||||
["exit"] = "EXIT",
|
||||
["back"] = "BACK",
|
||||
["sfx"] = "SFX",
|
||||
["music"] = "MUSIC",
|
||||
["keyboard"] = "Keyboard",
|
||||
["inputtype"] = "SOURCE",
|
||||
["vsync"] = "VSYNC",
|
||||
["borders"] = "BORDERS",
|
||||
["fullscreen"] = "FULLSCREEN",
|
||||
["resolution"] = "RESOLUTION"
|
||||
}
|
6
sonic-radiance.love/datas/languages/init.lua
Normal file
6
sonic-radiance.love/datas/languages/init.lua
Normal file
|
@ -0,0 +1,6 @@
|
|||
return {
|
||||
available_langs = {
|
||||
["en"] = "English",
|
||||
["fr"] = "Français"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue