Skip to content

Commit 2263083

Browse files
authored
Merge pull request #122 from acidlabsdev/main
refactor(Translations): Refactor locales
2 parents 95f598d + 329568a commit 2263083

22 files changed

Lines changed: 311 additions & 157 deletions

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ You are free to use any style you want, except in these cases:
186186
## Translations
187187

188188
- The primary language for all labels is English (US) (`includes/lib/translations/en-US.lua`).
189-
- To add a new language, add its name and ISO code to `includes/lib/translations/__locales.lua`.
189+
- To add a new language, add its ISO code to `includes/lib/translations/__locales.lua`.
190190
- To add a new label, update `/lib/translations/en-US.lua`.
191191
- All other language files will be automatically generated via GitHub Actions.
192192

@@ -215,12 +215,12 @@ Suppose you want to draw some text that gets automatically translated:
215215
#### Adding A New Language
216216

217217
1. Open `includes/lib/translations/__locales.lua`.
218-
2. Add a new language dictionary `{ name, iso }`:
218+
2. Add a new language iso to the array:
219219

220220
```lua
221221
return {
222-
..., -- pre-existing tables
223-
{ name = "Türkçe", iso = "tr-TR" }, -- Your new language
222+
..., -- pre-existing strings
223+
"tr-TR", -- Your new language
224224
}
225225
```
226226

SSV2/includes/data/config.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ local Config <const> = {
1313
debug_mode = false,
1414
auto_cleanup_entities = false,
1515
language_index = 1,
16-
language_code = "en-US",
17-
language_name = "English",
1816
use_game_language = false
1917
},
2018
ui = {

SSV2/includes/frontend/settings/debug_ui.lua

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local RED <const> = Color("red")
1111
local GREEN <const> = Color("green")
1212
local BLUE <const> = Color("blue")
1313
local GREY <const> = Color("#636363")
14+
local LOCALES <const> = Translator.locales
1415

1516
local side_button_size = vec2:new(140, 35)
1617
local init_g_addr = 0
@@ -401,7 +402,17 @@ local function DrawSerializerDebug()
401402
ImGui.BulletText(_F("Is Disabled: %s", not Serializer:CanAccess()))
402403
ImGui.BulletText(_F("Time Since Last Flush: %.0f seconds ago.", Serializer:GetTimeSinceLastFlush() / 1e3))
403404

404-
if GUI:Button("Dump Serializer") then
405+
---@diagnostic disable
406+
if GUI:Button("Break 0") then
407+
Serializer:DebugBreak(0)
408+
end
409+
ImGui.SameLine()
410+
if GUI:Button("Break 1") then
411+
Serializer:DebugBreak(1)
412+
end
413+
---@diagnostic enable
414+
415+
if GUI:Button("Dump") then
405416
Serializer:Dump()
406417
end
407418
end
@@ -410,16 +421,25 @@ local function DrawTranslatorDebug()
410421
ImGui.TextDisabled("You can switch between available languages in Settings -> General.")
411422
ImGui.Spacing()
412423

413-
ImGui.BulletText(_F("Language Name: %s", GVars.backend.language_name))
414-
ImGui.BulletText(_F("ISO: %s", GVars.backend.language_code))
415-
ImGui.BulletText(_F("Index: %d", GVars.backend.language_index))
424+
local idx = GVars.backend.language_index
425+
local iso = LOCALES[idx]
426+
ImGui.BulletText(_F("Index: %d", idx))
427+
ImGui.BulletText(_F("ISO: %s", iso))
428+
ImGui.BulletText(_F("Translated Name: %s", _T(iso)))
416429

417430
ImGui.Spacing()
418431

419432
if (GUI:Button("Reload")) then
420433
Translator.wants_reload = true
421434
end
422435

436+
ImGui.BeginDisabled(Translator:IsReloading())
437+
if (GUI:Button("Break")) then
438+
---@diagnostic disable-next-line
439+
Translator:Reload(true)
440+
end
441+
ImGui.EndDisabled()
442+
423443
if (GUI:Button("Dump Labels")) then
424444
print(Translator.labels)
425445
end
@@ -443,7 +463,7 @@ local function PopulateVehlistOnce()
443463
table.insert(
444464
TVehList,
445465
{
446-
name = name,
466+
name = name,
447467
displayname = Game.GetVehicleDisplayName(name)
448468
}
449469
)
@@ -584,7 +604,7 @@ local function DrawMiscTests()
584604
end
585605

586606
return function()
587-
ImGui.BeginTabBar("##debug")
607+
ImGui.BeginTabBar("##ss_debug")
588608
ImGui.PushTextWrapPos(ImGui.GetFontSize() * 35)
589609

590610
if ImGui.BeginTabItem("Entities") then

SSV2/includes/frontend/settings/settings_ui.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ local function drawGeneralSettings()
6060

6161
ImGui.Spacing()
6262
ImGui.BeginDisabled(GVars.backend.use_game_language)
63-
if (ImGui.BeginCombo("##langs", _F("%s (%s)", GVars.backend.language_name or "English", GVars.backend.language_code or "en-US"))) then
64-
for i, lang in ipairs(LOCALES) do
63+
local currentLang = LOCALES[GVars.backend.language_index]
64+
if (ImGui.BeginCombo("##langs", currentLang and _T(currentLang) or "NULL")) then
65+
for i, iso in ipairs(LOCALES) do
6566
local idx = GVars.backend.language_index
6667
local is_selected = (i == idx)
67-
if (ImGui.Selectable(_F("%s (%s)", lang.name, lang.iso), is_selected)) then
68+
local langName = _T(iso)
69+
if (ImGui.Selectable(_F("%s (%s)", langName, iso), is_selected)) then
6870
GVars.backend.language_index = i
69-
GVars.backend.language_name = lang.name
70-
GVars.backend.language_code = lang.iso
7171
end
7272
end
7373
ImGui.EndCombo()

SSV2/includes/lib/translations/__hashmap.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,5 +682,17 @@
682682
"GENERIC_LOADED": 509630758,
683683
"GENERIC_RELOADED": 1138106350,
684684
"SETTINGS_GAME_LANGUAGE": 3879522379,
685-
"SETTINGS_GAME_LANGUAGE_TT": 1188280448
685+
"SETTINGS_GAME_LANGUAGE_TT": 1188280448,
686+
"en-US": 1673434086,
687+
"fr-FR": 3776105897,
688+
"de-DE": 2179654766,
689+
"es-ES": 1534915433,
690+
"it-IT": 2247455874,
691+
"pt-BR": 2259953526,
692+
"ru-RU": 2313641554,
693+
"zh-TW": 3645775527,
694+
"zh-CN": 3102494356,
695+
"ja-JP": 3546002874,
696+
"pl-PL": 1768783297,
697+
"ko-KR": 425250019
686698
}

