跳转到内容

模組:Sarb-translit

維基詞典,自由的多語言詞典

這個模組會將古南阿拉伯文文字轉寫為拉丁字母。

最好不要直接從模板或其他模組調用此模組。要從模板中使用它,請以{{xlit}}做為替代;若要在模組中使用,則以Module:languages#Language:transliterate替代。

關於測試用例,請參閱Module:Sarb-translit/testcases

函數

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

local export = {}

local correspondences = {
	["𐩠"] = "h", ["𐩡"] = "l", ["𐩢"] = "ḥ", ["𐩣"] = "m", ["𐩤"] = "q",
	["𐩥"]= "w", ["𐩦"] = "s²", ["𐩧"] = "r", ["𐩨"] = "b", ["𐩩"] = "t",
	["𐩪"] = "s¹", ["𐩫"] = "k", ["𐩬"] = "n", ["𐩭"] = "ḫ", ["𐩮"] = "ṣ",
	["𐩯"] = "s³", ["𐩰"] = "f", ["𐩱"] = "ʾ", ["𐩲"] = "ʿ", ["𐩳"] = "ḍ",
	["𐩴"] = "g", ["𐩵"] = "d", ["𐩶"] = "ġ", ["𐩷"] = "ṭ", ["𐩸"] = "z",
	["𐩹"] = "ḏ", ["𐩺"] = "y", ["𐩻"] = "ṯ", ["𐩼"] = "ẓ",
	
	["𐩽"] = " ",
}

local numbers = {
	["𐩽"] = "1",
	["𐩭"] = "5",
	["𐩲"] = "10",
	["𐩾"] = "50",
	["𐩣"] = "100",
	["𐩱"] = "1000",
}

function export.tr(text, lang, sc)
	-- Interpret numbers.
	-- Will not work for thousands!
	text = text:gsub(
		"𐩿(..-)𐩿",
		function (number)
			local value = 0
			for digit in mw.ustring.gmatch(number, ".") do
				value = value + numbers[digit] or error("The character " .. digit .. " in " .. number .. " does not have a numeric value.")
			end
			return value
		end)
	
	text = mw.ustring.gsub(text, ".", correspondences)
	
	return text
end

return export