This module will transliterate text in the อักษรอเวสตะ. It is used to transliterate อเวสตะ and เปอร์เซียกลาง. 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:Avst-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 = {
	["𐬀"] = "ะ", -- AVESTAN LETTER A 
	["𐬁"] = "า", -- AVESTAN LETTER AA 
	["𐬂"] = "↶เาะ", -- AVESTAN LETTER AO 
	["𐬃"] = "อ̂", -- AVESTAN LETTER AAO 
	["𐬄"] = "ํ", -- AVESTAN LETTER AN 
	["𐬅"] = "าํ", -- AVESTAN LETTER AAN 
	["𐬆"] = "↶เอ̂ะ", -- AVESTAN LETTER AE 
	["𐬇"] = "↶เอ̂", -- AVESTAN LETTER AEE 
	["𐬈"] = "↶เะ", -- AVESTAN LETTER E 
	["𐬉"] = "↶เ", -- AVESTAN LETTER EE 
	["𐬊"] = "↶โะ", -- AVESTAN LETTER O 
	["𐬋"] = "↶โ", -- AVESTAN LETTER OO 
	["𐬌"] = "ิ", -- AVESTAN LETTER I 
	["𐬍"] = "ี", -- AVESTAN LETTER II 
	["𐬎"] = "ุ", -- AVESTAN LETTER U 
	["𐬏"] = "ู", -- AVESTAN LETTER UU 

	["𐬐"] = "ก", -- AVESTAN LETTER KE 
	["𐬑"] = "ฃ", -- AVESTAN LETTER XE 
	["𐬒"] = "ฃ̱", -- AVESTAN LETTER XYE 
	["𐬓"] = "ฃฺว", -- AVESTAN LETTER XVE
	["𐬔"] = "ค", -- AVESTAN LETTER GE 
	["𐬕"] = "ค̱", -- AVESTAN LETTER GGE 
	["𐬖"] = "ฆ", -- AVESTAN LETTER GHE 
	["𐬗"] = "จ", -- AVESTAN LETTER CE 
	["𐬘"] = "ช", -- AVESTAN LETTER JE 
	["𐬙"] = "ต", -- AVESTAN LETTER TE 
	["𐬚"] = "ท", -- AVESTAN LETTER THE 
	["𐬛"] = "ด", -- AVESTAN LETTER DE 
	["𐬜"] = "ธ", -- AVESTAN LETTER DHE 
	["𐬝"] = "ฏ", -- AVESTAN LETTER TTE 
	["𐬞"] = "ป", -- AVESTAN LETTER PE 
	["𐬟"] = "ฟ", -- AVESTAN LETTER FE 
	["𐬠"] = "บ", -- AVESTAN LETTER BE 
	["𐬡"] = "ภ", -- AVESTAN LETTER BHE 
	["𐬢"] = "ง", -- AVESTAN LETTER NGE 
	["𐬣"] = "ง̱", -- AVESTAN LETTER NGYE 
	["𐬤"] = "งฺว", -- AVESTAN LETTER NGVE
	["𐬥"] = "น", -- AVESTAN LETTER NE 
	["𐬦"] = "ญ", -- AVESTAN LETTER NYE 
	["𐬧"] = "ณ", -- AVESTAN LETTER NNE 
	["𐬨"] = "ม", -- AVESTAN LETTER ME 
	["𐬩"] = "ม̱", -- AVESTAN LETTER HME 
	["𐬪"] = "ย̱", -- AVESTAN LETTER YYE 
	["𐬫"] = "ย", -- AVESTAN LETTER YE 
	["𐬬"] = "ว", -- AVESTAN LETTER VE 
	["𐬭"] = "ร", -- AVESTAN LETTER RE 
	["𐬮"] = "ล", -- AVESTAN LETTER LE 
	["𐬯"] = "ส", -- AVESTAN LETTER SE 
	["𐬰"] = "ซ", -- AVESTAN LETTER ZE 
	["𐬱"] = "ศ", -- AVESTAN LETTER SHE 
	["𐬲"] = "ษ", -- AVESTAN LETTER ZHE 
	["𐬳"] = "ศ̱", -- AVESTAN LETTER SHYE 
	["𐬴"] = "ษ̱", -- AVESTAN LETTER SSHE 
	["𐬵"] = "ห", -- AVESTAN LETTER HE 
	["𐬹"] = "ฯ", -- AVESTAN ABBREVIATION MARK
	["⸱"] = "-"  -- WORD SEPARATOR MIDDLE DOT
}

function export.tr(text, lang, sc)
	text = mw.ustring.gsub(text, "[⸱𐬹]?[𐬺𐬻𐬼𐬽𐬾𐬿]", ".") -- punctuation

	text = mw.ustring.gsub(text, "𐬌𐬌", "ย")
	text = mw.ustring.gsub(text, "𐬎𐬎", "ว")

	text = mw.ustring.gsub(text, "^([𐬀𐬁𐬂𐬃𐬄𐬅𐬆𐬇𐬈𐬉𐬊𐬋𐬌𐬍𐬎𐬏])", "อ%1")
	text = mw.ustring.gsub(text, "([%p%s])([𐬀𐬁𐬂𐬃𐬄𐬅𐬆𐬇𐬈𐬉𐬊𐬋𐬌𐬍𐬎𐬏])", "%1อ%2")
	text = mw.ustring.gsub(text, "([𐬀𐬁𐬂𐬃𐬄𐬅𐬆𐬇𐬈𐬉𐬊𐬋𐬌𐬍𐬎𐬏])([𐬀𐬁𐬂𐬃𐬄𐬅𐬆𐬇𐬈𐬉𐬊𐬋𐬌𐬍𐬎𐬏])", "%1อ%2")

	text = mw.ustring.gsub(text, ".", mapping)

	text = mw.ustring.gsub(text, "([ก-ฮ]̱?)↶([เโ])", "%2%1")

	return text
end

return export