1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-24 17:45:50 +01:00

Add transliteration for Arabic and Farsi.

This commit is contained in:
Ted Stein 2017-12-01 21:26:00 -08:00 committed by Carsten Pfeiffer
parent ce9698c4e5
commit 39e151f51d
2 changed files with 32 additions and 3 deletions

View File

@ -61,8 +61,20 @@ public class LanguageUtils {
//ukrainian characters
put('ґ', "gh"); put('є', "je"); put('і', "i"); put('ї', "ji"); put('Ґ', "GH"); put('Є', "JE"); put('І', "I"); put('Ї', "JI");
//TODO: these must be configurabe. If someone wants to transliterate cyrillic it does not mean his device has no German umlauts
// Arabic
put('ا', "a"); put('ب', "b"); put('ت', "t"); put('ث', "th"); put('ج', "j"); put('ح', "7"); put('خ', "5");
put('د', "d"); put('ذ', "th"); put('ر', "r"); put('ز', "z"); put('س', "s"); put('ش', "sh"); put('ص', "9");
put('ض', "9'"); put('ط', "6"); put('ظ', "6'"); put('ع', "3"); put('غ', "3'"); put('ف', "f");
put('ق', "q"); put('ك', "k"); put('ل', "l"); put('م', "m"); put('ن', "n"); put('ه', "h");
put('و', "w"); put('ي', "y"); put('ى', "a");
put('آ', "2"); put('ئ', "2"); put('إ', "2"); put('ؤ', "2"); put('أ', "2"); put('ء', "2");
// Farsi
put('پ', "p"); put('چ', "ch"); put('ڜ', "ch"); put('ڤ', "v"); put('ڥ', "v");
put('ڨ', "g"); put('گ', "g"); put('ݣ', "g");
//TODO: these must be configurable. If someone wants to transliterate cyrillic it does not mean his device has no German umlauts
//all or nothing is really bad here
}
};

View File

@ -27,7 +27,6 @@ public class LanguageUtilsTest extends TestBase {
@Test
public void testStringTransliterateHebrew() throws Exception {
//input with cyrillic and diacritic letters
String input = "בדיקה עברית";
String output = LanguageUtils.transliterate(input);
String result = "bdykh 'bryth";
@ -35,6 +34,24 @@ public class LanguageUtilsTest extends TestBase {
assertEquals("Transliteration failed", result, output);
}
@Test
public void testStringTransliterateArabic() {
String pangram = "نص حكيم له سر قاطع وذو شأن عظيم مكتوب على ثوب أخضر ومغلف بجلد أزرق";
String pangramExpected = "n9 7kym lh sr qa63 wthw sh2n 36'ym mktwb 3la thwb 259'r wm3'lf bjld 2zrq";
String pangramActual = LanguageUtils.transliterate(pangram);
assertEquals("Arabic pangram transliteration failed", pangramExpected, pangramActual);
String hamza = "ءأؤإئآ";
String hamzaExpected = "222222";
String hamzaActual = LanguageUtils.transliterate(hamza);
assertEquals("hamza transliteration failed", hamzaExpected, hamzaActual);
String farsi = "پچڜڤڥڨگݣ";
String farsiExpected = "pchchvvggg";
String farsiActual = LanguageUtils.transliterate(farsi);
assertEquals("Farsi transiteration failed", farsiExpected, farsiActual);
}
@Test
public void testTransliterateOption() throws Exception {
setDefaultTransliteration();