Module:ItemData/nav: Difference between revisions

added support for language subpages with more that 2 letters
changed subpage detection logic
Line 4: Line 4:
local generic_module = require('Module:GenericData')
local generic_module = require('Module:GenericData')
local util_module = require('Module:Utilities')
local util_module = require('Module:Utilities')
local function get_language_from_subpage()
    -- Get the full page path (including subpages)
    local full_page_name = mw.title.getCurrentTitle().fullText
   
    -- Split path by slashes
    local parts = {}
    for part in full_page_name:gmatch("[^/]+") do
        table.insert(parts, part)
    end
   
    -- Last part - potential language code
    local last_part = parts[#parts] or ""
   
    -- Check for language codes matching:
    -- 1. Exactly 2 letters (like 'ru'), OR
    -- 2. 2 letters + hyphen + any characters (like 'zh-hans')
    if last_part:match("^[a-z][a-z]$") or last_part:match("^[a-z][a-z]%-[%w]+$") then
        -- Convert to lowercase and replace _ with -
        return last_part:lower():gsub("_", "-")
    end
   
    return "en" -- Default to English
end


--With debug_mode on, it outputs unprocessed wikitext
--With debug_mode on, it outputs unprocessed wikitext
Line 63: Line 39:
             if slot == this_slot and this_cost >= min_souls and this_cost < max_souls then
             if slot == this_slot and this_cost >= min_souls and this_cost < max_souls then
                 local item_name_english = lang_module.get_string(item_key, "en") -- Get the English name
                 local item_name_english = lang_module.get_string(item_key, "en") -- Get the English name
                 local lang_code = get_language_from_subpage() -- Get the language code from the subpage
                 local lang_code = lang_module.get_lang_code() -- Get the language code from the subpage
                 local item_name_local = lang_module.get_string(item_key, lang_code) -- Get the localized name
                 local item_name_local = lang_module.get_string(item_key, lang_code) -- Get the localized name