1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 10:35:50 +01:00

Add Common Symbols transliteration

This commit is contained in:
Davis Mosenkovs 2023-10-06 21:55:43 +03:00
parent dcf2629854
commit 77450efb99
6 changed files with 59 additions and 1 deletions

View File

@ -1147,7 +1147,7 @@ public class GBApplication extends Application {
if (oldVersion < 16) {
// If transliteration was enabled for a device, migrate it to the per-language setting
final String defaultLanguagesIfEnabled = "extended_ascii,scandinavian,german,russian,hebrew,greek,ukranian,arabic,persian,latvian,lithuanian,polish,estonian,icelandic,czech,turkish,bengali,korean";
final String defaultLanguagesIfEnabled = "extended_ascii,common_symbols,scandinavian,german,russian,hebrew,greek,ukranian,arabic,persian,latvian,lithuanian,polish,estonian,icelandic,czech,turkish,bengali,korean";
try (DBHandler db = acquireDB()) {
final DaoSession daoSession = db.getDaoSession();
final List<Device> activeDevices = DBHelper.getActiveDevices(daoSession);

View File

@ -36,6 +36,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.ArabicTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.BengaliTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.CommonSymbolsTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.CroatianTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.CzechTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.EstonianTransliterator;
@ -63,6 +64,7 @@ public class LanguageUtils {
private static final Map<String, Transliterator> TRANSLITERATORS_MAP = new HashMap<String, Transliterator>() {{
put("arabic", new ArabicTransliterator());
put("bengali", new BengaliTransliterator());
put("common_symbols", new CommonSymbolsTransliterator());
put("croatian", new CroatianTransliterator());
put("czech", new CzechTransliterator());
put("estonian", new EstonianTransliterator());

View File

@ -0,0 +1,38 @@
/* Copyright (C) 2017-2023 Andreas Shimokawa, Aniruddha Adhikary, Daniele
Gobbetti, ivanovlev, kalaee, lazarosfs, McSym28, M. Hadi, Roi Greenberg,
Taavi Eomäe, Ted Stein, Thomas, Yaron Shahrabani, José Rebelo, Davis
Mosenkovs
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.util.language.impl;
import java.util.HashMap;
import nodomain.freeyourgadget.gadgetbridge.util.language.SimpleTransliterator;
public class CommonSymbolsTransliterator extends SimpleTransliterator {
public CommonSymbolsTransliterator() {
super(new HashMap<Character, String>() {{
put('“', "\""); put('”', "\""); put('‟', "\""); put('„', "\""); put('', "'"); put('', "'"); put('', "'"); put('', "'"); put('«', "<"); put('»', ">"); put('', "<"); put('', ">");
put('©', "(c)"); put('®', "(r)"); put('™', "(tm)"); put('°', "*"); put('€', "EUR");
put('', "-"); put('⸺', "-"); put('˗', "-"); put('ᐨ', "-"); put('', "-"); put('', "-"); put('', "-"); put('—', "-"); put('―', "-"); put('', "-");
put('⎯', "-"); put('⏤', "-"); put('─', "-"); put('', "-"); put('⸻', "-"); put('ㅡ', "-"); put('ᅳ', "-"); put('ー', "-"); put('一', "-"); put('', "-");
put('﹣', "-"); put('', "-"); put('𑁋', "-"); put('𑁒', "-"); put('˜', "~"); put('', "~"); put('', "~"); put('〜', "~"); put('〰', "~~"); put('', "~");
put('⁰', "0"); put('¹', "1"); put('²', "2"); put('³', "3"); put('⁴', "4"); put('⁵', "5"); put('⁶', "6"); put('⁷', "7"); put('⁸', "8"); put('⁹', "9");
put('₀', "0"); put('₁', "1"); put('₂', "2"); put('₃', "3"); put('₄', "4"); put('₅', "5"); put('₆', "6"); put('₇', "7"); put('₈', "8"); put('₉', "9");
}});
}
}

View File

@ -3072,6 +3072,7 @@
<string-array name="pref_transliteration_languages">
<item>@string/arabic</item>
<item>@string/bengali</item>
<item>@string/common_symbols</item>
<item>@string/croatian</item>
<item>@string/czech</item>
<item>@string/estonian</item>
@ -3096,6 +3097,7 @@
<string-array name="pref_transliteration_languages_values">
<item>arabic</item>
<item>bengali</item>
<item>common_symbols</item>
<item>croatian</item>
<item>czech</item>
<item>estonian</item>

View File

@ -989,6 +989,7 @@
<string name="georgian">Georgian</string>
<string name="german">German</string>
<string name="bengali">Bengali</string>
<string name="common_symbols">Common Symbols</string>
<string name="croatian">Croatian</string>
<string name="czech">Czech</string>
<string name="estonian">Estonian</string>

View File

@ -189,6 +189,21 @@ public class LanguageUtilsTest extends TestBase {
assertEquals("georgian transliteration failed", expected, output);
}
@Test
public void testStringTransliterateCommonSymbols() {
final Transliterator transliterator = LanguageUtils.getTransliterator("common_symbols");
String input = "© ® ™ ° « » “ ” 〜 ² ³ ₅";
String output = transliterator.transliterate(input);
String expected = "(c) (r) (tm) * < - > \" \" ~ 2 3 5";
assertEquals("common symbols translation failed", expected, output);
input = "a©a b®b c™c d°d e«e ff g»g h“h i”i j〜j k²k l³l m₅m";
output = transliterator.transliterate(input);
expected = "a(c)a b(r)b c(tm)c d*d e<e f-f g>g h\"h i\"i j~j k2k l3l m5m";
assertEquals("common symbols translation failed", expected, output);
}
@Test
public void testStringTransliterateCroatian() {
final Transliterator transliterator = LanguageUtils.getTransliterator("croatian");