1
0
Fork 0

added support for a currency character in the language definitions and added some more local currencies

This commit is contained in:
sspanak 2025-02-15 12:18:04 +02:00 committed by Dimo Karaivanov
parent 5c1b3b532b
commit ae619e1f0f
19 changed files with 43 additions and 10 deletions

View file

@ -56,6 +56,7 @@ To support a new language one needs to:
- For 1-key, you could use `[PUNCTUATION]` and have standard English/computer punctuation; or `[PUNCTUATION_FR]` that includes the French quotation marks: `«`, `»`; or `[PUNCTUATION_DE]` that includes the German quotation marks: `„`, `“`. And if the language has extra punctuation marks, like Spanish, you could complement the list like this: `[PUNCTUATION, ¡, ¿]`. Or you could define your own list, like for 0-key.
- Keys 2 through 9, just contain the possible letters.
- `abcString` _(optional)_. A custom string to display in ABC mode. By default, the first three letters on 2-key are used (e.g. "ABC" or "АБВ"). Set this if the first letters of the alphabet are _not_ on 2-key, like in Hebrew, or if a different string makes more sense.
- `currency` _(optional)_. A string representing the currency related to that language, for example: `₪`, `₩`, `﷼`, etc. The character will be displayed in position 3 between the factory currency characters.
- `hasSpaceBetweenWords` _(optional)_ set to `no` when the language does not use spaces between words. For example: Thai, Chinese, Japanese, Korean, and so on. The default is `yes`.
- `hasUpperCase` _(optional)_ set to `no` when the language has no upper- and lowercase letters. For example: Arabic, Hebrew, East Asian languages, and so on. The default is `yes`.
- `name` _(optional)_ is automatically generated and equals the native name of the language (e.g. "English", "Deutsch", "Українська"). However, sometimes, the automatically selected name may be ambiguous. For example, both Portuguese in Portugal and Brazil will default to "Português", so assigning "Português brasileiro" would make it clear it's the language used in Brazil.

View file

@ -1,4 +1,5 @@
locale: ar-JO
currency:
dictionaryFile: ar-utf8.csv
abcString: أﺏﺕ
hasUpperCase: no

View file

@ -1,4 +1,5 @@
locale: gu-IN
currency:
dictionaryFile: gu-utf8.csv
abcString: કખગ
hasUpperCase: no

View file

@ -1,4 +1,5 @@
locale: iw-IL
currency:
dictionaryFile: he-utf8.csv
abcString: אבג
hasUpperCase: no

View file

@ -1,4 +1,5 @@
locale: hi-IN
currency:
dictionaryFile: hi-utf8.csv
abcString: कखग
hasUpperCase: no

View file

@ -1,4 +1,5 @@
locale: ko-KR
currency:
dictionaryFile: ko-utf8.csv
hasUpperCase: no
layout: # only used for the virtual key labels

View file

@ -1,4 +1,5 @@
locale: ru-RU
currency:
dictionaryFile: ru-utf8.csv
layout:
- [SPECIAL] # 0

View file

@ -1,4 +1,5 @@
locale: th-TH
currency: ฿
dictionaryFile: th-utf8.csv
abcString: กขค
hasSpaceBetweenWords: no

View file

@ -1,4 +1,5 @@
locale: tr-TR
currency:
dictionaryFile: tr-utf8.csv
layout:
- [SPECIAL] # 0

View file

@ -1,4 +1,5 @@
locale: uk-UA
currency:
dictionaryFile: uk-utf8.csv
layout:
- [SPECIAL] # 0

View file

@ -1,4 +1,5 @@
locale: vi-VN
currency:
dictionaryFile: vi-utf8.csv
layout:
- [SPECIAL] # 0

View file

