Module:User:Suzukaze-c/jpx-links

From Wiktionary, the free dictionary
Jump to navigation Jump to search
  • Lua error: bad argument #1 to 'match' (string expected, got nil) [term request?]
  • Lua error at line 70: Parameter 2 is not used by this template. [term request]
  • Lua error at line 70: Parameter 2 is not used by this template. [term request: secondary]
  • Lua error at line 70: Parameter 2 is not used by this template. [?error: empty parameter?]
  • Lua error at line 70: Parameter 2 is not used by this template. [term request: secondary]
  • Lua error at line 70: Parameter 2 is not used by this template. [?error: empty parameter?]
  • Lua error at line 85: attempt to index field '?' (a nil value) [term request?]
  • Lua error at line 85: attempt to index field '?' (a nil value) [term request]
  • Lua error at line 70: Parameter 2 is not used by this template. [term request: hist]
  • Lua error at line 70: Parameter 2 is not used by this template. [term request: hist]

  • Lua error: bad argument #1 to 'match' (string expected, got nil) [term] [automatic kana]
  • Lua error: bad argument #1 to 'match' (string expected, got nil) [term] [automatic kana]
  • Lua error: bad argument #1 to 'match' (string expected, got nil) [term] [automatic kana, none due to multiple readings]
  • Lua error: bad argument #1 to 'match' (string expected, got nil) [term] [automatic kana, disabled]

  • Lua error: bad argument #1 to 'match' (string expected, got nil) [term]
  • Lua error at line 70: Parameter 2 is not used by this template. [term + gloss]
  • Lua error at line 70: Parameter 2 is not used by this template. [term`secondary + gloss]
  • Lua error at line 70: Parameter 2 is not used by this template. [term`secondary<hist + gloss]
  • Lua error at line 70: Parameter 2 is not used by this template. [lang + term`secondary + gloss]
  • Lua error at line 70: Parameter 2 is not used by this template. [lang + term`secondary + t=gloss]
  • Lua error at line 70: Parameter 2 is not used by this template. [lang + term`secondary]
  • Lua error at line 70: Parameter 2 is not used by this template. [lang + term]

  • Lua error: bad argument #1 to 'match' (string expected, got nil) [term]
  • Lua error at line 70: Parameter 2 is not used by this template. [term + gloss]
  • Lua error at line 70: Parameter 2 is not used by this template. [term`secondary + gloss]
  • Lua error at line 70: Parameter 2 is not used by this template. [term`secondary<hist + gloss]
  • Lua error at line 70: Parameter 2 is not used by this template. [lang + term`secondary + gloss]
  • Lua error at line 70: Parameter 2 is not used by this template. [lang + term`secondary + t=gloss]
  • Lua error at line 70: Parameter 2 is not used by this template. [lang + term`secondary]
  • Lua error at line 70: Parameter 2 is not used by this template. [lang + term]

  • Lua error: bad argument #1 to 'match' (string expected, got nil) [term]
  • Lua error at line 70: Parameter 2 is not used by this template. [term + gloss]
  • Lua error at line 70: Parameter 2 is not used by this template. [term`secondary + gloss]
  • Lua error at line 70: Parameter 2 is not used by this template. [term<hist`secondary + gloss]
  • Lua error at line 70: Parameter 2 is not used by this template. [lang + term`secondary + gloss]
  • Lua error at line 70: Parameter 2 is not used by this template. [lang + term`secondary + t=gloss]
  • Lua error at line 70: Parameter 2 is not used by this template. [lang + term`secondary]
  • Lua error at line 70: Parameter 2 is not used by this template. [lang + term]

  • Lua error at line 70: Parameter 2 is not used by this template. [term`secondary<hist<hist + gloss]
  • Lua error at line 70: Parameter 2 is not used by this template. [term<hist<hist`secondary + gloss]
  • Lua error at line 70: Parameter 2 is not used by this template. [term<hist`secondary<hist<hist + gloss]

  • Lua error at line 70: Parameter 2 is not used by this template. [ja + term`secondary,secondary]
  • Lua error at line 70: Parameter 2 is not used by this template. [ja + term<hist`secondary<hist,secondary<hist]
  • Lua error: bad argument #1 to 'match' (string expected, got nil) [link in term] strip links from romaji
  • Lua error: bad argument #1 to 'match' (string expected, got nil) [link in term & romaji space]
  • Lua error: bad argument #1 to 'match' (string expected, got nil) [link in term & romaji space`secondary]
  • Lua error: bad argument #1 to 'match' (string expected, got nil) [link in term & romaji space`link in secondary]
  • Lua error: bad argument #1 to 'match' (string expected, got nil) [term`link in secondary]
  • Lua error: bad argument #1 to 'match' (string expected, got nil) [term is kana`secondary is kana]
  • Lua error: bad argument #1 to 'match' (string expected, got nil) [term is kanji`secondary is kanji]
  • Lua error: bad argument #1 to 'match' (string expected, got nil)
  • Lua error at line 70: Parameter 2 is not used by this template. [error: ????????]
  • Lua error: bad argument #1 to 'match' (string expected, got nil) [error: ????????]
  • Lua error: bad argument #1 to 'match' (string expected, got nil)

  • Lua error at line 70: Parameter 2 is not used by this template. [error: duplicate glosses]
  • Lua error at line 70: Parameter 2 is not used by this template. [error: extra parameters]
  • Lua error at line 70: Parameter 2 is not used by this template. [error: no tertiary]
  • Lua error at line 70: Parameter 2 is not used by this template. [error: lang does not exist]
  • Lua error at line 70: Parameter 2 is not used by this template. [error: non-japonic language]

