Module:User:Suzukaze-c/Hani-tab

-- is "tab" short for "table"?

local export = {}

local m_languages = require("Module:languages") local m_scripts = require("Module:scripts") local m_links = require("Module:links")

local gsub = mw.ustring.gsub local upper = mw.ustring.upper

local hanzi_local_name = { ja = 'kanji', ko = 'hanja', vi = 'Hán tự', }

local iteration_marks = { ja = '々', vi = 'ヌ', }

local elements = {}

elements.table = function(data) return mw.html.create('table') :addClass('wikitable') :css('text-align', 'center') :css('font-size', 'small') :done end

elements.table_head = function(data) return mw.html.create('tr') :tag('th') :attr('colspan', data.colspan) :css('font-weight', 'normal') :wikitext(data.title) :done :done end

elements.table_row_a = function(data) return mw.html.create('tr') :attr('lang', data.lang:getCode) :addClass(data.sc:getCode) :css('font-size', '2em') :css('background', 'white') :css('line-height', '1') :done end

elements.table_row_a_cell = function(data) return mw.html.create('td') :css('padding', '0.5em') :wikitext(m_links.language_link({ lang = data.lang, term = data.char })) :done end

function export.show(frame) local params = { [1] = { required = true, default = "und" },

-- ja		[2] = { list = true, allow_holes = true }, yomi = { },

-- testing用 x_pagename = { }, }	local args = require("Module:parameters").process(frame:getParent.args, params)

local lang = m_languages.getByCode(args[1]) local chars = args.x_pagename or mw.title.getCurrentTitle.text local sc = m_scripts.findBestScript(chars, lang) local hani_tab local hani_tab_row_a local categories

if iteration_marks[lang:getCode] then chars = gsub(chars, '(.)' .. iteration_marks[lang:getCode], '%1%1') -- change "時々" to "時時" end chars = gsub(chars, '[^' .. m_scripts.getByCode('Hani'):getCharacters .. ']', '') -- remove non-Hani characters chars = mw.text.split(chars, '')

hani_tab = elements.table :node(elements.table_head({ colspan = #chars, title = '' .. gsub(hanzi_local_name[lang:getCode], '^.', upper) .. ' in this term' })) :done hani_tab_row_a = elements.table_row_a({ lang = lang, sc = sc }) :done

for _, char in ipairs(chars) do		hani_tab_row_a :node(elements.table_row_a_cell({ lang = lang, char = char })) :done end

hani_tab :node(hani_tab_row_a) :done

if lang:getCode == 'ja' and (table.maxn(args[2]) ~= 0 or args.yomi) then hani_tab, categories = require('Module:User:Suzukaze-c/Hani-tab/ja').main({ hani_tab = hani_tab, chars = chars, readings = args[2], yomi = args.yomi }) elseif lang:getCode == 'ko' then hani_tab = require('Module:User:Suzukaze-c/Hani-tab/ko').main({ hani_tab = hani_tab, chars = chars }) end

if categories then -- categories = require("Module:utilities").format_categories(categories)

for i, category in ipairs(categories) do categories[i] = '[' .. category .. ']'		end

categories = table.concat(categories) end

return tostring(hani_tab) .. (categories or '') end

return export