From 1cae1846476616bb13941090fa59bcef7afe4e5e Mon Sep 17 00:00:00 2001 From: Procybit Date: Mon, 28 Nov 2022 23:45:05 +0300 Subject: [PATCH] feat: better OS localization system now system just HAVE TO run even if we haven't any .lang --- Libraries/System.lua | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/Libraries/System.lua b/Libraries/System.lua index 4938749c..cb40a0af 100755 --- a/Libraries/System.lua +++ b/Libraries/System.lua @@ -160,25 +160,39 @@ function system.getCurrentScript() end end + function system.getLocalization(pathToLocalizationFolder) local required, english = pathToLocalizationFolder .. userSettings.localizationLanguage .. ".lang", pathToLocalizationFolder .. "English.lang" - - -- First trying to return required localization - if filesystem.exists(required) then - return filesystem.readTable(required) - -- Otherwise maybe english localization exists? - elseif filesystem.exists(english) then - return filesystem.readTable(english) - -- Otherwise returning first available localization + local readyLocalization + local firstAvailable + + -- Best localization preparement + if filesystem.exists(english) then + firstAvailable = filesystem.readTable(english) else local list = filesystem.list(pathToLocalizationFolder) - if #list > 0 then - return filesystem.readTable(pathToLocalizationFolder .. list[1]) + firstAvailable = filesystem.readTable(pathToLocalizationFolder .. list[1]) else - error("Failed to get localization: directory is empty") + firstAvailable = {} -- WORST case end end + + -- Final choose + if filesystem.exists(required) then + local reql = filesystem.readTable(required) + for k,v in pairs(firstAvailable) do + if not reql[k] then reql[k] = v end + end + readyLocalization = reql + else + readyLocalization = firstAvailable + end + + -- For unknown localization name cases + setmetatable(readyLocalization, {__index=(function(t,k) return "$"..k end)}) + + return readyLocalization end function system.getCurrentScriptLocalization()