MyWikiBiz, Author Your Legacy — Wednesday September 28, 2022
Jump to navigationJump to search

Template:Module rating This is a module for Bopomofo Ruby and their mixed use with "normal" Ruby.


Normal Ruby characters go to either the top or the bottom of text, and follow the same horizontal, left-to-right direction that the text being annotated flows. Bopomofo, however, acts differently: it is traditional to put the bopomofo to the right of each character being phonetically labelled, laid out in a vertical direction.[1] As a result, it is non-trivial to lay out Bopomofo-annotated text.

This module roughly follows the methology established by Han.css in its DOM output.



-- 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')
		:tag('span')	-- inline-block
	return ru

-- 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')
	for i, v in ipairs(tbl) do
		:attr('rbspan', tostring(n))
	return ruby

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

-- 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