SSV2/includes/lib/translations/__locales.lua

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
--
1414
-- The error is actually just a warning from the API but just to keep things clean and running smoothly, don't add non-existing locales.
1515
return {
16-
{ name = "English", iso = "en-US" },
17-
{ name = "Français", iso = "fr-FR" },
18-
{ name = "Deütsch", iso = "de-DE" },
19-
{ name = "Español", iso = "es-ES" },
20-
{ name = "Italiano", iso = "it-IT" },
21-
{ name = "Português", iso = "pt-BR" },
22-
{ name = "Русский", iso = "ru-RU" },
23-
{ name = "中國人", iso = "zh-TW" },
24-
{ name = "中国人", iso = "zh-CN" },
25-
{ name = "日本語", iso = "ja-JP" },
26-
{ name = "Polski", iso = "pl-PL" },
27-
{ name = "한국인", iso = "ko-KR" },
16+
"en-US",
17+
"fr-FR",
18+
"de-DE",
19+
"es-ES",
20+
"it-IT",
21+
"pt-BR",
22+
"ru-RU",
23+
"zh-TW",
24+
"zh-CN",
25+
"ja-JP",
26+
"pl-PL",
27+
"ko-KR",
2828
}

SSV2/includes/lib/translations/de-DE.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,5 +682,17 @@ return {
682682
["GENERIC_LOADED"] = "Geladen.",
683683
["GENERIC_RELOADED"] = "Neu geladen.",
684684
["SETTINGS_GAME_LANGUAGE"] = "Verwenden Sie die Spielsprache",
685-
["SETTINGS_GAME_LANGUAGE_TT"] = "Verwenden Sie die aktuell ausgewählte Spielsprache."
685+
["SETTINGS_GAME_LANGUAGE_TT"] = "Verwenden Sie die aktuell ausgewählte Spielsprache.",
686+
["fr-FR"] = "Französisch",
687+
["es-ES"] = "Spanisch",
688+
["en-US"] = "Englisch (USA)",
689+
["de-DE"] = "Deutsch",
690+
["it-IT"] = "Italienisch",
691+
["ru-RU"] = "Russisch",
692+
["zh-TW"] = "Chinesisch (traditionell)",
693+
["ko-KR"] = "Koreanisch",
694+
["pl-PL"] = "Polieren",
695+
["zh-CN"] = "Chinesisch (vereinfacht)",
696+
["ja-JP"] = "japanisch",
697+
["pt-BR"] = "Portugiesisch"
686698
}

