Module:links Mar 31st 2013, 01:47 | | Line 42: | Line 42: | | -- links, these are replaced with links to the correct section. | | -- links, these are replaced with links to the correct section. | | function export.language_link(text, alt, lang) | | function export.language_link(text, alt, lang) | − | if text and not mw.ustring.match(text, "%[%[.-%]%]") then | | − | text = export.prepare_title(lang, text) | | − | elseif text == nil and alt then | | − | text = export.prepare_title(lang, alt) | | − | end | | − | | | | if mw.ustring.match(text, "%[%[.-%]%]") then | | if mw.ustring.match(text, "%[%[.-%]%]") then | | text = mw.ustring.gsub(text, "%[%[(.-)|(.-)%]%]", | | text = mw.ustring.gsub(text, "%[%[(.-)|(.-)%]%]", | Line 54: | Line 48: | | "[[%1#" .. languages[lang]["names"][1] .. "|" .. (alt or "%1") .. "]]") | | "[[%1#" .. languages[lang]["names"][1] .. "|" .. (alt or "%1") .. "]]") | | else | | else | − | text = "[[" .. text .. "#" .. languages[lang]["names"][1] .. "|" .. (alt or text) .. "]]" | + | text = "[[" .. export.prepare_title(lang, text) .. "#" .. languages[lang]["names"][1] .. "|" .. (alt or text) .. "]]" | | end | | end | | | | | Line 83: | Line 77: | | | | | | if gloss then | | if gloss then | − | table.insert(annotations, "<span class='mention-gloss'>" .. gloss .. "</span>") | + | table.insert(annotations, "<span class=\"mention-gloss-double-quote\">"</span><span class='mention-gloss'>" .. gloss .. "</<span class=\"mention-gloss-double-quote\">"</span>span>") | | end | | end | | | | |
- This module needs documentation and categorisation. Please create the documentation page.
--[=[ See [[Template:l]], [[Template_talk:l#Lua-ising]] ]=]-- local languages = mw.loadData("Module:languages") local export = {} -- This is supposed to be used in {{l}}. -- Similar functions can be used in for example a form-of template, {{term}}, etc. function export.template_l(frame) local args = frame:getParent().args local text = args[2]; if text == nil or text == "" then error("The second parameter (word) has not been given.") end local alt = args[3]; if alt == "" or alt == text then alt = nil end local lang = args[1]; if lang == nil or lang == "" then error("The first parameter (language code) has not been given.") end local script = args["sc"]; if script == "" then script = nil end --local gender = args["g"]; if g == "" then gender = nil end local translit = args["tr"]; if translit == "" then translit = nil end local gloss = args["gloss"]; if gloss == "" then gloss = nil end if not script then script = languages[lang].scripts[1] end return export.annotated_link(text, alt, lang, "span", script, translit, gloss) end -- Prepare title: remove macrons, etc. function export.prepare_title(lang, text) if lang == "la" then local la_utilities = require("Module:la-utilities") text = la_utilities.strip_macrons(text) end return text end -- Creates a basic wikilink to the given term. If the text already contains -- links, these are replaced with links to the correct section. function export.language_link(text, alt, lang) if mw.ustring.match(text, "%[%[.-%]%]") then text = mw.ustring.gsub(text, "%[%[(.-)|(.-)%]%]", "[[%1#" .. languages[lang]["names"][1] .. "|" .. "%2" .. "]]") text = mw.ustring.gsub(text, "%[%[([^|]-)%]%]", "[[%1#" .. languages[lang]["names"][1] .. "|" .. (alt or "%1") .. "]]") else text = "[[" .. export.prepare_title(lang, text) .. "#" .. languages[lang]["names"][1] .. "|" .. (alt or text) .. "]]" end return text end -- Create a tagged text from a given text. This is equivalent of the script templates. function export.tag_text(text, lang, tag, class) if not class then return "<" .. tag .. " lang=\"" .. lang .. "\">" .. text .. "</" .. tag .. ">" else return "<" .. tag .. " lang=\"" .. lang .. "\" class=\"" .. class .. "\">" .. text .. "</" .. tag .. ">" end return text end -- Create a full link to a term. function export.annotated_link(text, alt, lang, tag, class, translit, gloss) text = export.language_link(text, alt, lang) -- link it text = export.tag_text(text, lang, tag, class) -- tag it local annotations = {} if translit then table.insert(annotations, "<span lang=\"\">" .. translit .. "</span>") end if gloss then table.insert(annotations, "<span class=\"mention-gloss-double-quote\">"</span><span class='mention-gloss'>" .. gloss .. "</<span class=\"mention-gloss-double-quote\">"</span>span>") end if #annotations > 0 then text = text .. " (" .. table.concat(annotations, ", ") .. ")" end return text end return export | |