Jump to content

Module:xbc-translit

From Wiktionary, the free dictionary

This module will transliterate Bactrian language text. 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 Module:xbc-translit/testcases.

Functions

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 mapping = {
	["α"] = "a",  ["β"] = "b",  ["γ"] = "g",  ["δ"] = "d",  ["ε"] = "e",  ["ζ"] = "z",
	["η"] = "ē",  ["θ"] = "θ",  ["ι"] = "i",  ["κ"] = "k",  ["λ"] = "l",  ["μ"] = "m",
	["ν"] = "n",  ["ο"] = "o",  ["π"] = "p",  ["ρ"] = "r",  ["ϸ"] = "š",  ["σ"] = "s",
	["τ"] = "t",  ["υ"] = "u",  ["φ"] = "f",  ["χ"] = "x",  ["ω"] = "ō",  ["ς"] = "s",
	
	["Α"] = "A",  ["Β"] = "B",  ["Γ"] = "G",  ["Δ"] = "D",  ["Ε"] = "E",  ["Ζ"] = "Z",
	["Η"] = "Ē",  ["Θ"] = "Θ",  ["Ι"] = "I",  ["Κ"] = "K",  ["Λ"] = "L",  ["Μ"] = "M",
	["Ν"] = "N",  ["Ο"] = "O",  ["Π"] = "P",  ["Ρ"] = "R",  ["Ϸ"] = "Š",  ["Σ"] = "S",
	["Τ"] = "T",  ["Υ"] = "U",  ["Φ"] = "F",  ["Χ"] = "X",  ["Ω"] = "Ō",
}

function export.tr(text, lang, sc)
	if sc == "Grek" then
		text = string.gsub(text, "[\1-\127\194-\244][\128-\191]*", mapping)
		return text
	end
end

return export