Module:ohel-translit

From Linguifex
Revision as of 18:05, 6 July 2026 by Nehster9 (talk | contribs) (Created page with "local export = {} local tt = {} tt["Runr"] = { {"ᚨ", "a"}, {"ᛒ", "b"}, {"ᛞ", "d"}, {"ᛖ", "e"}, {"ᚠ", "f"}, {"ᚷ", "g"}, {"ᚺ", "h"}, {"ᛁ", "i"}, {"ᛃ", "j"}, {"ᚲ", "k"}, {"ᛚ", "l"}, {"ᛗ", "m"}, {"ᚾ", "n"}, {"ᛟ", "o"}, {"ᛈ", "p"}, {"ᚱ", "r"}, {"ᛊ", "s"}, {"ᛏ", "t"}, {"ᚢ", "u"}, {"ᚹ", "w"}, {"ᛉ", "z"}, } tt["Latn"] = require("Module:table").invert(tt["Runr"]) function export.tr(text, lang, sc) text = mw.ustrin...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This module will transliterate Old Heldic 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:ohel-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 tt = {}
tt["Runr"] = {
	{"ᚨ", "a"},
	{"ᛒ", "b"},
	{"ᛞ", "d"},
	{"ᛖ", "e"},
	{"ᚠ", "f"},
	{"ᚷ", "g"},
	{"ᚺ", "h"},
	{"ᛁ", "i"},
	{"ᛃ", "j"},
	{"ᚲ", "k"},
	{"ᛚ", "l"},
	{"ᛗ", "m"},
	{"ᚾ", "n"},
	{"ᛟ", "o"},
	{"ᛈ", "p"},
	{"ᚱ", "r"},
	{"ᛊ", "s"},
	{"ᛏ", "t"},
	{"ᚢ", "u"},
	{"ᚹ", "w"},
	{"ᛉ", "z"},
}

tt["Latn"] = require("Module:table").invert(tt["Runr"])

function export.tr(text, lang, sc)
	text = mw.ustring.lower(text)
	
	for _, rule in ipairs(tt[sc]) do
		text = mw.ustring.gsub(text, rule[1], rule[2])
	end

    return text
end

function export.template_tr(frame)
	local args = require("Module:parameters").process(frame.args, {
		[1] = {required = true}, -- text
		[2] = {required = true, default = "ohel"},
		["sc"] = {default = require("Module:scripts").findBestScriptWithoutLang(frame.args[1])}
	})
	
	local tr = export.tr(args[1], "ohel", args.sc)
	
	return tr or "-"	
end

return export