Compare commits
2 Commits
eeffae6852
...
2813d9d5fe
| Author | SHA1 | Date | |
|---|---|---|---|
| 2813d9d5fe | |||
| 652200f28c |
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
})
|
||||
|
||||
@@ -8,4 +8,5 @@ require('Lib.color')
|
||||
require('Lib.immersiveCraftData')
|
||||
require('Lib.getObjectByGUID')
|
||||
require('Lib.receiveFields')
|
||||
require('Lib.registeredItems')
|
||||
require('Lib.requires')
|
||||
33
mods/SYSTEM/HelperLib/src/Lib/registeredItems.lua
Normal file
33
mods/SYSTEM/HelperLib/src/Lib/registeredItems.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
---@type table<string, Item>
|
||||
local registeredItems = {}
|
||||
|
||||
---@type table<string, table<string, Item>>
|
||||
local registeredItemsByMod = {}
|
||||
|
||||
---@param shortModName string
|
||||
---@param item Item
|
||||
function Smc.addRegisteredItem(shortModName, item)
|
||||
local itemName = item.itemDef.settings.name
|
||||
local modItems = registeredItemsByMod[shortModName]
|
||||
|
||||
if modItems == nil then
|
||||
registeredItemsByMod[shortModName] = {[itemName]=item}
|
||||
return
|
||||
end
|
||||
|
||||
assert(modItems[itemName] == nil)
|
||||
|
||||
registeredItems[itemName] = item
|
||||
modItems[itemName] = item
|
||||
end
|
||||
|
||||
---@param shortModName string
|
||||
---@return table<string, Item>?
|
||||
function Smc.getRegisteredItemsByMod(shortModName)
|
||||
return table.copy_with_metatables(registeredItemsByMod[shortModName])
|
||||
end
|
||||
|
||||
---@return table<string, Item>?
|
||||
function Smc.getRegisteredItems()
|
||||
return table.copy_with_metatables(registeredItems)
|
||||
end
|
||||
Submodule util/ide-helper updated: a8dfcb767b...52df233a28
Reference in New Issue
Block a user