Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add localization override support using custom params #4038

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions luaui/Widgets/gui_language.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function widget:LanguageChanged()
end

function widget:Initialize()
i18nHelper.RefreshDefs()

widgetHandler:RegisterGlobal('GadgetMessageProxy', getMessageProxy)

WG['language'] = {}
Expand Down
40 changes: 40 additions & 0 deletions luaui/Widgets/tweakdefs_unit_translations.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function widget:GetInfo()
return {
name = "Tweakdefs Custom Unit Names",
desc = "Allow tweakdefs to override I18N entries for units",
author = "Centrifugal",
date = "Dec 20, 2024",
license = "GNU GPL, v2 or later",
layer = -1000000, -- must run before gui_language
enabled = true
}
end

local function updateTranslations()
local currentLanguage = Spring.GetConfigString("language", "en")

for unitDefName, unitDef in pairs(UnitDefNames) do
--Naming convention for language overrides
local nameKey = "i18n_" .. currentLanguage .. "_humanname"
local tooltipKey = "i18n_" .. currentLanguage .. "_tooltip"

local customHumanName = unitDef.customParams[nameKey]
local customTooltip = unitDef.customParams[tooltipKey]

if customHumanName then
Spring.I18N.set(currentLanguage .. '.units.names.' .. unitDefName, customHumanName)
end

if customTooltip then
Spring.I18N.set(currentLanguage .. '.units.descriptions.' .. unitDefName, customTooltip)
end
end
end

function widget:Initialize()
updateTranslations()
end

function widget:LanguageChanged()
updateTranslations()
end
6 changes: 0 additions & 6 deletions luaui/setupdefs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,3 @@ do
end
WeaponDefNames = tbl
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local i18nDefs = VFS.Include('luaui/i18nhelpers.lua')
i18nDefs.RefreshDefs()