Module:Sandbox/Dorumin/Translations

local p = {} local title = mw.title.getCurrentTitle local function getLocalizationsPage(script) local i18n_title = 'MediaWiki:Custom-' .. script .. '/i18n.json' local i18n = mw.title.new(i18n_title) return i18n end local function getTranslations(page) local text = page:getContent local languages = text:gmatch('\n   "%a%a%a?%-?%a?%a?') -- yeah, it's ugly but it does the job :P                                                            -- please tell me if you come up with a better way    return languages end local function getLanguageList(translations, frame)    local list =     for lang in translations do        lang = lang:sub(7)        if lang ~= 'qqq' and lang ~= '_metadata' then            local parser_func =             list = list .. '\n' .. frame:preprocess(parser_func)        end    end    return list:sub(2) end function p.main(frame)    if title.namespace ~= 0 then        return 'Namespace not supported.'    else        local i18n = getLocalizationsPage(title.rootText)        if i18n.exists then            local translations = getTranslations(i18n)            local list = getLanguageList(translations, frame)            return list        else return i18n.title .. ' does not exist.' end end end return p