Module:sortkeys

-- Load the wikitext of a page, look at each top-level header, and if it is a -- valid language name, generate a sortkey for it. Return all sortkeys. local function generate_sortkeys(title) local sortkeys = {} local success, title_object = pcall(mw.title.new, title) local content if success and title_object then -- If title was valid, get content. content = title_object:getContent end if not content then mw.log(string.format("Page name '%s' invalid or could not get page content. " .. "Could not create sortkeys.", title)) return sortkeys -- Return empty table. end local get_by_name = require "Module:languages".getByCanonicalName for language_name in content:gmatch("%f[=]==%f[^=](.-)%f[=]==%f[^=]") do		local lang = get_by_name(language_name) -- If name is valid, make a sortkey and add it to the table with the -- language code as key. if lang then sortkeys[lang:getCode] = (lang:makeSortKey(title, nil, true)) end end mw.logObject(sortkeys) return sortkeys end

return generate_sortkeys(mw.title.getCurrentTitle.text)