Module:ItemData/nav: Difference between revisionsGive feedback
fixed /en subpage being added to links |
added support for language subpages with more that 2 letters |
||
| Line 6: | Line 6: | ||
local function get_language_from_subpage() | local function get_language_from_subpage() | ||
-- Get the | -- Get the full page path (including subpages) | ||
local | local full_page_name = mw.title.getCurrentTitle().fullText | ||
-- | -- Split path by slashes | ||
local | local parts = {} | ||
for part in full_page_name:gmatch("[^/]+") do | |||
table.insert(parts, part) | |||
end | |||
-- | -- Last part - potential language code | ||
return | 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 | end | ||