Module:fa-ira-translit

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module will transliterate Iranian Persian 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:fa-ira-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.

Notes

THIS MODULE SHOULD NOT BE USED FOR CLASSICAL PERSIAN OR DARI Due to pronunciation differences between modern Iranian Persian from other varieties of Persian, as well ans differences in vowel notation, Iranian Persian cannot be transliterated the same way as other varieties of Persian. If you need to transliterate a variety of Persian other than modern Iranian Persian, use Module:fa-cls-translit.

This module uses Module:fa-cls-translit as a backend.

Test cases

3 of 38 tests failed. (refresh)

TextExpectedActualDiffers at
test_translit_persian:
Passedسَرْاَنْجامsar-anjâmsar-anjâm
Passedکُروزkoruzkoruz
Passedکُرُوزkorowzkorowz
Passedواوvâvvâv
Passedنُوروزnowruznowruz
Passedقَهْوِه‌ایğahve-iğahve-i
Passedخوانْدَنxândanxândan
Passedخویشxišxiš
Passedخوَدxodxod
Passedچامِه‌سَراییčâme-sarâyičâme-sarâyi
Passedچامه‌سَرایی(nil)(nil)N/A
Passedطَنینtanintanin
Passedطَنِینtaneyntaneyn
Passedلِهٰذاlehâzâlehâzâ
Passedعَصاًasanasan
Passedخانه(nil)(nil)N/A
Passedخانِهxânexâne
Passedکُرِهٔ شُمالیkore-ye šomâlikore-ye šomâli
Passedضَمّه(nil)(nil)N/A
Passedضَمِّهzammezamme
Passedوُدْکاvodkâvodkâ
Passedاَرْمَنِسْتانarmanestânarmanestân
Passedباکوbâkubâku
Passedبَرادَرِ بُزُرْگbarâdar-e bozorgbarâdar-e bozorg
Passedقُرونِ وُسْطیٰğorun-e vostâğorun-e vostâ
Passedدَرْ-آمَدdar-âmaddar-âmad
Passedبازیِ شَطْرَنْجbâzi-ye šatranjbâzi-ye šatranj
Passedمتعلق(nil)(nil)N/A
Passedمُتَعَلِّقmota'alleğmota'alleğ
Passedاِتِّحادِیِهٔ اُروپاettehâdiye-ye orupâettehâdiye-ye orupâ
Failedآیَتُ‌اللّٰهâyato-llâhâyato-l-lâh8
Passedشِیْخšeyxšeyx
Passedنُوْروزnowruznowruz
Failedپَیامpayâmpeyâm2
Failedاَیّوبayyubeyّub1
Passedشِبْهِ‌جَزیرِهšebh-e-jazirešebh-e-jazire
Passedپایْگاهِ‌دادِهpâygâh-e-dâdepâygâh-e-dâde
Passedصَحْرایِ غَرْبیsahrâ-ye ğarbisahrâ-ye ğarbi

local export = {}

local m_str_utils = require("Module:string utilities")

local gsub = m_str_utils.gsub
local U = m_str_utils.char

local fatHatan = U(0x64B)
local zabar = U(0x64E)
local zer = U(0x650)
local pesh = U(0x64F)
local tashdid = U(0x651) -- also called shadda
local jazm = "ْ"
local he = "ه"
local zwnj = U(0x200C)
local highhmz = U(0x654)
local alef_wasla = "ٱ"
local balticons = "ڃڇڑڗݜݨݩǩ"
local consonants = "ءبپتټٹثجچحخدډڈذرزژسشصضطظعغفقکگلمنؤهئ"
local consonants2 = "ءبپتټٹثجچحخدډڈذرزژسشصضطظعغفقکگلمنوؤهیئyw" .. balticons -- including semivowels

local ain = "ع"
local alif = "ا"
local ye = "ی"
local ye2 = "ئ"
local ye3 = "ے" -- for balti
local vao = "و"
local function clscheck(text, lang, sc)
	return require("Module:fa-cls-translit").tr(text, lang, sc)
end
-- this has the fa-cls-translit perform the diactic check and other basic functions

function export.tr(text, lang, sc)
	text = gsub(text, alif .. fatHatan, fatHatan)
	text = gsub(text, "([" .. consonants2 .. "])" .. alif, "%1" .. zabar .. alif)
	text = gsub(text, pesh .. vao .. "([" .. consonants .. jazm .. "])", zabar .. vao .. "%1")
	text = gsub(text, zer .. ye .. "([" .. consonants .. jazm .. "])", zabar .. ye .. "%1")
	-- alows an alif without a zabar to work
	text = clscheck(text, lang, sc)
	if text == nil then --prevent module from breaking if diacritic check fails
		return nil
	end
	text = gsub(text, "e" .. " ", "e-ye")
	text = gsub(text, "iy", "ēy")
	text = gsub(text, "y%-i", "ē-yi")
	text = gsub(text, "q", "ğ")
	text = gsub(text, "ww", "vv")
	text = gsub(text, "i", "e")
	text = gsub(text, "u", "o")
	text = gsub(text, "ē", "i")
	text = gsub(text, "ay([^yaâeoiu])", "ī%1")
	text = gsub(text, "ī", "ey")
	text = gsub(text, "ō", "u")
	text = gsub(text, "ā", "â")
	text = gsub(text, "w([aâeoiu])", "v%1")
	text = gsub(text, "aw", "ū")
	text = gsub(text, "w", "v")
	text = gsub(text, "ū", "ow")
	return text
end

return export