Skip to content

Commit

Permalink
Merge pull request #34 from hmlendea/arabic
Browse files Browse the repository at this point in the history
Improved the `Arabic` transliteration
  • Loading branch information
hmlendea authored May 25, 2023
2 parents 4ae056b + 97a66cf commit d7c07b2
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,41 @@ public void SetUp()
}

[Test]
[TestCase("أريحا", "ʾArīḥā")]
[TestCase("ٱلنَّقَب", "an-Naqab")]
[TestCase("إسدود", "ʾIsdūd")]
[TestCase("إِسْرَائِيل", "ʾIsrāʾīl")]
[TestCase("اسلو", "Āslū")]
[TestCase("الرملة", "āl-Ramlaḧ")] // Or ar-Ramleh
[TestCase("الأردن", "Al-ʾUrdunn")]
[TestCase("البيرة", "al-Bīra")]
[TestCase("الخليل", "al-Khalīl")]
[TestCase("السامرة", "as-Sāmirah")]
[TestCase("العمارنة", "al-ʿAmārnah")]
[TestCase("الفرات", "al-Furāt")]
[TestCase("الكويت", "al-Kuwayt")]
[TestCase("المندائيّة", "al-Mandāʾiyya")]
[TestCase("بئر السبع", "Biʾr as-Sabʿ")]
[TestCase("بابل", "Babil")]
[TestCase("تشيشيناو", "Tšīšīnāū")]
[TestCase("حَدِيثَةٌ", "Ḥadīthah")]
[TestCase("حركة المقاومة الإسلامية", "Ḥarakah al-Muqāwamah al-ʾIslāmiyyah")]
[TestCase("حماس", "Ḥamās")]
[TestCase("حَيْفَا", "Ḥayfā")]
[TestCase("دمشق", "Dimašq")]
[TestCase("رام الله", "Rām Allāh")]
[TestCase("روما", "Rūmā")]
[TestCase("سُورِيَا", "Sūriyā")]
[TestCase("عَسْقَلَان", "ʿAsqalān")]
[TestCase("غَزَّة", "Ġazzah")]
[TestCase("فتح", "Fatḥ")]
[TestCase("فِلَسْطِينَ", "Filasṭīn")]
[TestCase("فهرج", "Fahraǧ")]
[TestCase("مَنْف", "Manf")]
[TestCase("هرتسليا", "Hirtsiliyā")]
[TestCase("يوانينا", "Īānīnā")]
public void GivenATextInArabicScript_WhenTransliteratingIntoLatin_ThenTheCorrectTextIsReturned(
string arabicText,
string expectedTransliteratedText)
=> Assert.That(transliterator.Transliterate(arabicText), Is.EqualTo(expectedTransliteratedText));
=> Assert.That(transliterator.Transliterate(arabicText, "ar"), Is.EqualTo(expectedTransliteratedText));
}
}
10 changes: 5 additions & 5 deletions TransliterationAPI/Service/TransliterationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ async Task<string> TryGetTransliteratedText(string text, string language)
}
}

async Task<string> GetTransliteratedText(string text, string language)
async Task<string> GetTransliteratedText(string text, string languageCode)
{
switch (language)
switch (languageCode)
{
case "ab": // Abkhaz
return await translitterationDotComTransliterator.Transliterate(text, "abk", "iso-9");
Expand All @@ -97,7 +97,7 @@ async Task<string> GetTransliteratedText(string text, string language)
case "ar": // Arabic
case "ary": // Maghrebi Arabic
case "arz": // Egyptian Arabic
return arabicTransliterator.Transliterate(text);
return arabicTransliterator.Transliterate(text, languageCode);
case "ba": // Bashkir
return await translitterationDotComTransliterator.Transliterate(text, "bak", "iso-9");
case "be": // Belarussian
Expand All @@ -107,7 +107,7 @@ async Task<string> GetTransliteratedText(string text, string language)
case "bn": // Bengali
return await ushuaiaTransliterator.Transliterate(text, "bengali_iso_transliterate");
case "cu": // Old Church Slavonic
return await podolakTransliterator.Transliterate(text, language);
return await podolakTransliterator.Transliterate(text, languageCode);
case "cv": // Chuvash
return await translitterationDotComTransliterator.Transliterate(text, "chv", "ala-lc");
case "el": // Greek
Expand Down Expand Up @@ -172,7 +172,7 @@ async Task<string> GetTransliteratedText(string text, string language)
case "zh-hans": // Simplified Chinese
return pinyinTransliterator.Transliterate(text);
default:
throw new ArgumentException($"The \"{language}\" language is not supported");
throw new ArgumentException($"The \"{languageCode}\" language is not supported");
}
}

Expand Down
Loading

0 comments on commit d7c07b2

Please sign in to comment.