Skip to content
Draft
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
1 change: 1 addition & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"luaui",
"spec",
"types",
".lux/5.1/bc9d25ebdcc8e85d77e17e27b8d98785b6a08aa20e71c7b98d7438ec7f0a3175-i18n@0.9.2-1/src",
".lux/5.1/test_dependencies/5.1/01a3c364614bddff7370223a5a9c4580f8e62d144384148444c518ec5367a59b-mediator_lua@1.1.2-0/src",
".lux/5.1/test_dependencies/5.1/287e827f4a088d41bba04af5f61a13614346c16fe8150eb7c4246e67d6fd163e-lua-term@0.8-1/src",
".lux/5.1/test_dependencies/5.1/316ac0b30e04e86a253d64886f3b110bd0508267474e6b58a3b973bd6857dbf4-penlight@1.14.0-3/src",
Expand Down
4 changes: 2 additions & 2 deletions luaui/Widgets/gui_raptorStatsPanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ local function getResistancesMessage()
if UnitDefNames[attackerName].customParams.i18nfromunit then
attackerName = UnitDefNames[attackerName].customParams.i18nfromunit
end
messages[i+1] = textColor .. Spring.I18N('units.names.' .. attackerName)
currentlyResistantToNames[#currentlyResistantToNames+1] = Spring.I18N('units.names.' .. attackerName)
messages[i+1] = textColor .. Spring.I18N.unitName(attackerName)
currentlyResistantToNames[#currentlyResistantToNames+1] = Spring.I18N.unitName(attackerName)
end
resistancesTable = {}

Expand Down
8 changes: 4 additions & 4 deletions luaui/Widgets/gui_scavStatsPanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ local function getResistancesMessage()
if UnitDefNames[attackerNameNonScav].customParams.i18nfromunit then
attackerNameNonScav = UnitDefNames[attackerNameNonScav].customParams.i18nfromunit
end
messages[i+1] = textColor .. "Scav " .. Spring.I18N('units.names.' .. attackerNameNonScav)
currentlyResistantToNames[#currentlyResistantToNames+1] = "Scav " .. Spring.I18N('units.names.' .. attackerNameNonScav)
messages[i+1] = textColor .. "Scav " .. Spring.I18N.unitName(attackerNameNonScav)
currentlyResistantToNames[#currentlyResistantToNames+1] = "Scav " .. Spring.I18N.unitName(attackerNameNonScav)
else
if UnitDefNames[attackerName].customParams.i18nfromunit then
attackerName = UnitDefNames[attackerName].customParams.i18nfromunit
end
messages[i+1] = textColor .. Spring.I18N('units.names.' .. attackerName)
currentlyResistantToNames[#currentlyResistantToNames+1] = Spring.I18N('units.names.' .. attackerName)
messages[i+1] = textColor .. Spring.I18N.unitName(attackerName)
currentlyResistantToNames[#currentlyResistantToNames+1] = Spring.I18N.unitName(attackerName)
end
end
resistancesTable = {}
Expand Down
4 changes: 2 additions & 2 deletions luaui/i18nhelpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local function refreshUnitDefs()
local proxyUnitDef = UnitDefNames[proxyUnitDefName]
proxyUnitDefName = proxyUnitDef and proxyUnitDef.customParams.i18nfromunit or proxyUnitDefName

local fromUnitHumanName = Spring.I18N('units.names.' .. proxyUnitDefName)
local fromUnitHumanName = Spring.I18N.unitName(proxyUnitDefName)
humanName = Spring.I18N('units.scavenger', { name = fromUnitHumanName })

if (i18nDescriptionEntries[unitDefName]) then
Expand All @@ -22,7 +22,7 @@ local function refreshUnitDefs()
end
else
local proxyUnitDefName = unitDef.customParams.i18nfromunit or unitDefName
humanName = Spring.I18N('units.names.' .. proxyUnitDefName)
humanName = Spring.I18N.unitName(proxyUnitDefName)
tooltip = Spring.I18N('units.descriptions.' .. proxyUnitDefName)
end

Expand Down
25 changes: 25 additions & 0 deletions lux.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
{
"version": "1.0.0",
"dependencies": {
"rocks": {
"bc9d25ebdcc8e85d77e17e27b8d98785b6a08aa20e71c7b98d7438ec7f0a3175": {
"name": "i18n",
"version": "0.9.2-1",
"pinned": false,
"opt": false,
"dependencies": [],
"constraint": ">=0.9.2",
"binaries": [],
"source": "luarocks_rockspec+https://luarocks.org/",
"source_url": {
"type": "url",
"url": "https://github.com/kikito/i18n.lua/archive/v0.9.2.tar.gz"
},
"hashes": {
"rockspec": "sha256-rCc26QezHIXazcT7A+GAkoNVJ92D1xErnlirgmbHHMs=",
"source": "sha256-hdysQmehRpLlKdhIYLgwB0/GzyEBYbQTAFLzhtk/HQc="
}
}
},
"entrypoints": [
"bc9d25ebdcc8e85d77e17e27b8d98785b6a08aa20e71c7b98d7438ec7f0a3175"
]
},
"test_dependencies": {
"rocks": {
"01a3c364614bddff7370223a5a9c4580f8e62d144384148444c518ec5367a59b": {
Expand Down
3 changes: 3 additions & 0 deletions lux.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ maintainer = "BAR Team"
labels = [ "BAR" ]
license = "GPLv2"

[dependencies]
i18n = ">=0.9.2"

[test_dependencies]
busted = "2.2.0"
luassert = "1.9.0"
Expand Down
71 changes: 68 additions & 3 deletions modules/i18n/i18n.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,71 @@
local currentDirectory = "modules/i18n/"
I18N_PATH = currentDirectory .. "i18nlib/i18n/" -- I18N_PATH is expected to be global inside the i18n module
local i18n = VFS.Include(I18N_PATH .. "init.lua", nil, VFS.ZIP)
local function _findI18nBase()
local luxDirs = VFS.SubDirs('.lux/5.1/', VFS.RAW_ONLY) or {}
for _, dir in ipairs(luxDirs) do
if dir:match('i18n@') then
local initPath = dir .. 'src/i18n/init.lua'
if VFS.FileExists(initPath, VFS.RAW_ONLY) then
return dir .. 'src/'
end
end
end
error("i18n library not found. Run 'lx sync' to install dependencies.")
end

local _origRequire = require
do
local _loaded = {}
local _base = _findI18nBase()
require = function(modname)
if _loaded[modname] then return _loaded[modname] end
local rel = modname:gsub("%.", "/")
local path = _base .. rel .. "/init.lua"
if not VFS.FileExists(path, VFS.RAW_FIRST) then
path = _base .. rel .. ".lua"
end
local src = VFS.LoadFile(path, VFS.RAW_FIRST)
if not src then error("module '" .. modname .. "' not found at " .. path) end
local chunk = assert(loadstring(src, path))
local result = chunk(modname)
_loaded[modname] = result or true
return _loaded[modname]
end
end
local i18n = require("i18n")
require = _origRequire

function i18n.loadFile(path)
local success, data = pcall(function()
local chunk = VFS.LoadFile(path, VFS.ZIP_FIRST)
return assert(loadstring(chunk))()
end)
if not success then
Spring.Log("i18n", LOG.ERROR, "Failed to parse file " .. path)
Spring.Log("i18n", LOG.ERROR, data)
return nil
end
i18n.load(data)
end

local _translate = i18n.translate
local missingTranslations = {}
function i18n.translate(key, data)
local result = _translate(key, data)
if result ~= nil then return result end
if not missingTranslations[key] then
missingTranslations[key] = true
Spring.Log("i18n", "notice", 'No translation found for "' .. key .. '"')
end
return (data and data.default) or key
end

function i18n.unitName(unitDefName, data)
data = data or {}
if Spring.GetConfigInt("language_english_unit_names", 1) == 1 then
data.locale = "en"
end
return i18n.translate("units.names." .. unitDefName, data)
end


local asianFont = 'fallbacks/SourceHanSans-Regular.ttc'
local translationDirs = VFS.SubDirs('language')
Expand Down
220 changes: 0 additions & 220 deletions modules/i18n/i18nlib/i18n/init.lua

This file was deleted.

Loading
Loading