local export = {}
local m_links = require("Module:links")
local m_ja = require("Module:ja")
local m_ja_link = require("Module:ja-link")
local m_ja_pron = require("Module:ja-pron")
local match = mw.ustring.match
local split = mw.text.split
local function map(list, func)
local result = {}
for _, item in ipairs(list) do
table.insert(result, func(item))
end
return result
end
function export.show(frame)
local params = {
= {},
= { list = true },
= {},
= { boolean = true },
= {}
}
local args, unrecognized_args = require("Module:parameters").process(frame:getParent().args, params, true)
for key, value in pairs(unrecognized_args) do
error("“" .. key .. "” is not a recognized parameter.")
end
local function ja(text) return '<span class="Jpan" lang="ja">' .. text .. '</span>' end
local pagename = mw.title.getCurrentTitle().text
local header = args or ('Inflection rules for the ' .. ja(pagename) .. ' form')
local function format_accent(pron, acc)
local ja_pron = m_ja_pron.accent(pron, acc)
--[[
local kana, romaji = ja_pron:match('(<span lang="ja" class="Jpan">.-) <span class="Latn"><samp>%</samp></span>')
if kana:find('ー') then
-- revert to the original kana zukai (unicode mandatory here)
local orig_kana = mw.ustring.gmatch(pron, '')
kana = mw.ustring.gsub(kana, '', orig_kana)
end
return kana .. ' (<i>' .. romaji .. '</i>)'
]]
local kana = mw.ustring.gsub(pron, "", '')
local romaji = ja_pron:match('<span lang="ja" class="Jpan">.- <span class="Latn"><samp>%</samp></span>')
return '<span class="Jpan" lang="ja">]</span> (<i>' .. romaji .. '</i>)'
end
local function format_word(word)
local accent, label
if word:find(':') then
word, label = match(word, '(.-):(.*)')
end
if word:find('') then
word, accent = match(word, '(.-)(+)')
accent = tonumber(accent)
end
local result
if accent then
result = format_accent(word, accent)
elseif not m_ja.script(word):find('Hani') and not word:find('^*') and args == 'y' then
result = m_ja_link.link({ lemma = word })
else
result = m_links.full_link({ term = word:gsub('^*', ''), lang = require("Module:languages").getByCode('ja') })
end
if label then
result = result .. ' (<i>' .. mw.ustring.gsub(label, '(+)', ja) .. '</i>)'
end
return result
end
local function format_cell(cell)
if cell == '' or cell == '-' then
return ''
else
return table.concat(map(split(cell, '/'), format_word), '<br>')
end
end
local function format_row(row)
local number_of_rows = #args
local predefined = {
= 'godan verbs (type 1)',
= 'ichidan verbs (type 2)',
= 'kami ichidan verbs (type 2a)',
= 'shimo ichidan verbs (type 2b)',
= 'irregular verbs (type 3)',
= 'adjectives',
}
if predefined then
return '! colspan=' .. number_of_rows .. ' | ' .. predefined
elseif not row:find(';') then
return '! colspan=' .. number_of_rows .. ' | ' .. row
else
local cells = map(split(row, ';'), format_cell)
for i = 1, number_of_rows - #cells do table.insert(cells, '') end
return '| ' .. table.concat(cells, ' || ')
end
end
local result = {}
table.insert(result, '<div class="NavFrame"><div class="NavHead">' .. header .. '</div><div class="NavContent">\n{| class=wikitable')
table.insert(result, "! " .. table.concat(args, " !! ") )
table.insert(result, '|-')
table.insert(result, table.concat(map(split(args, '\n'), function(row) return format_row(row) end), '\n|-\n'))
table.insert(result, '|}')
if args then
table.insert(result, '<p style="font-size:85%;">(Part of the accent information comes from the .)</p>')
end
table.insert(result, '</div></div>')
return table.concat(result, '\n')
end
return export