มอดูล:Cans-translit

จาก วิกิพจนานุกรม พจนานุกรมเสรี
ไปยังการนำทาง ไปยังการค้นหา

มอดูลนี้ใช้ถอดอักษรข้อความในอักษรCanadian syllabics.

The module should preferably not be called directly from templates or other modules. To use it from a template, use {{xlit}}. Within a module, use Module:languages#Language:transliterate.

For testcases, see มอดูล:Cans-translit/testcases.

ฟังก์ชัน[แก้ไข]

tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by sc, and language specified by lang. When the transliteration fails, returns nil.

local export = {}

-- to be discussed: not to create this module, but create individual modules instead?
function export.tr(text, lang, sc)
	local data = {
		{ --short-vowel
			"ᐁᐃᐅᐊᐯᐱᐳᐸᑌᑎᑐᑕᑫᑭᑯᑲᒉᒋᒍᒐᒣᒥᒧᒪᓀᓂᓄᓇᓭᓯᓱᓴᔦᔨᔪᔭᖊᖋᖌᖍᕃᕆᕈᕍᕂᕄᕊᕋᔐᔑᔓᔕᕓᕕᕗᕙᕞᕠᕤᕦᘚᘛᘕᘔᓓᓕᓗᓚᙯᕿᖁᖃᙰᖏᖑᖓ ᙱᙳᙵᕴᕵᕷᕹ",
			"อปตกจมนซยรรรฌฟธ1ล2ง3ฮ",
			{"ซ̱","ก̱","ง̱"},
			"เิ็ะ",
			function(a,b) return a..b end
		},
		{ --w
			"ᐌᐍᐎᐏᐒᐓᐗᐘᐺᐻᐼᐽᑀᑁᑄᑅᑗᑘᑙᑚᑝᑞᑡᑢᑴᑵᑶᑷᑺᑻᑾᑿᒒᒓᒔᒕᒘᒙᒜᒝᒬᒭᒮᒯᒲᒳᒶᒷ"
				.. "ᓉᓊ  ᓋᓌ  ᓶᓷᓸᓹᓼᓽᔀᔁᔯᔰᔱᔲᔵᔶᔹᔺᔗᔘᔙᔚᔝᔞᔡᔢᓜᓝᓞᓟᓢᓣᓦᓧ",
			"อปตกจมนซยร1",
			{"ซ̱"},
			"เเิิ็็ะะ",
			function(a,b) return a.."ฺว"..b end
		},
		{ --long-vowel
			"ᐄᐆᐋᐲᐴᐹᑏᑑᑖᑮᑰᑳᒌᒎᒑᒦᒨᒫᓃᓅᓈᓰᓲᓵᔩᔫᔮᕇᕉᕌᔒᔔᔖᕖᕘᕚᕢᕥᕧᓖᓘᓛᐐᐔᐙᖀᖂᖄᕶᕸᕺ",
			"อปตกจมนซยรฌฟธลว1ฮ",
			{"ก̱"},
			"ีโา",
			function(a,b) return a..b end
		},
		{ --w-long
			"ᐐᐑᐔᐕᐖᐙᐚᐛᐾᐿᑂᑃ ᑆᑇᑈᑛᑜᑟᑠ ᑣᑤᑥᑸᑹᑼᑽ ᒀᒁᒂᒖᒗᒚᒛ ᒞᒟᒠᒰᒱᒴᒵ ᒸᒹᒺ     ᓍᓎᓏ"
				.. "ᓠᓡᓤᓥ ᓨᓩ ᓺᓻᓾᓿ ᔂᔃᔄᔛᔜᔟᔠ ᔣᔤ ᔳᔴᔷᔸ ᔻᔼᔽ     ᕎᕏ      ᕛᕜ      ᕨᕩ ",
			"อปตกจมนลซฌยรฟธ",
			{},
			"ีีโโโาาา",
			function(a,b) return a.."ฺว"..b end
		},
		{ --individual
			"ᑊᐟᐠᐨᒼᐣᐢᐧᐤᐦᕁᕽᓫᕑᑉᑦᒡᒃᒻᓐᔅᔥᔾᓪᕐᕪ‡ᒄᔉᖅᖕᖖᕝᖦᕀᕻᕼ",
			"ปตกจมนซยวฮ11ลรปตจกมนซฌยลรธธ234ง5ฝลยฮฮ",
			{"ฮ์ก","ก์ว","ซ์ก","ก̱","ง̱"},
		},
	}
	for i=1,#data do
		if data[i][4] then
			local length = mw.ustring.len(data[i][4])
			for c=1,mw.ustring.len(data[i][1]) do
				local s = mw.ustring.sub(data[i][1],c,c)
				local a = mw.ustring.sub(data[i][2],math.ceil(c/length),math.ceil(c/length)); if tonumber(a) then a = data[i][3][tonumber(a)] end
				local b = mw.ustring.sub(data[i][4],(c-1)%length+1,(c-1)%length+1)
				if s ~= " " then text = mw.ustring.gsub(text,s,data[i][5](a,b)) end
			end
		else
			for c=1,mw.ustring.len(data[i][1]) do
				local s = mw.ustring.sub(data[i][1],c,c)
				local a = mw.ustring.sub(data[i][2],c,c); if tonumber(a) then a = data[i][3][tonumber(a)] end
				text = mw.ustring.gsub(text,s,a)
			end
		end
	end
	text = mw.ustring.gsub(text, "([ก-ฮ]̱?)ะ([ก-ฮ]̱?)([ก-ฮ]̱?)", "%1ั%2%3")
	text = mw.ustring.gsub(text, "([ก-ฮ]̱?)ะ([ก-ฮ]̱?) ", "%1ั%2 ")
	text = mw.ustring.gsub(text, "([ก-ฮ]̱?)ะ([ก-ฮ]̱?)$", "%1ั%2")
	return text
end

return export