This commit is contained in:
gononono64 committed 2025-02-19 04:37:55 -06:00
1 parent c8475ebc57
commit 17f788fb96
2 files changed
+38 -16

No files matched your search

+8 -1
View File
@@ -5,5 +5,12 @@
"place_object_scroll_up": "[SCROLL UP] Turn right \n",
"place_object_scroll_down": "[SCROLL DOWN] Turn left",
"enter_text": "Enter Text",
"no_prop_defined": "You didnt define any object to place"
"no_prop_defined": "You didnt define any object to place",
"UNITTEST": {
"UNITTESTA": "Im a %s %s",
"UNITTEST": {
"UNITTESTA": "\n.-._ _,-,\n`._`-._ _,-'_,'\n `._ `-._ _,-' _,'\n `._ `-._ __.-----.__ _,-' _,'\n `._ `#===\\\"\\\"\\\" \\\"\\\"\\\"===#' _,'\n `._/) ._ _. (\\_,'\n )*' **.__ __.** '*(\n # .==..__ \\\"\\\" \\\"\\\" __..==, #\n # `\\\"._(_). .(_)_.\\\"' #"
}
}
}
+30 -15
View File
@@ -19,27 +19,42 @@ Language = {}
function Language.Locale(str, ...)
local resource = GetInvokingResource() or GetCurrentResourceName()
assert(resource, "Resource name not found")
--print(resource, "locales/" .. Lang .. ".json")
local locales = LoadResourceFile(resource, "locales/" .. Lang .. ".json")
--print(locales, Lang)
locales = locales and json.decode(locales) or {}
local locale = locales[str]
if not locale then
warn("Locale not found for language: " .. Lang)
return str
end
local args = {...}
if #args > 0 then
for i = 1, #args do
locale = locale:gsub('{' .. i .. '}', args[i])
-- Handle nested tables via dot notation
local current = locales
for part in str:gmatch("[^%.]+") do
if type(current) ~= "table" then
warn(("Invalid nested locale path: %s"):format(str))
return str
end
current = current[part]
if not current then
warn(("Locale not found for key: %s in language: %s"):format(str, Lang))
return str
end
end
return locale
-- Handle variable replacement
local args = {...}
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")
-- whatever.Locales("some-index-in-language-.json-file")