| Module:User:DTLHS/translations Jul 21st 2013, 01:34, by DTLHS | | | | Line 250: | Line 250: | | | | | | | | for i1, v1 in pairs(t_args) do | | for i1, v1 in pairs(t_args) do | | − | result = result .. "* " .. i1 .. ": " | + | result = result .. "* " .. i1 .. ":" | | | local langcode = langname_t[i1] | | local langcode = langname_t[i1] | | | for i2, v2 in pairs(v1) do | | for i2, v2 in pairs(v1) do | | − | result = result .. build_translation(v2, frame, langcode, langinfo_t[langcode]) .. ", " | + | result = result .. " " .. build_translation(v2, frame, langcode, langinfo_t[langcode]) .. "," | | | end | | end | | − | result = string.sub(result, 0, #result - 2) | + | result = string.sub(result, 0, #result - 1) | | | result = result .. "\n" | | result = result .. "\n" | | | end | | end | local m_links = require("Module:links") local languages = mw.loadData("Module:languages") local export = {} function build_translation(t_params, frame, langcode, langinfo) -- modified from Module:translations local interwiki = t_params["iw"] or "" if interwiki == "" or interwiki == "-" then interwiki = "tneg" elseif interwiki == "+" then interwiki = "tpos" end NAMESPACE = mw.title.getCurrentTitle().nsText local ret = "" local categories = {} local sc = t_params["sc"] or ""; if sc == "" then sc = langinfo.scripts[1] end local lang = langcode local term = t_params["t"] or (NAMESPACE == "Template" and "term") or error("Term has not been specified.") local alt = t_params["alt"]; if alt == "" then alt = nil end local tr = t_params["tr"]; if tr == "" then tr = nil end local qualifier = t_params["q"]; if qualifier == "" then qualifier = nil end -- Interwiki link local interwiki_langs = { ["nan"] = "zh-min-nan", ["yue"] = "zh-yue", ["cmn"] = "zh", ["nb"] = "no", ["rup"] = "roa-rup", ["kmr"] = "ku", ["nds-de"] = "nds", ["nds-nl"] = "nds", ["pdt"] = "nds" } -- Don't show the link if the language is not recognised by MediaWiki -- or if the term contains links (for SOP translations) if term:find("[[", nil, true) or not mw.language.isKnownLanguageTag(interwiki_langs[lang] or lang) then interwiki = false end -- If no transliteration was given, try auto-transliteration if available. -- This information should really be in Module:languages, but for now it works. local has_auto_translit = { ["ab"] = true, ["ady"] = true, ["axm"] = true, ["ba"] = true, ["bg"] = true, ["be"] = true, ["cv"] = true, ["hy"] = true, ["el"] = true, ["ka"] = true, ["kk"] = true, ["ky"] = true, ["mk"] = true, ["mn"] = true, ["os"] = true, ["ru"] = true, ["si"] = true, ["tg"] = true, ["tt"] = true, ["ug"] = true, ["uk"] = true, ["xcl"] = true } local needs_translit = { ["alr"] = true, ["ab"] = true, ["abq"] = true, ["ady"] = true, ["agh"] = true, ["akv"] = true, ["am"] = true, ["ani"] = true, ["aqc"] = true, ["ar"] = true, ["as"] = true, ["av"] = true, ["ba"] = true, ["bbl"] = true, ["bdk"] = true, ["be"] = true, ["bg"] = true, ["bn"] = true, ["bo"] = true, ["bph"] = true, ["bxr"] = true, ["ce"] = true, ["cji"] = true, ["ckt"] = true, ["cv"] = true, ["dar"] = true, ["dlg"] = true, ["dng"] = true, ["dv"] = true, ["el"] = true, ["enf"] = true, ["ess"] = true, ["eve"] = true, ["evn"] = true, ["fa"] = true, ["gdo"] = true, ["got"] = true, ["gu"] = true, ["he"] = true, ["hi"] = true, ["hy"] = true, ["inh"] = true, ["itl"] = true, ["ja"] = true, ["ka"] = true, ["kap"] = true, ["kbd"] = true, ["kca"] = true, ["kjh"] = true, ["kk"] = true, ["km"] = true, ["kn"] = true, ["ko"] = true, ["krc"] = true, ["kv"] = true, ["kva"] = true, ["ky"] = true, ["lez"] = true, ["lo"] = true, ["mdf"] = true, ["mk"] = true, ["ml"] = true, ["mn"] = true, ["mr"] = true, ["my"] = true, ["myv"] = true, ["ne"] = true, ["or"] = true, ["os"] = true, ["ps"] = true, ["ru"] = true, ["rue"] = true, ["sah"] = true, ["si"] = true, ["ta"] = true, ["te"] = true, ["tg"] = true, ["th"] = true, ["ti"] = true, ["tt"] = true, ["tt"] = true, ["tyv"] = true, ["udm"] = true, ["ug"] = true, ["uk"] = true, ["ur"] = true, ["xal"] = true, ["yi"] = true, ["yrk"] = true} if not tr and has_auto_translit[lang] then local translit_module = require("Module:" .. lang .. "-translit") tr = translit_module.tr(alt or term) end -- Gender and number -- Iterate over all numbered parameters starting from 3, until one is empty. local genders = {} local g = t_params["g"] or "" if mw.ustring.find(g, "?", nil, true) then table.insert(categories, langinfo.names[1] .. " terms with incomplete gender") end table.insert(genders, g) -- Show the term ret = ret .. frame:expandTemplate{ title = sc, args = { m_links.language_link(term, alt, langinfo), lang = lang } } -- Show the interwiki link if interwiki then ret = ret .. "<span class=\"" .. interwiki .. "\"> [[:" .. (interwiki_langs[lang] or lang) .. ":" .. term .. "|(" .. (interwiki_langs[lang] or lang) .. ")]]</span>" end -- Show transliteration if tr then ret = ret .. " (" .. tr .. ")" elseif needs_translit[lang] then table.insert(categories, langinfo.names[1] .. " translations lacking transliteration") end -- Show the genders --if genders then -- local gen = require("Module:gender and number") -- ret = ret .. " " .. gen.format_list(genders) --end -- Add qualifier if qualifier then ret = ret .. " (" .. qualifier .. ")" end -- Add the categories for key, cat in ipairs(categories) do ret = ret .. "[[Category:" .. cat .. "]]" end return ret end function export.show(frame) local args = frame:getParent().args local t_args = {} local langinfo_t = {} local langname_t = {} for i, v in pairs(args) do if type(i) ~= "number" then s = mw.text.split(i, '_') langcode = s[1] if langinfo_t[langcode] == nil then langinfo = languages[langcode] or error("The language code \"" .. lang .. "\" is not valid.") langinfo_t[langcode] = langinfo end langname = langinfo_t[langcode]["names"][1] langname_t[langname] = langcode t = s[2] n = s[3] if t_args[langname] == nil then t_args[langname] = {} end if t_args[langname][n] == nil then t_args[langname][n] = {} end t_args[langname][n][t] = v end end local result = "" table.sort(t_args) for i1, v1 in pairs(t_args) do result = result .. "* " .. i1 .. ":" local langcode = langname_t[i1] for i2, v2 in pairs(v1) do result = result .. " " .. build_translation(v2, frame, langcode, langinfo_t[langcode]) .. "," end result = string.sub(result, 0, #result - 1) result = result .. "\n" end return result end return export |