Module:HeroData/nav: Difference between revisions

Auto-detect language from subpage
changed subpage detection logic
Line 12: Line 12:
     local herolabs_text_size = frame.args['herolabs_text_size']
     local herolabs_text_size = frame.args['herolabs_text_size']
     local debug_mode = frame.args['debug_mode']
     local debug_mode = frame.args['debug_mode']
   
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
local lang_code = get_language_from_subpage() -- Get the language code
local lang_code = lang_module.get_lang_code() -- Get the language code
      
      
     -- Turn debug_mode from string to bool, default to false
     -- Turn debug_mode from string to bool, default to false