Definition from Wiktionary, the free dictionary
Jump to: navigation, search

This does all of the work of {{ja-usex}}. It displays an example or quote like {{usex}}, but unlike usex it adds furigana to the example and generates the romanization to be used as the transliteration comprising the second line of the quote or example.

local m_ja = require("Module:ja")

local export = {}

-- main entry point
	local args = frame:getParent().args
	local text = {}
	local example = args[1] or error("Example has not been specified. Please pass parameter 1 to the module invocation.")
	local second_param = args[2] or error("A kana form or a translation must be passed in parameter 2.")
	-- if user only specified two params, assume second param is translation, first param has no kanji
	local translation = args[3] or ""
	local romaji = args["rom"] or ""
	local manyou = args["m"] or args["manyou"] or ""
	local old_kana = args["m_kana"] or args["manyou_kana"] or ""
	local kana = ""
	local ref = args["ref"] or ""
	if translation == "" then 
		translation = second_param
		kana = example
		kana = second_param
	local tag_start = " <span style=\"color:darkgreen; font-size:x-small;\">&#91;" -- see also [[module:zh-usex]]
	local tag_end = "&#93;</span>"
	if manyou ~= "" then
		table.insert(text, ('<span lang="ja" class="Jpan">%s</span>'):format((old_kana ~= "") and m_ja.add_ruby_backend(manyou, old_kana) or manyou))
		table.insert(text, tag_start)
		table.insert(text, "[[w:Man'yōgana|Man'yōgana]]")
		table.insert(text, tag_end)
		table.insert(text, "<dd>")
	table.insert(text, ('<span lang="ja" class="Jpan">%s</span>'):format(m_ja.add_ruby_backend(example, kana)) .. ref)
	if manyou ~= "" then
		table.insert(text, tag_start)
		table.insert(text, "Modern spelling")
		table.insert(text, tag_end)
		table.insert(text, "</dd>")
	table.insert(text, "<dl><dd><i>")
	if romaji ~= "" then
		table.insert(text, romaji)
		-- add capitalization markup to the kana if manual capitalization is not already present
		if mw.ustring.match(kana, "[。?!]") and not mw.ustring.match(kana, "%^") then
			-- "「テスト」です。"→"「^テスト」^です。"
			kana = mw.ustring.gsub(kana, "([^()「」『』。?!]+)", "^%1")
			-- "「^此れ (^これ) ^は テスト です。」"→"「^此れ (^これ) は テスト です。」" (remove a "^" that appears between an ending bracket and a sentence-ending punctuation)
			kana = mw.ustring.gsub(kana, "([)」』]+)%^(.+)([。?!])", "%1%2%3")

		-- add romaji
		table.insert(text, m_ja.kana_to_romaji(kana))
	table.insert(text, "</i></dd><dd>")
	table.insert(text, translation)
	table.insert(text, "</dd></dl>")
	return table.concat(text)

return export