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

@@ -66,3 +66,66 @@ core.register_on_joinplayer(function(player, last_login)
saturation = 1.0,
})
end)
-- Keys indicating the languages ​​for which localization presence is checked.
local LANG_CODES = {'en', 'ru'}
-- Number of missed localizations.
local missedLocaleCount = 0
local function checkLocale(strTranslate, langCodes)
local str = core.strip_escapes(strTranslate)
for _, langCode in ipairs(langCodes or LANG_CODES) do
if core.strip_escapes(core.get_translated_string(langCode, strTranslate)) == str then
missedLocaleCount = missedLocaleCount + 1
Logger.warningLog('Localization missing[%s][%s]. String: `%s`.', missedLocaleCount, langCode, str)
end
end
end
core.register_chatcommand('get_missing_locale', {
privs = {server = true},
description = '{short_mod_name:string?, lang_codes:string[]?}',
func = function(name, paramsStr)
local params = core.deserialize('return '..paramsStr or '{}')
if params == nil then
return false
end
local shortModName = params.short_mod_name
local langCodes = params.lang_codes
if shortModName ~= nil and type(shortModName) ~= 'string' then
return false
end
if langCodes ~= nil and type(langCodes) ~= 'table' then
return false
end
local items
if shortModName == '' or shortModName == nil then
items = Smc.getRegisteredItems()
else
items = Smc.getRegisteredItemsByMod(shortModName)
end
if items == nil then
return false, 'There are no items registered for this mod (or the entire game)'
end
---@param name string
---@param item Item
for name, item in pairs(items) do
local itemSettings = item.itemDef.settings
local title, desc = itemSettings._title, itemSettings._description
checkLocale(title, langCodes)
checkLocale(desc, langCodes)
end
return true, ''
end
})