From 858eaa6690a2da7462e5022e5280bdc7b98ad21a Mon Sep 17 00:00:00 2001 From: Yaron Shahrabani Date: Sat, 4 Mar 2017 23:08:24 +0200 Subject: [PATCH] Added Hebrew transliteration and tests (#571) --- .../gadgetbridge/util/LanguageUtils.java | 7 ++++++- .../DeviceCommunicationServiceTestCase.java | 16 +++++++++++++++- .../gadgetbridge/test/LanguageUtilsTest.java | 12 +++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/LanguageUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/LanguageUtils.java index 78ae076c3..a5f69e1fa 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/LanguageUtils.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/LanguageUtils.java @@ -20,7 +20,12 @@ public class LanguageUtils { put('п', "p"); put('р', "r"); put('с', "s"); put('т', "t"); put('у', "u"); put('ф', "f"); put('х', "kh"); put('ц', "c"); put('ч', "ch");put('ш', "sh");put('щ', "shh");put('ъ', "\"");put('ы', "y"); put('ь', "'"); put('э', "eh"); put('ю', "ju"); put('я', "ja"); - + + //hebrew chars + put('א', "a"); put('ב', "b"); put('ג', "g"); put('ד', "d"); put('ה', "h"); put('ו', "u"); put('ז', "z"); put('ח', "kh"); + put('ט', "t"); put('י', "y"); put('כ', "c"); put('ל', "l"); put('מ', "m"); put('נ', "n"); put('ס', "s"); put('ע', "'"); + put('פ', "p"); put('צ', "ts"); put('ק', "k"); put('ר', "r"); put('ש', "sh"); put('ת', "th"); put('ף', "f"); put('ץ', "ts"); + put('ך', "ch");put('ם', "m");put('ן', "n"); //continue for other languages... } }; diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationServiceTestCase.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationServiceTestCase.java index 11fc855e9..8625feba1 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationServiceTestCase.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationServiceTestCase.java @@ -102,7 +102,7 @@ public class DeviceCommunicationServiceTestCase extends TestBase { } @Test - public void testTransliterationSupport() { + public void testTransliterationSupportCyrillic() { SharedPreferences settings = GBApplication.getPrefs().getPreferences(); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("transliteration", true); @@ -114,4 +114,18 @@ public class DeviceCommunicationServiceTestCase extends TestBase { assertTrue("Transliteration support fail!", result.equals("Prosto tekct")); } + + @Test + public void testTransliterationSupportHebrew() { + SharedPreferences settings = GBApplication.getPrefs().getPreferences(); + SharedPreferences.Editor editor = settings.edit(); + editor.putBoolean("transliteration", true); + editor.commit(); + + Intent intent = mDeviceService.createIntent().putExtra(EXTRA_NOTIFICATION_BODY, "בדיקה עברית"); + mDeviceService.invokeService(intent); + String result = intent.getStringExtra(EXTRA_NOTIFICATION_BODY); + + assertTrue("Transliteration support fail!", result.equals("bdykh 'vrith")); + } } diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/LanguageUtilsTest.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/LanguageUtilsTest.java index cfc8ec494..e6cb7a1f1 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/LanguageUtilsTest.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/LanguageUtilsTest.java @@ -15,7 +15,7 @@ import static org.junit.Assert.assertTrue; */ public class LanguageUtilsTest extends TestBase { @Test - public void testStringTransliterate() throws Exception { + public void testStringTransliterateCyrillic() throws Exception { //input with cyrillic and diacritic letters String input = "Прõсто текčт"; String output = LanguageUtils.transliterate(input); @@ -23,6 +23,16 @@ public class LanguageUtilsTest extends TestBase { assertTrue(String.format("Transliteration fail! Expected '%s', but found '%s'}", result, output), output.equals(result)); } + + @Test + public void testStringTransliterateCyrillic() throws Exception { + //input with cyrillic and diacritic letters + String input = "בדיקה עברית"; + String output = LanguageUtils.transliterate(input); + String result = "bdykh 'brith"; + + assertTrue(String.format("Transliteration fail! Expected '%s', but found '%s'}", result, output), output.equals(result)); + } @Test public void testTransliterateOption() throws Exception {