Module:ja-usex

Hello, you have come here looking for the meaning of the word Module:ja-usex. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:ja-usex, but we will also tell you about its etymology, its characteristics and you will know how to say Module:ja-usex in singular and plural. Everything you need to know about the word Module:ja-usex you have here. The definition of the word Module:ja-usex will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:ja-usex, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

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.

Requiring Module:ja, Module:scripts, Module:parameters, Module:utilities, Module:links, Module:languages, Module:ja-ruby.

Informal testcases:


local export = {}

local remove_ruby_markup = require("Module:ja").remove_ruby_markup
local kana_to_romaji = require("Module:Hrkt-translit").tr
-- ]
-- ]
-- ]
-- ]
-- ]
-- ]

local lang = require("Module:languages").getByCode("ja")
local pagename = mw.loadData("Module:headword/data").pagename

local HaniHiraKana_characters
local function test_script(text, scriptCode, entirely)
	if type(text) == "string" and type(scriptCode) == "string" then
		local characters
		if scriptCode == "HaniHiraKana" then
			if HaniHiraKana_characters then
				return HaniHiraKana_characters
			end
			local getScriptByCode = require("Module:scripts").getByCode
			characters = ""
			for code in scriptCode:gmatch("%u%l%l%l") do
				characters = characters .. getScriptByCode(code):getCharacters()
			end
		else
			characters = require("Module:scripts").getByCode(scriptCode):getCharacters()
		end

		local out
		if entirely then
			out = mw.ustring.match(text, "^+$")
		else
			text = mw.ustring.gsub(text, "%W", "")
			out = mw.ustring.find(text, "")
		end

		return out
	else
		mw.log("Parameters to test_script were incorrect.")
	end
end

-- main entry point
function export.show(frame)
	local params = {
		 = {},
		 = {},
		 = {},
		 = {},
		 = {},
		 = {},
		 = { alias_of = "manyou" },
		 = {},
		 = { alias_of = "manyou_kana" },
		 = {},
		 = {},
		 = {},	-- not currently used
	}
	local args = require("Module:parameters").process(frame:getParent().args, params)

	local literally = args.lit

	local sortkey
	-- Use sort parameter, or title if it consists only of kana.
	if args.sort then
		sortkey = args.sort
	elseif test_script(pagename, "Hira", true) or test_script(pagename, "Kana", true) then
		sortkey = pagename
	else
		-- ]
		require("Module:debug").track("ja-usex/no sortkey")
	end

	-- Process sortkey.
	if sortkey then
		sortkey = (lang:makeSortKey(sortkey))
	end

	local text = {}
	local categories = { "Japanese terms with usage examples" }

	local example, kana, translation

	-- Custom errors are preferable to the generic "These parameters are required.",
	-- which would be generated if "required = true" were added to the tables for parameters 1 and 2.
	if not args then
		error("Usage example text has not been given.")
	elseif test_script(args, "Hani") then
		example = args

		if args and test_script(args, "HaniHiraKana") then
			kana = args
			translation = args
		else
			error("Kana spelling of the usage example text has not been given.")
		end
	elseif test_script(args, "HaniHiraKana") then
		example = args

		if args and test_script(args, "HaniHiraKana") then
			kana = args
			translation = args
		else
			kana = args
			translation = args
		end
	end

	if (not translation) then
		translation = '<small>(please add an English translation of this example)</small>'
		table.insert(categories, "Requests for translations of Japanese usage examples")
	end

	local romaji = args
	local manyou = args
	local old_kana = args
	local ref = args

	local tag_start = " <span style=\"color:darkgreen; font-size:x-small;\">&#91;" -- see also ]
	local tag_end = "&#93;</span>"

	if manyou then
		table.insert(text, ('<span lang="ja" class="Jpan">%s</span>'):format(old_kana ~= "" and require('Module:ja-ruby').ruby_auto{
			term = manyou,
			kana = old_kana,
		} or manyou))
		table.insert(text, tag_start)
		table.insert(text, "]")
		table.insert(text, tag_end)
		table.insert(text, "<dd>")
	end

	local ruby_text
	if example and kana and example ~= kana then
		ruby_text = require('Module:ja-ruby').ruby_auto{
			term = example,
			kana = kana,
		}
	else
		ruby_text = remove_ruby_markup(kana)
		kana = require("Module:links").remove_links(kana)
	end
	if ruby_text then
		if string.find(ruby_text, "[[", 1, true) then
			ruby_text = require("Module:links").language_link{ term = ruby_text, lang = lang}
		end
		table.insert(text, ('<span lang="ja" class="Jpan">%s</span>'):format(ruby_text))
	end

	if ref then
		table.insert(text, ref)
	end

	if manyou then
		table.insert(text, tag_start)
		table.insert(text, "Modern spelling")
		table.insert(text, tag_end)
		table.insert(text, "</dd>")
	end

	if kana or romaji or translation then
		table.insert(text, "<dl>")
	end
	if kana or romaji then
		table.insert(text, '<dd><i><span class="tr">')
		if romaji then
			table.insert(text, romaji)
		elseif kana then
			-- add capitalization markup to the kana if manual markup is not present
			if mw.ustring.match(kana, "") and not mw.ustring.match(kana, "%^") then
				-- "「テスト」です。"→"「^テスト」^です。"
				kana = mw.ustring.gsub(kana, "(+)", "^%1")

				-- remove "^" in ~other certain circumstances~
				-- TESTS: https://en.wiktionary.org/?oldid=51248532
				kana = mw.ustring.gsub(kana, "()%^", "%1")
				kana = mw.ustring.gsub(kana, "()()%^", "%1%2")
			end

			-- add romaji
			table.insert(text, kana_to_romaji(kana, "ja"))
		end
		table.insert(text, "</span></i></dd>")
	end
	if translation then
		table.insert(text, "<dd>" .. translation .. "</dd>")
	end
	if literally then
		table.insert(text, "<dd>(literally, “" ..  literally .. "”)</dd>")
	end
	table.insert(text, "</dl>")

	return table.concat(text) .. require("Module:utilities").format_categories(categories, lang, args.sort)
end

return export