Add missing locale admin command. Remove auto-check missing locale`

This commit is contained in:
Van
2026-03-08 20:56:48 +03:00
parent 652200f28c
commit 2813d9d5fe
4 changed files with 103 additions and 21 deletions

View File

@@ -31,12 +31,6 @@ local RARITY_INDEX = {
['unique'] = 0
}
-- Keys indicating the languages ​​for which localization presence is checked.
local LANG_CODES = {'en', 'ru'}
-- Number of missed localizations.
local missedLocaleCount = 0
---@class Item
---@field itemDef Item.ItemDefinition
---@field luantiDef ItemDefinition
@@ -85,23 +79,12 @@ local defMerge = function(...)
return tableMerge(...)
end
local function checkLocale(str, strTranslate)
local modName = Mod.getInfo().name
for _, langCode in ipairs(LANG_CODES) do
if core.get_translated_string(langCode, strTranslate) == str then
missedLocaleCount = missedLocaleCount + 1
Logger.warningLog('Localization missing[%s][%s]. String: `%s`. Mod: `%s`', missedLocaleCount, langCode, str, modName)
end
end
end
---@param itemDef Item.ItemDefinition
---@return NodeDefinition|ItemDefinition
local function itemDefToLuantiDef(itemDef)
local modName = Mod.getInfo().shortName
local S = core.get_translator(modName)
itemDef = tableCopy(itemDef)
local s = itemDef.settings
local c = itemDef.callbacks
@@ -117,9 +100,6 @@ local function itemDefToLuantiDef(itemDef)
local titleTranslate, descriptionTranslate = S(title), S(description)
checkLocale(title, titleTranslate)
checkLocale(description, descriptionTranslate)
if s._title_color ~= nil and s._description_color ~= nil then
titleTranslate = colorize(s._title_color , titleTranslate)
descriptionTranslate = colorize(s._description_color, descriptionTranslate)
@@ -178,12 +158,16 @@ function Item:new(itemDef)
'Please note that the `description` field should not be used when registering an item. '..
'Use `_title` and `_description` instead.')
itemDef = tableCopy(itemDef)
-- Adding default parameters
itemDef = defMerge(itemDef, self.defaultDef, true)
local s = itemDef.settings
local shortModName = Mod.getInfo().shortName
if s._add_mod_name then
s.name = Mod.getInfo().shortName .. ':' .. s.name
s.name = shortModName .. ':' .. s.name
end
---@type Item
@@ -215,6 +199,7 @@ function Item:new(itemDef)
instance.itemDef = itemDef
instance.luantiDef = luantiDef
Smc.addRegisteredItem(shortModName, instance)
return instance
end