From dbaf2614bd7bec04311c88d5d7eef740597ea7b9 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 27 Jan 2019 21:59:33 +0100 Subject: [PATCH] src/core: add initial lang system --- sonic-radiance.love/core/init.lua | 1 + sonic-radiance.love/core/lang.lua | 55 +++++++++++++++++++ .../datas/languages/en/global/boolean.lua | 4 ++ .../datas/languages/en/options/menu.lua | 18 ++++++ .../datas/languages/fr/global/boolean.lua | 4 ++ .../datas/languages/fr/options/menu.lua | 18 ++++++ sonic-radiance.love/datas/languages/init.lua | 6 ++ 7 files changed, 106 insertions(+) create mode 100644 sonic-radiance.love/core/lang.lua create mode 100644 sonic-radiance.love/datas/languages/en/global/boolean.lua create mode 100644 sonic-radiance.love/datas/languages/en/options/menu.lua create mode 100644 sonic-radiance.love/datas/languages/fr/global/boolean.lua create mode 100644 sonic-radiance.love/datas/languages/fr/options/menu.lua create mode 100644 sonic-radiance.love/datas/languages/init.lua diff --git a/sonic-radiance.love/core/init.lua b/sonic-radiance.love/core/init.lua index 15d1396..8886ed4 100644 --- a/sonic-radiance.love/core/init.lua +++ b/sonic-radiance.love/core/init.lua @@ -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) diff --git a/sonic-radiance.love/core/lang.lua b/sonic-radiance.love/core/lang.lua new file mode 100644 index 0000000..61c55d3 --- /dev/null +++ b/sonic-radiance.love/core/lang.lua @@ -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 diff --git a/sonic-radiance.love/datas/languages/en/global/boolean.lua b/sonic-radiance.love/datas/languages/en/global/boolean.lua new file mode 100644 index 0000000..7abb335 --- /dev/null +++ b/sonic-radiance.love/datas/languages/en/global/boolean.lua @@ -0,0 +1,4 @@ +return { + ['false'] = "False", + ['true'] = "True" +} diff --git a/sonic-radiance.love/datas/languages/en/options/menu.lua b/sonic-radiance.love/datas/languages/en/options/menu.lua new file mode 100644 index 0000000..ad43f1a --- /dev/null +++ b/sonic-radiance.love/datas/languages/en/options/menu.lua @@ -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" +} diff --git a/sonic-radiance.love/datas/languages/fr/global/boolean.lua b/sonic-radiance.love/datas/languages/fr/global/boolean.lua new file mode 100644 index 0000000..040e542 --- /dev/null +++ b/sonic-radiance.love/datas/languages/fr/global/boolean.lua @@ -0,0 +1,4 @@ +return { + ['false'] = "Faux", + ['true'] = "Vrai" +} diff --git a/sonic-radiance.love/datas/languages/fr/options/menu.lua b/sonic-radiance.love/datas/languages/fr/options/menu.lua new file mode 100644 index 0000000..74aea9a --- /dev/null +++ b/sonic-radiance.love/datas/languages/fr/options/menu.lua @@ -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" +} diff --git a/sonic-radiance.love/datas/languages/init.lua b/sonic-radiance.love/datas/languages/init.lua new file mode 100644 index 0000000..4d76b9f --- /dev/null +++ b/sonic-radiance.love/datas/languages/init.lua @@ -0,0 +1,6 @@ +return { + available_langs = { + ["en"] = "English", + ["fr"] = "Français" + } +}