From 0382694f942b5d738889aebbfe16a69fb20d7cdd Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Wed, 19 Feb 2025 06:15:46 -0500 Subject: [PATCH] Crowley saved the day and fixed my brain --- modules/locales/shared.lua | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/locales/shared.lua b/modules/locales/shared.lua index 15296b4..1e49843 100644 --- a/modules/locales/shared.lua +++ b/modules/locales/shared.lua @@ -17,13 +17,12 @@ esxLang ~= "none" and esxLang or Language = {} function Language.Locale(str, ...) - print("Lang: ", GetInvokingResource(), GetCurrentResourceName()) local resource = GetInvokingResource() or GetCurrentResourceName() assert(resource, "Resource name not found") - + local locales = LoadResourceFile(resource, "locales/" .. Lang .. ".json") locales = locales and json.decode(locales) or {} - + -- Handle nested tables via dot notation local current = locales for part in str:gmatch("[^%.]+") do @@ -37,24 +36,19 @@ function Language.Locale(str, ...) return str end end - + -- Handle variable replacement local args = {...} - - if type(current) == "string" and #args > 0 then + + if type(current) == "string" and #args > 0 then current = string.format(current, ...) end - + return current end -RegisterCommand("lang", function(source, args, raw) - print(Language.Locale("UNITTEST.UNITTEST.UNITTESTA")) - print(Language.Locale("UNITTEST.UNITTESTA", "Devil", "GERRRRRRR!")) - print( "Oh also this works", Language.Locale("place_object_scroll_down")) -end) if BridgeSharedConfig.DebugLevel == 2 then -- if outside this resource, use local whatever = Require("modules/locales/shared.lua") @@ -62,14 +56,20 @@ if BridgeSharedConfig.DebugLevel == 2 then -- Files must be stored in "locales" folder, within the resource. -- Instead of using Require you can also import it via the manifest. -- The Lang variable is available globally, which tells you what the server is using. - --print("Language: ", Lang) - --print("Locale: ", Language.Locale("locale-unit-test")) + -- print("Language: ", Lang) + -- print("Locale: ", Language.Locale("locale-unit-test")) -- Example outside community bridge resource: -- local Language = Require('modules/locales/shared.lua') -- print("Language: ", Lang) -- print("Locale: ", Language.Locale("locale-unit-test")) + RegisterCommand("lang", function(source, args, raw) + print(Language.Locale("UNITTEST.UNITTEST.UNITTESTA")) + print(Language.Locale("UNITTEST.UNITTESTA", "Devil", "GERRRRRRR!")) + + print( "Oh also this works", Language.Locale("place_object_scroll_down")) + end) end return Language \ No newline at end of file