Module:ja-usex

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
The following documentation is located at Module:ja-usex/documentation. [edit]
See also: subpages of this module.

This does all of the work of {{ja-usex}}. It displays and 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
function export.show(frame)
	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 kana = ""
	if translation == "" then 
		translation = second_param
		kana = example
	else
		kana = second_param
	end
 
	table.insert(text, ('<span lang="ja" class="Jpan">%s</span>'):format(m_ja.add_ruby_backend(example, kana)))
	table.insert(text, "<dl><dd>''")
	-- capitalize first letter if last letter ends in period, question mark, or exclamation point
	if mw.ustring.match(kana, "[。?!]$") then 
		table.insert(text, (mw.ustring.gsub(m_ja.kana_to_romaji(kana), "^%'.-%l", mw.ustring.upper)))
	else
		table.insert(text, m_ja.kana_to_romaji(kana))
	end				
	table.insert(text, "''</dd><dd>")
	table.insert(text, translation)
	table.insert(text, "</dd></dl>")
	return table.concat(text)
end
 
return export