SSV2/includes/lib/translations/en-US.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,27 @@ return {
1515
["SUBTAB_GUI"] = "User Interface",
1616
--#endregion
1717

18+
--#region language names
19+
["en-US"] = "English (US)",
20+
["fr-FR"] = "French",
21+
["de-DE"] = "German",
22+
["es-ES"] = "Spanish", -- Always defaults to ES-ES (no ES-MX)
23+
["it-IT"] = "Italian",
24+
["pt-BR"] = "Portugese",
25+
["ru-RU"] = "Russian",
26+
["zh-TW"] = "Chinese (Traditional)",
27+
["zh-CN"] = "Chinese (Simplified)",
28+
["ja-JP"] = "Japanese",
29+
["pl-PL"] = "Polish",
30+
["ko-KR"] = "Korean",
31+
--#endregion
32+
33+
--#region GUI stuff
1834
["GUI_NEW_LAYOUT_NOTICE"] = "The script's UI is now independent from the menu. Press %s to toggle it.",
1935
["GUI_NOTIFICATIONS"] = "Notifications",
2036
["GUI_NOTIFICATIONS_UNREAD"] = "Unread notifications",
2137
["GUI_NOTIFICATIONS_NONE"] = "You have no notifications.",
38+
--#endregion
2239

2340
--#region generics
2441
["WARN_PED_SPAWN_LIMIT"] = "Ped spawn limit reached! Consider enabling 'Auto Replace Entities' in the Settings tab if you want to automatically replace old entities when you reach the limit.",

SSV2/includes/lib/translations/es-ES.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,5 +682,17 @@ return {
682682
["GENERIC_LOADED"] = "Cargado.",
683683
["GENERIC_RELOADED"] = "Recargado.",
684684
["SETTINGS_GAME_LANGUAGE"] = "Usar lenguaje de juego",
685-
["SETTINGS_GAME_LANGUAGE_TT"] = "Usa el idioma del juego seleccionado actualmente."
685+
["SETTINGS_GAME_LANGUAGE_TT"] = "Usa el idioma del juego seleccionado actualmente.",
686+
["es-ES"] = "Español",
687+
["ru-RU"] = "ruso",
688+
["en-US"] = "Inglés (Estados Unidos)",
689+
["de-DE"] = "Alemán",
690+
["pt-BR"] = "portugués",
691+
["it-IT"] = "italiano",
692+
["fr-FR"] = "Francés",
693+
["ko-KR"] = "coreano",
694+
["zh-CN"] = "Chino (simplificado)",
695+
["ja-JP"] = "japonés",
696+
["zh-TW"] = "Chino (tradicional)",
697+
["pl-PL"] = "Polaco"
686698
}

SSV2/includes/lib/translations/fr-FR.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,5 +682,17 @@ return {
682682
["GENERIC_LOADED"] = "Chargé.",
683683
["SETTINGS_GAME_LANGUAGE_TT"] = "Utilisez la langue de jeu actuellement sélectionnée.",
684684
["SETTINGS_GAME_LANGUAGE"] = "Utiliser le langage du jeu",
685-
["GENERIC_RELOADED"] = "Rechargé."
685+
["GENERIC_RELOADED"] = "Rechargé.",
686+
["en-US"] = "Anglais (États-Unis)",
687+
["fr-FR"] = "Français",
688+
["ru-RU"] = "russe",
689+
["es-ES"] = "Espagnol",
690+
["zh-CN"] = "Chinois (simplifié)",
691+
["it-IT"] = "italien",
692+
["de-DE"] = "Allemand",
693+
["zh-TW"] = "Chinois (traditionnel)",
694+
["ko-KR"] = "coréen",
695+
["pl-PL"] = "polonais",
696+
["ja-JP"] = "japonais",
697+
["pt-BR"] = "Portugais"
686698
}

0 commit comments

Comments
 (0)