Module:ja-link

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
This does the work of {{ja-r}}.
local m_ja = require("Module:ja")
local export = {}
 
function export.show(frame)
	local args = frame:getParent().args
	local lemma = args[1] or error("Page to be linked to has not been specified. Please pass parameter 1 to the module invocation.")
	local kana = args[2] or ""
	-- if only one arg passed, it may be kana with hyphens
	if kana == "" then 
		kana = lemma
		lemma = mw.ustring.gsub(lemma, '[%-]', '')
	end
	local gloss = args["gloss"] or "" 
	local pos = args["pos"] or "" 
	local linkto = args["linkto"] or "" 
	local caps = args["caps"] or ""
	local transliteration = m_ja.kana_to_romaji(kana)
	if caps ~= "" then 
		transliteration = mw.ustring.gsub(transliteration, "^%l", mw.ustring.upper)
		transliteration = mw.ustring.gsub(transliteration, " %l", mw.ustring.upper)
	end
	transliteration = "''" .. transliteration .. "''"
 
	--[[ The if-then logic for named param "gloss" appears to be unnecessary -- passing empty args doesn't do anything bad, they just get dropped, 
		so there's no need to sanity-check for the named params. --]]
 
	if linkto == "" then
		return frame:expandTemplate{ title = "l", args = {"ja", lemma, m_ja.add_ruby_backend(lemma, kana), gloss = gloss, sc = "Jpan", tr = transliteration, pos = pos}}
	else
		return frame:expandTemplate{ title = "l", args = {"ja", linkto, m_ja.add_ruby_backend(lemma, kana), gloss = gloss, sc = "Jpan", tr = transliteration, pos = pos}}
	end
 
end
 
return export