Definition from Wiktionary, the free dictionary
Jump to: navigation, search

This module will transliterate Persian language text per WT:FA 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:fa-translit/testcases.


tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by sc, and language specified by lang. When the transliteration fails, returns nil.

local export = {}
local mapping = {
	["ا"]='â', ["ب"]='b', ["پ"]='p', ["ت"]='t', ["ث"]='s', ["ج"]='j', ["چ"]='č', ["ح"]='h', ["خ"]='x', 
	["د"]='d', ["ذ"]='z', ["ر"]='r', ["ز"]='z', ["ژ"]='ž', ["س"]='s', ["ش"]='š', ["ص"]='s', ["ض"]='z', 
	["ط"]='t', ["ظ"]='z', ["ع"]='’', ["غ"]='ğ', ["ف"]='f', ["ق"]='q', ["ک"]='k', ["گ"]='g', ["ل"]='l', 
	["م"]='m', ["ن"]='n', ["و"]='u', ["ه"]='h', ["ی"]='i', ["آ"]='â', ["ﮥ"]='eye',

	-- displaying on separate lines as the viewing becomes distorted on these combinations
	-- diacritics
	["\217\142"]="a", -- fathe, zabar
	["\217\144"]="e", -- kasre, zir
	["\217\143"]="o", -- zamme, piš
	["\217\146"]="", --jazm, sokun - no vowel
	["\226\128\140"]="-", -- ZWNJ (zero-width non-joiner)
	-- ligatures
	-- kashida
	["ـ"]="", -- kashida, no sound
	-- numerals
	["۱"]="1", ["۲"]="2", ["۳"]="3", ["۴"]="4", ["۵"]="5",
	["۶"]="6", ["٧"]="7", ["٨"]="8", ["٩"]="9", ["۰"]="0",
	-- punctuation (leave on separate lines)
	["؟"]="?", -- question mark
	["،"]=",", -- comma
	["؛"]=";" -- semicolon
function, lang, sc)
	text = mw.ustring.gsub(text, '.', mapping)
	text = mw.ustring.gsub(text, "(.)\217\145", "%1%1") -- tašdid

	return text
return export