Module:ja-link

Mula Wiktionary

Ang dokumentasyon ng ng modyul na ito ay maaaring likhain sa Module:ja-link/doc

local export = {}
local m_ja = require("Module:ja")
local lang = require("Module:languages").getByCode("ja")
local sc = require("Module:scripts").getByCode("Jpan")
local m_links = require("Module:links")

function export.show(frame)
	local params = {
		[1] = { required = true },
		[2] = {},
		[3] = {},
		['gloss'] = { alias_of = 3 },
		['pos'] = {},
		['linkto'] = {},
		['caps'] = {},
		['rom'] = {},
	}
	local args = require("Module:parameters").process(frame:getParent().args, params)

	local lemma = args[1]
	local kana = args[2]
	-- if only one arg passed, it may be kana with hyphens
	if not kana then
		kana = lemma
		lemma = mw.ustring.gsub(lemma, '[%-^.]', '')
	end
	local gloss = args[3]
	local pos = args["pos"]
	local linkto = args["linkto"]
	local caps = args["caps"]
	local transliteration = args["rom"] or m_ja.kana_to_romaji(kana)

	if require("Module:scripts").getByCode('Hani'):countCharacters(transliteration) > 0 then
		error("The transliteration seems to have kanji in it. Was the kana reading properly provided?")
	end
	if caps then
		transliteration = mw.ustring.gsub(transliteration, "^%l", mw.ustring.upper)
		transliteration = mw.ustring.gsub(transliteration, " %l", mw.ustring.upper)
	end
	if transliteration ~= '-' then
		transliteration = "''" .. transliteration .. "''"
		transliteration = m_links.remove_links(transliteration) -- needed if $lemma has manual wikilinks
	end

	local ruby = m_ja.add_ruby_backend(lemma, kana)
	lemma = mw.ustring.gsub(lemma, "[%% ]", "")

	if mw.ustring.match(ruby, '%[%[') then -- for if $lemma has manual wikilinks
		return m_links.full_link({lang = lang, term = nil, alt = ruby, gloss = gloss, sc = sc, tr = transliteration, pos = pos})
	elseif linkto then
		return m_links.full_link({lang = lang, term = linkto, alt = ruby, gloss = gloss, sc = sc, tr = transliteration, pos = pos})
	else
		return m_links.full_link({lang = lang, term = lemma, alt = ruby, gloss = gloss, sc = sc, tr = transliteration, pos = pos})
	end

end

return export