Module:kdr-translit
Appearance
- The following documentation is located at Module:kdr-translit/documentation. [edit] Categories were auto-generated by Module:module categorization. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module will transliterate Karaim text per WT:KDR TR.
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:kdr-translit/testcases.
Functions
tr(text, lang, sc)- Transliterates a given piece of
textwritten in the script specified by the codesc, and language specified by the codelang. - When transliteration fails, returns
nil.
local export = {}
-- Digraphs (processed first)
local digraphs = {
["Дж"] = "C", ["дж"] = "c",
["Къ"] = "Q", ["къ"] = "q",
["Нъ"] = "Ñ", ["нъ"] = "ñ",
["Хъ"] = "X", ["хъ"] = "x",
["Гъ"] = "Ğ", ["гъ"] = "ğ"
}
-- Single characters
local single_chars = {
["А"] = "A", ["а"] = "a",
["Б"] = "B", ["б"] = "b",
["В"] = "V", ["в"] = "v",
["Г"] = "G", ["г"] = "g",
["Д"] = "D", ["д"] = "d",
["Е"] = "Ye", ["е"] = "ye",
["Ж"] = "J", ["ж"] = "j",
["З"] = "Z", ["з"] = "z",
["И"] = "I", ["и"] = "i",
["Й"] = "Y", ["й"] = "y",
["К"] = "K", ["к"] = "k",
["Л"] = "L", ["л"] = "l",
["М"] = "M", ["м"] = "m",
["Н"] = "N", ["н"] = "n",
["О"] = "O", ["о"] = "o",
["Ӧ"] = "Ö", ["ӧ"] = "ö",
["П"] = "P", ["п"] = "p",
["Р"] = "R", ["р"] = "r",
["С"] = "S", ["с"] = "s",
["Т"] = "T", ["т"] = "t",
["У"] = "U", ["у"] = "u",
["Ӱ"] = "Ü", ["ӱ"] = "ü",
["Ф"] = "F", ["ф"] = "f",
["Х"] = "H", ["х"] = "h",
["Ц"] = "Ts", ["ц"] = "ts",
["Ч"] = "Ç", ["ч"] = "ç",
["Ш"] = "Ş", ["ш"] = "ş",
["Щ"] = "Şç", ["щ"] = "şç",
["Ъ"] = "ʺ", ["ъ"] = "ʺ",
["Ы"] = "I", ["ы"] = "ı",
["Ь"] = "ʹ", ["ь"] = "ʹ",
["Э"] = "E", ["э"] = "e",
["Ю"] = "Yu", ["ю"] = "yu",
["Я"] = "Ya", ["я"] = "ya"
}
function export.tr(text, lang, sc)
-- Handle template invocations vs direct module calls
if type(text) == "table" then
text = text.args[1]
end
if not text or text == "" then
return ""
end
-- If script is provided as a string code or object, validate if necessary
-- (In Wiktionary, if sc is passed and it's not 'Cyrl', we usually don't transliterate)
if sc and sc ~= "Cyrl" and type(sc) == "string" then
return nil
end
-- Normalize Unicode to NFC form
text = mw.ustring.toNFC(text)
-- Step 1: Replace digraphs (cyr = Cyrillic key, lat = Latin value)
for cyr, lat in pairs(digraphs) do
text = mw.ustring.gsub(text, cyr, lat)
end
-- Step 2: Replace individual characters
text = mw.ustring.gsub(text, ".", single_chars)
return text
end
return export