@ -6,6 +6,7 @@ import io.github.sspanak.tt9.hacks.InputType;
import io.github.sspanak.tt9.ime.helpers.TextField;
import io.github.sspanak.tt9.languages.Language;
import io.github.sspanak.tt9.languages.LanguageKind;
import io.github.sspanak.tt9.languages.NullLanguage;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
import io.github.sspanak.tt9.util.Text;
import io.github.sspanak.tt9.util.chars.Characters;
@ -18,6 +19,7 @@ public class AutoSpace {
private static final Set<Character> NO_PRECEDING_SPACE_PUNCTUATION = Set.of('.', ',', ')', '\'', '@', '“', '؟', Characters.GR_QUESTION_MARK.charAt(0));
private static final Set<Character> NOT_FRENCH_NO_PRECEDING_SPACE_PUNCTUATION = Set.of(';', ':', '!', '?', '»');
private Language language;
private final SettingsStore settings;
private boolean isLanguageFrench;
@ -26,6 +28,7 @@ public class AutoSpace {
public AutoSpace(SettingsStore settingsStore) {
language = new NullLanguage();
settings = settingsStore;
isLanguageWithAlphabet = false;
isLanguageFrench = false;
@ -33,10 +36,11 @@ public class AutoSpace {
}
public AutoSpace setLanguage(Language language) {
isLanguageFrench = LanguageKind.isFrench(language);
isLanguageWithAlphabet = language != null && !language.isSyllabary();
isLanguageWithSpaceBetweenWords = language != null && language.hasSpaceBetweenWords();
public AutoSpace setLanguage(Language lang) {
language = language == null ? new NullLanguage() : lang;
isLanguageFrench = LanguageKind.isFrench(lang);
isLanguageWithAlphabet = !language.isSyllabary();
isLanguageWithSpaceBetweenWords = language.hasSpaceBetweenWords();
return this;
}
@ -112,7 +116,9 @@ public class AutoSpace {
|| (!Character.isDigit(penultimateChar) && previousChar == ':')
|| (!Character.isDigit(penultimateChar) && previousChar == '.')
|| (!Character.isDigit(penultimateChar) && previousChar == ',')
|| (Character.isDigit(penultimateChar) && Characters.Currency.contains(String.valueOf(previousChar)))
|| (
Character.isDigit(penultimateChar) && Characters.isCurrency(language, String.valueOf(previousChar))
)
);
}

View file

@ -18,6 +18,7 @@ public class EmojiLanguage extends Language {
locale = Locale.ROOT;
abcString = "emoji";
code = "emj";
currency = "";
name = "Emoji";
}

View file

@ -11,6 +11,7 @@ abstract public class Language {
protected int id;
protected String abcString;
protected String code;
protected String currency;
protected String dictionaryFile;
protected Locale locale = Locale.ROOT;
protected String name;
@ -31,6 +32,10 @@ abstract public class Language {
return code;
}
@NonNull public String getCurrency() {
return currency;
}
@NonNull final public String getDictionaryFile() {
return dictionaryFile;
}

View file

@ -21,6 +21,7 @@ public class LanguageDefinition extends AssetFile {
private static final String definitionsDir = languagesDir + "/definitions";
public String abcString = "";
public String currency = "";
public String dictionaryFile = "";
public boolean hasSpaceBetweenWords = true;
public boolean hasUpperCase = true;
@ -90,6 +91,7 @@ public class LanguageDefinition extends AssetFile {
private void parse(ArrayList<String> yaml) {
abcString = getPropertyFromYaml(yaml, "abcString", abcString);
currency = getPropertyFromYaml(yaml, "currency", currency);
dictionaryFile = getPropertyFromYaml(yaml, "dictionaryFile", dictionaryFile);
if (dictionaryFile != null) {
@ -102,8 +104,6 @@ public class LanguageDefinition extends AssetFile {
layout = getLayoutFromYaml(yaml);
locale = getPropertyFromYaml(yaml, "locale", locale);
name = getPropertyFromYaml(yaml, "name", name);
}

View file

@ -31,6 +31,7 @@ public class NaturalLanguage extends Language implements Comparable<NaturalLangu
NaturalLanguage lang = new NaturalLanguage();
lang.abcString = definition.abcString.isEmpty() ? null : definition.abcString;
lang.currency = definition.currency;
lang.dictionaryFile = definition.getDictionaryFile();
lang.hasSpaceBetweenWords = definition.hasSpaceBetweenWords;
lang.hasUpperCase = definition.hasUpperCase;
@ -213,6 +214,7 @@ public class NaturalLanguage extends Language implements Comparable<NaturalLangu
chars = new ArrayList<>();
} else if (characterGroup == 1) {
chars = new ArrayList<>(Characters.Currency);
if (!currency.isEmpty()) chars.add(2, currency);
}
}

View file

@ -7,12 +7,13 @@ import java.util.Locale;
public class NullLanguage extends Language {
public NullLanguage() {
locale = Locale.ROOT;
name = "Nulla Lingua";
abcString = "ABC";
code = "";
currency = "";
dictionaryFile = "";
hasUpperCase = false;
locale = Locale.ROOT;
name = "Nulla Lingua";
}
@NonNull

View file

@ -3,9 +3,11 @@ package io.github.sspanak.tt9.util.chars;
import java.util.ArrayList;
import java.util.Arrays;
import io.github.sspanak.tt9.languages.Language;
public class Characters extends Emoji {
final public static ArrayList<String> Currency = new ArrayList<>(Arrays.asList(
"$", "", "", "", "", "¢", "¤", "", "", "¥", "", "£"
"$", "", "", "¢", "¤", "", "¥", "£"
));
final public static ArrayList<String> Special = new ArrayList<>(Arrays.asList(
@ -40,4 +42,8 @@ public class Characters extends Emoji {
}
return keyCharacters;
}
public static boolean isCurrency(Language language, String c) {
return Currency.contains(c) || (language != null && language.getCurrency().equals(c));
}
}

View file

@ -62,6 +62,7 @@ ext.parseLanguageDefintion = { File languageFile, String dictionariesDir ->
if (
rawLine.matches("^[a-zA-Z].*")
&& !rawLine.startsWith("abcString")
&& !rawLine.startsWith("currency")
&& !rawLine.startsWith("dictionaryFile")
&& !rawLine.startsWith("hasSpaceBetweenWords")
&& !rawLine.startsWith("hasUpperCase")