模組:Deva-Gujr-translit
This module will transliterate text in the 天城文.
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:Deva-Gujr-translit/testcases.
Functions
tr(text, lang, sc)
- Transliterates a given piece of
text
written in the script specified by the codesc
, and language specified by the codelang
. - When the transliteration fails, returns
nil
.
local export = {}
local char = {
["क"] = "ક", ["ख"] = "ખ", ["ग"] = "ગ", ["घ"] = "ઘ", ["ङ"] = "ઙ", ["च"] = "ચ", ["छ"] = "છ", ["ज"] = "જ", ["झ"] = "ઝ", ["ञ"] = "ઞ", ["ट"] = "ટ", ["ठ"] = "ઠ", ["ड"] = "ડ", ["ढ"] = "ઢ", ["ण"] = "ણ", ["त"] = "ત", ["थ"] = "થ", ["द"] = "દ", ["ध"] = "ધ", ["न"] = "ન", ["प"] = "પ", ["फ"] = "ફ", ["ब"] = "બ", ["भ"] = "ભ", ["म"] = "મ", ["य"] = "ય", ["र"] = "ર", ["ल"] = "લ", ["ळ"] = "ળ", ["व"] = "વ", ["श"] = "શ", ["ष"] = "ષ", ["स"] = "સ", ["ह"] = "હ", ["ॹ"] = "ૹ",
["अ"] = "અ", ["आ"] = "આ", ["इ"] = "ઇ", ["ई"] = "ઈ", ["उ"] = "ઉ", ["ऊ"] = "ઊ", ["ऋ"] = "ઋ", ["ॠ"] = "ૠ", ["ऌ"] = "ઌ", ["ॡ"] = "ૡ", ["ऍ"] = "ઍ", ["ए"] = "એ", ["ऐ"] = "ઐ", ["ऑ"] = "ઑ",["ओ"] = "ઓ", ["औ"] = "ઔ",
["ा"] = "ા", ["ि"] = "િ", ["ी"] = "ી", ["ु"] = "ુ", ["ू"] = "ૂ", ["ृ"] = "ૃ", ["ॄ"] = "ૄ", ["ॢ"] = "ૢ", ["ॣ"] = "ૣ", ["ॅ"] = "ૅ", ["े"] = "ે", ["ै"] = "ૈ", ["ॉ"] = "ૉ", ["ो"] = "ો", ["ौ"] = "ૌ", ["्"] = "્",
["ं"] = "ં", ["ः"] = "ઃ", ["ँ"] = "ઁ", ["़"] = "઼", ["ऽ"] = "ઽ", ["ॐ"] = "ૐ", ["॰"] = "૰",
["०"] = "૦", ["१"] = "૧", ["२"] = "૨", ["३"] = "૩", ["४"] = "૪", ["५"] = "૫", ["६"] = "૬", ["७"] = "૭", ["८"] = "૮", ["९"] = "૯"
}
-- Override returns text even if some characters cannot be transliterated.
function export.tr(text, lang, sc, override)
local UTF8_char = "[%z\1-\127\194-\244][\128-\191]*"
local Gujr = require("Module:scripts").getByCode("Gujr")
text = mw.ustring.toNFD(text)
text = string.gsub(text, UTF8_char, char)
text = mw.ustring.toNFC(text)
local reducedText = mw.ustring.gsub(mw.ustring.gsub(text, "<.->", ""), "[%s%p\n]+", "")
if (mw.ustring.len(reducedText) == Gujr:countCharacters(reducedText) and not mw.ustring.find(text, "઼઼")) or override then
return text
else
return nil
end
end
return export