Item: add missing localization check
This commit is contained in:
@@ -31,6 +31,12 @@ 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
|
||||
@@ -79,6 +85,16 @@ 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)
|
||||
@@ -89,8 +105,7 @@ local function itemDefToLuantiDef(itemDef)
|
||||
local s = itemDef.settings
|
||||
local c = itemDef.callbacks
|
||||
|
||||
local title = s._title
|
||||
local description = s._description
|
||||
local title, description = s._title, s._description
|
||||
|
||||
if title == nil or title == '' then
|
||||
title = string.match(s.name, '%S:(%S+)')..'-title'
|
||||
@@ -100,9 +115,14 @@ local function itemDefToLuantiDef(itemDef)
|
||||
description = string.match(s.name, '%S:(%S+)')..'-desc'
|
||||
end
|
||||
|
||||
local titleTranslate, descriptionTranslate = S(title), S(description)
|
||||
|
||||
checkLocale(title, titleTranslate)
|
||||
checkLocale(description, descriptionTranslate)
|
||||
|
||||
if s._title_color ~= nil and s._description_color ~= nil then
|
||||
title = colorize(s._title_color ,S(title))
|
||||
description = colorize(s._description_color, S(description))
|
||||
titleTranslate = colorize(s._title_color , titleTranslate)
|
||||
descriptionTranslate = colorize(s._description_color, descriptionTranslate)
|
||||
else
|
||||
error('Item description color parameters cannot be empty.')
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user