local export = {}

local m_ja = require('Module:ja')
local m_links = require('Module:links')
local m_languages = require('Module:languages')
local m_scripts = require('Module:scripts')
local match = mw.ustring.match
local gsub = mw.ustring.gsub

local delimiter_conversion_table = {
	['<'] = ' &lt; ',
	['>'] = ' &gt; ',
	[','] = ', ',
}

function export.link(lang, term, face)
	return m_links.full_link(
		{
			lang = lang,
			-- sc = m_scripts.getByCode('Jpan'),
			term = term,
		},
		face,
		true -- allowSelfLink
	)
end

function export.process_terms(lang, text, face, text_type)
	if text == '' then
		return export.link(lang, false, face) -- '[Term?]' term request
	end

	local ret = ''

	if match(text, '[<>,]') then
		local term, delimiter, remainder = match(text, '^([^<>,]+)([<>,])(.*)$')
		ret = ret .. export.process_terms(lang, term, face, text_type)
		ret = ret .. delimiter_conversion_table[delimiter]
		ret = ret .. export.process_terms(lang, remainder, face, text_type)
	else
		local term = text
		term = mw.text.trim(term)
		-- term = m_ja.remove_ruby_markup(term)
		if text_type == 'term' then
			ret = ret .. export.link(lang, term, face)
		elseif text_type == 'tr' then
			-- XXX: different types of romaji for different situations
			ret = ret .. m_ja.kana_to_romaji(term)
		end
	end

	return ret
end

--[==[
	* $args.1: { 'ja' [optional for ja], 'あける', '開ける', 'to open' }
	* $data.face: {{jpx-m}}, $face: 'term'
]==]
function export.show(frame)
	local params = {
		[1] = { },

		['gloss'] = { },
		['t'] = { alias_of = 'gloss' },
		['pos'] = { },
		['lit'] = { },

		['face'] = { },
	}
	local args = require('Module:parameters').process(frame:getParent().args, params)

	local data = {}
	data.lang = nil
	data.terms = nil
	data.tr = nil
	data.gloss = args.gloss
	data.pos = args.pos
	data.lit = args.lit
	data.face = frame.args.face -- [[T:l]] or [[T:m]]

	-- [start] determine what $args[1] is composed of

	-- $data.lang
	local m_ja_script_result
	if match(args[1][1], '^[a-z][a-z][a-z]?$') then
		data.lang = table.remove(args[1], 1)
	else
		data.lang = 'ja'
	end
	data.lang = m_languages.getByCode(data.lang)

	-- $data.gloss
	m_ja_script_result = m_ja.script(args[1][#args[1]])
	if match(m_ja_script_result, 'Romaji') then
		data.gloss = (data.gloss and error('Duplicate glosses.') or table.remove(args[1]))
	end

	-- [end] determine what $args[1] is composed of

	-- generate $data.kana from entry
	if not data.kana then
		-- XXX: fairly hacky
		local readings = require('Module:User:Suzukaze-c/02').extract_ja_readings(data.kanji)
		if readings[1] then
			data.kana, data.tr = readings[1], data.lang.tr(readings[1])
		end
	end

	-- process $data.kanji, process $data.kana, generate $data.tr
	if data.kanji then
		data.kanji = export.process_terms(data.lang, data.kanji, data.face, 'term')
	end
	if data.kana == '-' then
		data.kana = nil
	end
	if data.kana then
		if not data.tr and data.kana ~= '' then
			data.tr = export.process_terms(data.lang, data.kana, data.face, 'tr')
		end
		data.kana = export.process_terms(data.lang, data.kana, data.face, 'term')
	end

	-- process $data.gloss, process $data.tr, process $data.pos, process $data.lit
	data.gloss = (data.gloss and m_links.mark(data.gloss, 'gloss', data.face, data.lang))
	data.tr = (data.tr and m_links.mark(data.tr, 'tr', data.face, data.lang))
	data.pos = (data.pos and m_links.mark(data.pos, 'pos', data.face, data.lang))
	data.lit = (data.lit and 'literally' .. m_links.mark(data.lit, 'gloss', data.face, data.lang))

	-- generate link annotations
	local annotations = {}
	if data.kana and data.kanji then
		table.insert(annotations, (data.is_kana_first and data.kanji or data.kana))
	end
	table.insert(annotations, data.tr)
	table.insert(annotations, data.gloss)
	table.insert(annotations, data.pos)
	table.insert(annotations, data.lit)
	if #annotations > 0 then
		annotations = ' ' .. m_links.mark(table.concat(annotations, ', '), 'annotations', data.face, data.lang)
	else
		annotations = false
	end

	return table.concat(
		{
			(data.is_kana_first and data.kana or data.kanji),
			(annotations and annotations or ''),
			' <code>[lang: ',
			data.lang:getCode(),
			']</code>',
		}
	)
end

return export