Skip to content

Commit

Permalink
Merge pull request #1598 from Kenshiin13/fix-locale
Browse files Browse the repository at this point in the history
feat(es_extended/locale): add support for lazy loading locales
  • Loading branch information
Kenshiin13 authored Jan 19, 2025
2 parents e855be0 + 86af2ef commit 6e3dbc1
Show file tree
Hide file tree
Showing 53 changed files with 111 additions and 100 deletions.
2 changes: 1 addition & 1 deletion [core]/es_extended/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ version '1.12.2'

shared_scripts {
'locale.lua',
'locales/*.lua',

'shared/config/main.lua',
'shared/config/weapons.lua',
Expand Down Expand Up @@ -63,6 +62,7 @@ ui_page {

files {
'imports.lua',
'locales/*.lua',
'locale.js',
'html/ui.html',

Expand Down
38 changes: 25 additions & 13 deletions [core]/es_extended/locale.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,33 @@ Locales = {}
function Translate(str, ...) -- Translate string
if not str then
error(("Resource ^5%s^1 You did not specify a parameter for the Translate function or the value is nil!"):format(GetInvokingResource() or GetCurrentResourceName()))
return "Given translate function parameter is nil!"
end
if Locales[Config.Locale] then
if Locales[Config.Locale][str] then
return string.format(Locales[Config.Locale][str], ...)
elseif Config.Locale ~= "en" and Locales["en"] and Locales["en"][str] then
return string.format(Locales["en"][str], ...)
else
return "Translation [" .. Config.Locale .. "][" .. str .. "] does not exist"

--- Load the locale file if it hasn't been loaded yet
if Locales[Config.Locale] == nil then
local success, result = pcall(function()
return assert(load(LoadResourceFile(GetCurrentResourceName(), ("locales/%s.lua"):format(Config.Locale))))()
end)

Locales[Config.Locale] = success and result or false
end

local translations = Locales[Config.Locale]
if not translations then
if Config.Locale == "en" then
return "Locale [en] does not exist"
end
elseif Config.Locale ~= "en" and Locales["en"] and Locales["en"][str] then
return string.format(Locales["en"][str], ...)
else
return "Locale [" .. Config.Locale .. "] does not exist"

-- Fall back to English translation if the current locale is not found
Config.Locale = "en"
return Translate(str, ...)
end

if translations[str] then
return translations[str]:format(...)
end

return ("Translation [%s][%s] does not exist"):format(Config.Locale, str)
end

function TranslateCap(str, ...) -- Translate string first char uppercase
Expand All @@ -26,4 +38,4 @@ end

_ = Translate
-- luacheck: ignore _U
_U = TranslateCap
_U = TranslateCap
8 changes: 4 additions & 4 deletions [core]/es_extended/locales/cs.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["cs"] = {
return {
-- Inventory
["inventory"] = "Inventář ( Váha %s / %s )",
["use"] = "Použít",
Expand Down Expand Up @@ -223,10 +223,10 @@ Locales["cs"] = {
["weapon_tactilerifle"] = "Service Carbine",

-- Drug Wars DLC
["weapon_candycane"] = "Candy Cane", -- not translated
["weapon_candycane"] = "Candy Cane", -- not translated
["weapon_acidpackage"] = "Acid Package", -- not translated
["weapon_pistolxm3"] = "WM 29 Pistol", -- not translated
["weapon_railgunxm3"] = "Railgun", -- not translated
["weapon_pistolxm3"] = "WM 29 Pistol", -- not translated
["weapon_railgunxm3"] = "Railgun", -- not translated

-- Thrown
["weapon_ball"] = "Míček",
Expand Down
2 changes: 1 addition & 1 deletion [core]/es_extended/locales/de.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["de"] = {
return {
-- Inventory
["inventory"] = "Inventar ( Gewicht %s / %s )",
["use"] = "Benutzen",
Expand Down
2 changes: 1 addition & 1 deletion [core]/es_extended/locales/el.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["el"] = {
return {
-- Inventory
["inventory"] = "Αποθήκη ( Βάρος %s / %s )",
["use"] = "Χρήση",
Expand Down
2 changes: 1 addition & 1 deletion [core]/es_extended/locales/en.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["en"] = {
return {
-- Inventory
["inventory"] = "Inventory ( Weight %s / %s )",
["use"] = "Use",
Expand Down
2 changes: 1 addition & 1 deletion [core]/es_extended/locales/es.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["es"] = {
return {
-- Inventory
["inventory"] = "Inventario %s / %s",
["use"] = "Usar",
Expand Down
2 changes: 1 addition & 1 deletion [core]/es_extended/locales/fi.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["fi"] = {
return {
-- Inventory
["inventory"] = "Reppu %s / %s",
["use"] = "Käytä",
Expand Down
2 changes: 1 addition & 1 deletion [core]/es_extended/locales/fr.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["fr"] = {
return {
-- Inventory
["inventory"] = "Inventaire ( Poids %s / %s )",
["use"] = "Utiliser",
Expand Down
2 changes: 1 addition & 1 deletion [core]/es_extended/locales/he.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["he"] = {
return {
-- Inventory
["inventory"] = "מלאי ( משקל %s / %s )",
["use"] = "השתמש",
Expand Down
8 changes: 4 additions & 4 deletions [core]/es_extended/locales/hu.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["hu"] = {
return {
-- Inventory
["inventory"] = "Inventory ( Súly %s / %s )",
["use"] = "Használ",
Expand Down Expand Up @@ -229,10 +229,10 @@ Locales["hu"] = {
["weapon_tactilerifle"] = "Service Carbine",

-- Drug Wars DLC
["weapon_candycane"] = "Candy Cane", -- not translated
["weapon_candycane"] = "Candy Cane", -- not translated
["weapon_acidpackage"] = "Acid Package", -- not translated
["weapon_pistolxm3"] = "WM 29 Pistol", -- not translated
["weapon_railgunxm3"] = "Railgun", -- not translated
["weapon_pistolxm3"] = "WM 29 Pistol", -- not translated
["weapon_railgunxm3"] = "Railgun", -- not translated

-- Thrown
["weapon_ball"] = "Baseball",
Expand Down
2 changes: 1 addition & 1 deletion [core]/es_extended/locales/id.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["id"] = {
return {
-- Inventory
["inventory"] = "Inventaris ( Berat %s / %s )",
["use"] = "Gunakan",
Expand Down
2 changes: 1 addition & 1 deletion [core]/es_extended/locales/it.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["it"] = {
return {
-- Inventory
["inventory"] = "Inventario ( Peso %s / %s )",
["use"] = "Usa",
Expand Down
2 changes: 1 addition & 1 deletion [core]/es_extended/locales/nl.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["nl"] = {
return {
-- Inventory
["inventory"] = "Inventaris ( Gewicht %s / %s )",
["use"] = "Gebruik",
Expand Down
8 changes: 4 additions & 4 deletions [core]/es_extended/locales/pl.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["pl"] = {
return {
-- Inventory
["inventory"] = "ekwipunek %s / %s",
["use"] = "użyj",
Expand Down Expand Up @@ -202,10 +202,10 @@ Locales["pl"] = {
["component_luxary_finish"] = "luksusowe wykończenie broni",

-- Drug Wars DLC
["weapon_candycane"] = "Candy Cane", -- not translated
["weapon_candycane"] = "Candy Cane", -- not translated
["weapon_acidpackage"] = "Acid Package", -- not translated
["weapon_pistolxm3"] = "WM 29 Pistol", -- not translated
["weapon_railgunxm3"] = "Railgun", -- not translated
["weapon_pistolxm3"] = "WM 29 Pistol", -- not translated
["weapon_railgunxm3"] = "Railgun", -- not translated

-- Weapon Ammo
["ammo_rounds"] = "nabój/oi",
Expand Down
8 changes: 4 additions & 4 deletions [core]/es_extended/locales/sl.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["sl"] = {
return {
-- Inventory
["inventory"] = "Shramba ( Teza %s / %s )",
["use"] = "Uporabi",
Expand Down Expand Up @@ -229,10 +229,10 @@ Locales["sl"] = {
["weapon_tactilerifle"] = "Service Carbine",

-- Drug Wars DLC
["weapon_candycane"] = "Candy Cane", -- not translated
["weapon_candycane"] = "Candy Cane", -- not translated
["weapon_acidpackage"] = "Acid Package", -- not translated
["weapon_pistolxm3"] = "WM 29 Pistol", -- not translated
["weapon_railgunxm3"] = "Railgun", -- not translated
["weapon_pistolxm3"] = "WM 29 Pistol", -- not translated
["weapon_railgunxm3"] = "Railgun", -- not translated

-- Thrown
["weapon_ball"] = "Baseball",
Expand Down
8 changes: 4 additions & 4 deletions [core]/es_extended/locales/sr.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["sr"] = {
return {
-- Inventory
["inventory"] = "Inventar ( Težina %s / %s )",
["use"] = "Koristi",
Expand Down Expand Up @@ -229,10 +229,10 @@ Locales["sr"] = {
["weapon_tactilerifle"] = "Service Carbine",

-- Drug Wars DLC
["weapon_candycane"] = "Candy Cane", -- not translated
["weapon_candycane"] = "Candy Cane", -- not translated
["weapon_acidpackage"] = "Acid Package", -- not translated
["weapon_pistolxm3"] = "WM 29 Pistol", -- not translated
["weapon_railgunxm3"] = "Railgun", -- not translated
["weapon_pistolxm3"] = "WM 29 Pistol", -- not translated
["weapon_railgunxm3"] = "Railgun", -- not translated

-- Thrown
["weapon_ball"] = "Baseball",
Expand Down
2 changes: 1 addition & 1 deletion [core]/es_extended/locales/sv.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["sv"] = {
return {
-- Inventory
["inventory"] = "Inventory ( Vikt %s / %s )",
["use"] = "Använd",
Expand Down
16 changes: 8 additions & 8 deletions [core]/es_extended/locales/tr.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["tr"] = {
return {
-- Inventory
["inventory"] = "Envanter ( Ağırlık %s / %s )",
["use"] = "Kullan",
Expand Down Expand Up @@ -36,10 +36,10 @@ Locales["tr"] = {
["threw_weapon_already"] = "Bu Silaha Zaten Sahipsiniz",
["threw_cannot_pickup"] = "Envanter Dolu, Alınamaz!",
["threw_pickup_prompt"] = "Almak İçin E'ye Basın",

-- Key mapping
["keymap_showinventory"] = "Envanteri Göster",

-- Salary related
["received_salary"] = "Maaşınız Ödendi: $%s",
["received_help"] = "Yardım Çekiniz Ödendi: $%s",
Expand All @@ -49,11 +49,11 @@ Locales["tr"] = {
["account_bank"] = "Banka",
["account_black_money"] = "Kirli Para",
["account_money"] = "Nakit",

["act_imp"] = "İşlem Yapılamaz",
["in_vehicle"] = "İşlem Yapılamaz, Oyuncu Araçta",
["not_in_vehicle"] = "İşlem Yapılamaz, Oyuncu Araçta Değil",

-- Commands
["command_bring"] = "Oyuncuyu Yanınıza Getir",
["command_car"] = "Araç Spawn Et",
Expand Down Expand Up @@ -119,14 +119,14 @@ Locales["tr"] = {
["command_giveammo_ammo"] = "Mermi Miktarı",
["tpm_nowaypoint"] = "Hiçbir Yol İşareti Ayarlanmadı.",
["tpm_success"] = "Başarıyla Teleport Edildi",

["noclip_message"] = "Noclip %s Yapıldı",
["enabled"] = "~g~Aktif Edildi~s~",
["disabled"] = "~r~Pasif Edildi~s~",

-- Locale settings
["locale_digit_grouping_symbol"] = ",",
["locale_currency"] = "£%s",
["locale_currency"] = "£%s",

-- Silahlar

Expand Down
8 changes: 4 additions & 4 deletions [core]/es_extended/locales/zh-cn.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["zh-cn"] = {
return {
-- Inventory
["inventory"] = "背包 %s / %s",
["use"] = "使用",
Expand Down Expand Up @@ -229,10 +229,10 @@ Locales["zh-cn"] = {
["weapon_tactilerifle"] = "制式卡宾步枪",

-- Drug Wars DLC
["weapon_candycane"] = "Candy Cane", -- not translated
["weapon_candycane"] = "Candy Cane", -- not translated
["weapon_acidpackage"] = "Acid Package", -- not translated
["weapon_pistolxm3"] = "WM 29 Pistol", -- not translated
["weapon_railgunxm3"] = "Railgun", -- not translated
["weapon_pistolxm3"] = "WM 29 Pistol", -- not translated
["weapon_railgunxm3"] = "Railgun", -- not translated

-- Thrown
["weapon_ball"] = "棒球",
Expand Down
9 changes: 4 additions & 5 deletions [core]/es_extended/shared/config/main.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Config = {}

local txAdminLocale = GetConvar("txAdmin-locale", "en")
local esxLocale = GetConvar("esx:locale", "invalid")
Config.Locale = (esxLocale ~= "invalid") and esxLocale or (txAdminLocale ~= "custom" and txAdminLocale) or "en"

-- for ox inventory, this will automatically be adjusted, do not change! for other inventories, change to "resource_name"
Config.CustomInventory = false

Expand Down Expand Up @@ -60,8 +64,3 @@ if GetResourceState("ox_inventory") ~= "missing" then
end

Config.EnableDefaultInventory = Config.CustomInventory == false -- Display the default Inventory ( F2 )

local txAdminLocale = GetConvar("txAdmin-locale", "en")
local esxLocale = GetConvar("esx:locale", "invalid")

Config.Locale = (esxLocale ~= "invalid") and esxLocale or (txAdminLocale ~= "custom" and txAdminLocale) or "en"
2 changes: 1 addition & 1 deletion [core]/esx_identity/locales/cs.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["cs"] = {
return {
["show_registration"] = "zobrazit registracni menu",
["show_active_character"] = "zobrazit aktivni postavy",
["delete_character"] = "smazat svou stavajici postavu a vytvorit novou",
Expand Down
2 changes: 1 addition & 1 deletion [core]/esx_identity/locales/da.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["da"] = {
return {
["show_active_character"] = "Vis aktiv karakter",
["active_character"] = "Aktiv karakter: %s",
["error_active_character"] = "Der opstod en fejl under indhentning af dine data.",
Expand Down
4 changes: 2 additions & 2 deletions [core]/esx_identity/locales/de.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["de"] = {
return {
["show_active_character"] = "Aktiven Charakter anzeigen",
["active_character"] = "Aktiver Charakter: %s",
["error_active_character"] = "Beim Abrufen deiner Daten ist ein Fehler aufgetreten",
Expand Down Expand Up @@ -35,4 +35,4 @@ Locales["de"] = {
["invalid_dob_format"] = "Ungültiges Format (Geburtstag): Bitte versuche es erneut.",
["invalid_sex_format"] = "Ungültiges Format (Geschlecht): Bitte versuche es erneut.",
["invalid_height_format"] = "Ungültiges Format (Körpergröße): Bitte versuche es erneut.",
}
}
2 changes: 1 addition & 1 deletion [core]/esx_identity/locales/en.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["en"] = {
return {
["show_active_character"] = "Show Active Character",
["active_character"] = "Active Character: %s",
["error_active_character"] = "There was an error obtaining your data.",
Expand Down
2 changes: 1 addition & 1 deletion [core]/esx_identity/locales/es.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["es"] = {
return {
["show_active_character"] = "Mostrar personaje actual",
["active_character"] = "Personaje actual: %s",
["error_active_character"] = "Se produjo un error al recuperar tu nombre. Por favor contacta con un administrador",
Expand Down
2 changes: 1 addition & 1 deletion [core]/esx_identity/locales/fi.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["fi"] = {
return {
["show_active_character"] = "Näytä nykyinen hahmosi",
["active_character"] = "Nykyinen hahmosi: %s",
["error_active_character"] = "Hahmosi hakemisessa ilmeni ongelma. Ota yhteyttä ylläpitoon.",
Expand Down
2 changes: 1 addition & 1 deletion [core]/esx_identity/locales/fr.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["fr"] = {
return {
["show_active_character"] = "Afficher le personnage actif",
["active_character"] = "Personnage actif: %s",
["error_active_character"] = "Une erreur s'est produite lors de l'obtention de vos données.",
Expand Down
2 changes: 1 addition & 1 deletion [core]/esx_identity/locales/he.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["he"] = {
return {
["show_active_character"] = "הצג דמות פעילה",
["active_character"] = "דמות פעילה: %s",
["error_active_character"] = "אירעה שגיאה בקבלת הנתונים שלך.",
Expand Down
2 changes: 1 addition & 1 deletion [core]/esx_identity/locales/hu.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["hu"] = {
return {
["show_active_character"] = "Aktív karakterek mutatása",
["active_character"] = "Aktív karakter: %s",
["error_active_character"] = "A név nem megfelelő",
Expand Down
2 changes: 1 addition & 1 deletion [core]/esx_identity/locales/it.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["it"] = {
return {
["show_active_character"] = "Mostra Personaggio Attivo",
["active_character"] = "Personaggio Attivo: %s",
["error_active_character"] = "Errore nel recuperare i tuoi dati.",
Expand Down
2 changes: 1 addition & 1 deletion [core]/esx_identity/locales/nl.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Locales["nl"] = {
return {
["show_active_character"] = "Actieve karakter laten zien",
["active_character"] = "Actief karakter: %s",
["error_active_character"] = "Er is een probleem opgetreden tijdens het verzamelen van uw data.",
Expand Down
Loading

0 comments on commit 6e3dbc1

Please sign in to comment.