-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from hmlendea/berber
Created a transliterator for `Berber`
- Loading branch information
Showing
3 changed files
with
110 additions
and
39 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
TransliterationAPI.UnitTests/Service/Transliterators/BerberTransliteratorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using NUnit.Framework; | ||
|
||
using TransliterationAPI.Service.Entities; | ||
using TransliterationAPI.Service.Transliterators; | ||
|
||
namespace TransliterationAPI.UnitTests.Service.Transliterators | ||
{ | ||
public class BerberTransliteratorTests | ||
{ | ||
private ITransliterator transliterator; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
this.transliterator = new BerberTransliterator(); | ||
} | ||
|
||
[Test] | ||
[TestCase("ⴳⵓⵍⵎⵉⵎ ⴰⵙⵉⴼ ⵏⵓⵏ", "Gulmim Asif Nun")] | ||
public void GivenATextInBerberScript_WhenTransliteratingIntoLatin_ThenTheCorrectTextIsReturned( | ||
string arabicText, | ||
string expectedTransliteratedText) | ||
=> Assert.That(transliterator.Transliterate(arabicText, Language.Berber), Is.EqualTo(expectedTransliteratedText)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
TransliterationAPI/Service/Transliterators/BerberTransliterator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text.RegularExpressions; | ||
using NuciExtensions; | ||
using TransliterationAPI.Service.Entities; | ||
|
||
namespace TransliterationAPI.Service.Transliterators | ||
{ | ||
public class BerberTransliterator : ITransliterator | ||
{ | ||
Dictionary<string, string> transliterationTable; | ||
public BerberTransliterator() | ||
{ | ||
transliterationTable = new Dictionary<string, string> | ||
{ | ||
{ "ⴰ", "a" }, | ||
{ "ⴳ", "g" }, | ||
{ "ⴼ", "f" }, | ||
{ "ⵉ", "i" }, | ||
{ "ⵍ", "l" }, | ||
{ "ⵎ", "m" }, | ||
{ "ⵏ", "n" }, | ||
{ "ⵓ", "u" }, | ||
{ "ⵙ", "s" }, | ||
}; | ||
} | ||
|
||
public string Transliterate(string text, Language language) | ||
{ | ||
if (!language.Equals(Language.Berber)) | ||
{ | ||
throw new ArgumentException($"The {language.Name} language is not supported by the {nameof(BerberTransliterator)}"); | ||
} | ||
|
||
string transliteratedText = text; | ||
|
||
foreach (string character in transliterationTable.Keys) | ||
{ | ||
transliteratedText = Regex.Replace(transliteratedText, character, transliterationTable[character]); | ||
} | ||
|
||
return transliteratedText.ToTitleCase(); | ||
} | ||
} | ||
} |