Changes

1,550 bytes added ,  05:50, 16 July 2021
Pywikibot 6.4.0
-- Template for generating Ruby for Chinese characters.
local p = {}

-- Annotate a single character with bopomofo.
-- This can be done in a template... but something else can't.
function p._zhuyin1(char, bopo, tone) -- inline-table
local ru = mw.html.create('span')
ru
:addClass('zhuyin-ru')
:wikitext(char)
:tag('span') -- inline-block
:addClass('zhuyin-rt')
:tag('span')
:addClass('zhuyin-rt-phon')
:wikitext(bopo)
:done()
:tag('span')
:addClass('zhuyin-rt-tone')
:wikitext(tone)
return ru
end

-- Annotate objects in pinyin.
-- Pinyin orthography allow multiple characters to be annotated.
-- In this case, we might be adding a pinyin to multiple bopo-annotated pairs.
-- (And this of course applies to other romanisations of Chinese.)
function p._pinyin(tbl, pinyin, n)
n = n or #tbl
local ruby = mw.html.create('ruby')
ruby:addClass('zhuyin-container')
for i, v in ipairs(tbl) do
ruby:node(v)
end
ruby:tag('rt')
:attr('rbspan', tostring(n))
:wikitext(pinyin)
return ruby
end

-- This is for test.
function p.test()
return p._pinyin({
p._zhuyin1('謝', 'ㄒㄧㄝ', 'ˋ'),
p._zhuyin1('謝', 'ㄒㄧㄝ', '˙')
}, 'xièxie', 2)
end

-- Now the CSS still needs to be written. And the interface is obviously clumsy,
-- and not translatable to templates yet. The main problem is that we will need
-- to either separate the syllables themselves or come up with a way for the user
-- to express the separation in a template-string.
--
-- Also there's a point in tagging stuff with lang

return p