Module:hort-translit: Difference between revisions

From Linguifex
Jump to navigation Jump to search
Nehster9 (talk | contribs)
Created page with "local export = {} local tt = {} tt["hort-Goth"] = { {"𐌰", "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["hort-Goth"]) function export.tr(te..."
 
Nehster9 (talk | contribs)
mNo edit summary
 
Line 2: Line 2:


local tt = {}
local tt = {}
tt["hort-Goth"] = {
tt["Goth"] = {
{"𐌰", "a"},
{"𐌰", "a"},
{"𐌱", "b"},
{"𐌱", "b"},
Line 26: Line 26:
}
}


tt["Latn"] = require("Module:table").invert(tt["hort-Goth"])
tt["Latn"] = require("Module:table").invert(tt["Goth"])


function export.tr(text, lang, sc)
function export.tr(text, lang, sc)

Latest revision as of 04:10, 6 July 2026


This module will transliterate Hortannic 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:hort-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["Goth"] = {
	{"𐌰", "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["Goth"])

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 = "hort"},
		["sc"] = {default = require("Module:scripts").findBestScriptWithoutLang(frame.args[1])}
	})
	
	local tr = export.tr(args[1], "hort", args.sc)
	
	return tr or "-"	
end

return export