La documentazione per questo modulo può essere creata in Modulo:ja-kanjitab/man
local m_utilities = require("Modulo:utilities")
local m_ja = require("Modulo:ja")
local export = {}
local lang = require("Modulo:languages").getByCode("ja")
local kanji_grade_links = {
"]",
"]",
"]",
"]",
"]",
"]",
"]", -- 7
"]", -- 8
"]" -- 9
}
-- this is the function that is called from templates
function export.show(frame)
PAGENAME = mw.title.getCurrentTitle().text
local args = frame:getParent().args
local categories = {}
local cells = {}
-- replace e.g. 時々 with 時時
local kanji = mw.ustring.gsub(PAGENAME, '()々', '%1%1')
-- remove non-kanji characters
kanji = mw.ustring.gsub(kanji, '', '')
local table_head = '<table align="right" class="wikitable" style="text-align:center; font-size:small; margin:0;"><tr><th colspan="' .. mw.ustring.len(kanji) .. '" style="font-weight:normal;">] in questo lemma</th></tr><tr lang="ja" class="Jpan" style="font-size:2em; background:#FFF; color:#000; line-height:1em;" >'
-- hold the single kanji as we iterate over all the kanji
local single_kanji = ""
-- hold a reading passed from the first unnamed parameter
local reading = ""
local actual_reading = ""
local okurigana = ""
local sortkey = ""
local yomi = args or ""
if yomi == "ok" or yomi == "j" then yomi = "jūbakoyomi" end -- on/kun is jūbakoyomi; NOTE: these are only applicable for two-kanji compounds
if yomi == "ko" or yomi == "y" or yomi == "yu" then yomi = "yutōyomi" end -- kun/on is yutōyomi; NOTE: these are only applicable for two-kanji compounds
if yomi == "on" or yomi == "o" then yomi = "on" end
if yomi == "kun" or yomi == "k" then yomi = "kun" end
if yomi == "irr" or yomi == "irreg" or yomi == "irregular" then yomi = "irregolare" end
if yomi == "kan" or yomi == "kanyo" or yomi == "kanyoon" then yomi = "kanyoon" end
-- if hiragana readings were passed,
-- make the "spelled with ..." categories, the readings cells on the lower level and build the sort key
-- otherwise rely on the pagename to make the original kanjitab and categories
table.insert(cells, '<tr style="background:#FFF; color:#000;">')
for i = 1, mw.ustring.len(kanji) do
single_kanji = mw.ustring.sub(kanji,i,i)
reading = args or ""
table.insert(cells, "<td>")
if reading ~= "" and mw.ustring.match(reading, '') then
-- subcategorize by reading if this is joyo kanji, don't do that for less common kanji, with exceptions
if (m_ja.kanji_grade(single_kanji) < 8 or mw.ustring.match(single_kanji, '')) and yomi ~= "irregular" then
-- table.insert(categories, "Japanese terms spelled with " .. single_kanji .. " read as " .. reading)
else
-- table.insert(categories, "Japanese terms spelled with " .. single_kanji)
end
-- commentato senza categorie inglesi!
actual_reading = args or ""
okurigana = args or ""
table.insert(cells, '<span class="Jpan" lang="ja">')
if actual_reading == "" and okurigana == "" then
sortkey = (sortkey .. reading)
table.insert(cells, reading)
elseif actual_reading ~= "" and okurigana == "" then
sortkey = (sortkey .. actual_reading)
table.insert(cells, reading)
table.insert(cells, " > ")
table.insert(cells, actual_reading)
elseif actual_reading == "" and okurigana ~= "" then
sortkey = (sortkey .. reading .. okurigana)
table.insert(cells, reading)
table.insert(cells, "(")
table.insert(cells, okurigana)
table.insert(cells, ")")
else
sortkey = (sortkey .. actual_reading .. okurigana)
table.insert(cells, reading)
table.insert(cells, "(")
table.insert(cells, okurigana)
table.insert(cells, ") > ")
table.insert(cells, actual_reading)
table.insert(cells, "(")
table.insert(cells, okurigana)
table.insert(cells, ")")
end
table.insert(cells, '</span>')
else
-- table.insert(categories, "Japanese terms spelled with " .. single_kanji)
-- no cat inglesi
end
if reading ~= "" and mw.ustring.match(reading, '') then table.insert(cells, "<br/>") end
table.insert(cells, "<small>")
local kanji_grade = m_ja.kanji_grade(single_kanji)
table.insert(cells, kanji_grade_links or "")
table.insert(cells, "</small>")
table.insert(cells, "</td>")
end
-- finish the html for the row
table.insert(cells, "</tr>")
local rendaku = args or ""
-- no categorie inglesi
-- if rendaku ~= "" then table.insert(categories, "Japanese terms with rendaku") end
if yomi ~= "" then
table.insert(cells, "<tr>")
if yomi == "on" then
--no categorie inglesi
--table.insert(categories, "Japanese terms read with on'yomi")
table.insert(cells, '<td colspan="' .. mw.ustring.len(kanji) .. '">]</td>')
elseif yomi == "kun" then
--no categorie inglesi
--table.insert(categories, "Japanese terms read with kun'yomi")
table.insert(cells, '<td colspan="' .. mw.ustring.len(kanji) .. '">]</td>')
elseif yomi == "yutōyomi" then
--no categorie inglesi
--table.insert(categories, "Japanese terms read with yutōyomi")
table.insert(cells, '<td colspan="' .. mw.ustring.len(kanji) .. '">]</td>')
elseif yomi == "jūbakoyomi" then
--no categorie inglesi
--table.insert(categories, "Japanese terms read with jūbakoyomi")
table.insert(cells, '<td colspan="' .. mw.ustring.len(kanji) .. '">]</td>')
elseif yomi == "irregolare" then
--no categorie inglesi
--table.insert(categories, "Japanese terms with irregular kanji readings")
table.insert(cells, '<td colspan="' .. mw.ustring.len(kanji) .. '"><i>lettura irregolare</i></td>')
elseif yomi == "kanyoon" then
--no categorie inglesi
--table.insert(categories, "Japanese terms read with kan'yōon")
table.insert(cells, '<td colspan="' .. mw.ustring.len(kanji) .. '">]</td>')
end
table.insert(cells, "</tr>")
end
-- use user-provided sortkey if we got one, otherwise
-- use the sortkey we've already made by combining the
-- readings if provided, if we have neither then
-- default to empty string and don't sort
local userprovided_sortkey = args or ""
if userprovided_sortkey ~= "" then sortkey = userprovided_sortkey end
if sortkey ~= "" then sortkey = m_ja.jsort(sortkey) end
-- will only use sortkey if sortkey is different from PAGENAME
if sortkey == "" then
return
table_head ..
mw.ustring.gsub(kanji, '(.)', '<td style="padding:0.5em;">]</td>') .. '</tr>' ..
table.concat(cells) ..
'</table>' ..
m_utilities.format_categories(categories, lang)
else
return
table_head ..
mw.ustring.gsub(kanji, '(.)', '<td style="padding:0.5em;">]</td>') .. '</tr>' ..
table.concat(cells) ..
'</table>' ..
m_utilities.format_categories(categories, lang, sortkey)
end
end
return export