This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Maximus7474/locale-integration
Locale integration
- Loading branch information
Showing
7 changed files
with
59 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"DEFAULT": { | ||
"TITLE": "Dispatch Notification", | ||
"LOCATION_LABEL": "Call Origin" | ||
}, | ||
"RCORE": { | ||
"SHOP_ROBBERY": "Shop Robbery", | ||
"CAR_ROBBERY": "Car theft" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
CONFIG = { | ||
['default-time'] = GetConvarInt('lb-tablet-dispatch:default-time', 100), | ||
['locale'] = GetConvar('lb-tablet-dispatch:locale', 'en') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
local locale = {} | ||
|
||
local localeKey = CONFIG['locale'] | ||
|
||
local rawContent = LoadResourceFile(GetCurrentResourceName(), ('locales/%s.json'):format(localeKey)) | ||
|
||
if not rawContent then | ||
lib.print.warn(('Unable to load %s locale as it doesn\'t exist in @%s/locales/'):format(localeKey, GetCurrentResourceName())) | ||
lib.print.warn('Falling back to english locale.') | ||
rawContent = LoadResourceFile(GetCurrentResourceName(), 'locales/en.json') | ||
end | ||
|
||
locale = json.decode(rawContent)[IsDuplicityVersion() and 'SERVER' or 'CLIENT'] | ||
|
||
function T(key, args) | ||
local keys = {} | ||
for str in string.gmatch(key, "([^%.]+)") do | ||
keys[#keys+1] = str | ||
end | ||
|
||
local localizedString = locale | ||
for _, keyPart in ipairs(keys) do | ||
localizedString = localizedString[keyPart] | ||
if localizedString == nil then | ||
return key | ||
end | ||
end | ||
|
||
local formatedString = localizedString:gsub("%b{}", function(match) | ||
local key = match:sub(2, -2) | ||
return args[key] or "" | ||
end) | ||
|
||
return formatedString | ||
end |