From eb498456aa87053e96b3e34c12a6befff46dd66c Mon Sep 17 00:00:00 2001 From: LuaFan2 Date: Mon, 17 Aug 2020 01:34:17 +0500 Subject: [PATCH 1/3] Dictionary system | Part 1 --- shared/Dictionary.lua | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 shared/Dictionary.lua diff --git a/shared/Dictionary.lua b/shared/Dictionary.lua new file mode 100644 index 0000000..82a4bac --- /dev/null +++ b/shared/Dictionary.lua @@ -0,0 +1,48 @@ +Dictionary = class(ValueStorage) + +function Dictionary:__init() + self:InitializeValueStorage(self) + + self:SetValue("current_language", "en") +end + +function Dictionary:AddLanguage(lang) + self:SetValue(lang, {}) +end + +function Dictionary:AddPhrase(lang, id, phrase) + local phrases = self:GetValue(lang) + if not phrases then + print("No language found with id " .. lang) + end + + phrases[id] = phrase + + self:SetValue(lang, phrases) +end + +function Dictionary:SetLanguage(lang) + self:SetValue("current_language", lang) +end + +function Dictionary:GetLanguage() + return self:GetValue("current_language") +end + +function Dictionary:GetPhrase(language, id) + if not id then language = self:GetLanguage() end + + local phrases = self:GetValue(language) + if not phrases then + print("Trying to get phrase on unlisted language") + return + end + + local phrase = phrases[id] + if not phrase then + print("Trying to get phrase by wrong identifier") + return + end + + return phrase +end \ No newline at end of file From f0ae3e0fdf4f5e6948861179caba94ba80a3316a Mon Sep 17 00:00:00 2001 From: LuaFan2 <51294434+LuaFan2@users.noreply.github.com> Date: Mon, 17 Aug 2020 02:15:32 +0500 Subject: [PATCH 2/3] Minor fix --- shared/Dictionary.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/Dictionary.lua b/shared/Dictionary.lua index 82a4bac..a59a4b4 100644 --- a/shared/Dictionary.lua +++ b/shared/Dictionary.lua @@ -38,11 +38,11 @@ function Dictionary:GetPhrase(language, id) return end - local phrase = phrases[id] + local phrase = id and phrases[id] or pharses[language] if not phrase then print("Trying to get phrase by wrong identifier") return end return phrase -end \ No newline at end of file +end From 22c52a99e84129c9c9848cb2f4a7b8301c487b89 Mon Sep 17 00:00:00 2001 From: LuaFan2 <51294434+LuaFan2@users.noreply.github.com> Date: Mon, 17 Aug 2020 02:18:40 +0500 Subject: [PATCH 3/3] Oops... --- shared/Dictionary.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/shared/Dictionary.lua b/shared/Dictionary.lua index a59a4b4..a7578a4 100644 --- a/shared/Dictionary.lua +++ b/shared/Dictionary.lua @@ -30,7 +30,10 @@ function Dictionary:GetLanguage() end function Dictionary:GetPhrase(language, id) - if not id then language = self:GetLanguage() end + if not id then + id = language + language = self:GetLanguage() + end local phrases = self:GetValue(language) if not phrases then @@ -38,7 +41,7 @@ function Dictionary:GetPhrase(language, id) return end - local phrase = id and phrases[id] or pharses[language] + local phrase = phrases[id] if not phrase then print("Trying to get phrase by wrong identifier") return