Check LT long code

pull/207/head
M66B 3 years ago
parent 1dcafe01df
commit 77438c13f9

@ -0,0 +1,317 @@
[
{
"name": "Arabic",
"code": "ar",
"longCode": "ar"
},
{
"name": "Asturian",
"code": "ast",
"longCode": "ast-ES"
},
{
"name": "Belarusian",
"code": "be",
"longCode": "be-BY"
},
{
"name": "Breton",
"code": "br",
"longCode": "br-FR"
},
{
"name": "Catalan",
"code": "ca",
"longCode": "ca-ES"
},
{
"name": "Catalan (Valencian)",
"code": "ca",
"longCode": "ca-ES-valencia"
},
{
"name": "Chinese",
"code": "zh",
"longCode": "zh-CN"
},
{
"name": "Danish",
"code": "da",
"longCode": "da-DK"
},
{
"name": "Dutch",
"code": "nl",
"longCode": "nl"
},
{
"name": "Dutch",
"code": "nl",
"longCode": "nl"
},
{
"name": "Dutch (Belgium)",
"code": "nl",
"longCode": "nl-BE"
},
{
"name": "English",
"code": "en",
"longCode": "en"
},
{
"name": "English",
"code": "en",
"longCode": "en"
},
{
"name": "English (Australian)",
"code": "en",
"longCode": "en-AU"
},
{
"name": "English (Australian)",
"code": "en",
"longCode": "en-AU"
},
{
"name": "English (Canadian)",
"code": "en",
"longCode": "en-CA"
},
{
"name": "English (Canadian)",
"code": "en",
"longCode": "en-CA"
},
{
"name": "English (GB)",
"code": "en",
"longCode": "en-GB"
},
{
"name": "English (GB)",
"code": "en",
"longCode": "en-GB"
},
{
"name": "English (New Zealand)",
"code": "en",
"longCode": "en-NZ"
},
{
"name": "English (New Zealand)",
"code": "en",
"longCode": "en-NZ"
},
{
"name": "English (South African)",
"code": "en",
"longCode": "en-ZA"
},
{
"name": "English (South African)",
"code": "en",
"longCode": "en-ZA"
},
{
"name": "English (US)",
"code": "en",
"longCode": "en-US"
},
{
"name": "English (US)",
"code": "en",
"longCode": "en-US"
},
{
"name": "Esperanto",
"code": "eo",
"longCode": "eo"
},
{
"name": "French",
"code": "fr",
"longCode": "fr"
},
{
"name": "French",
"code": "fr",
"longCode": "fr"
},
{
"name": "Galician",
"code": "gl",
"longCode": "gl-ES"
},
{
"name": "German",
"code": "de",
"longCode": "de"
},
{
"name": "German",
"code": "de",
"longCode": "de"
},
{
"name": "German (Austria)",
"code": "de",
"longCode": "de-AT"
},
{
"name": "German (Austria)",
"code": "de",
"longCode": "de-AT"
},
{
"name": "German (Germany)",
"code": "de",
"longCode": "de-DE"
},
{
"name": "German (Germany)",
"code": "de",
"longCode": "de-DE"
},
{
"name": "German (Swiss)",
"code": "de",
"longCode": "de-CH"
},
{
"name": "German (Swiss)",
"code": "de",
"longCode": "de-CH"
},
{
"name": "Greek",
"code": "el",
"longCode": "el-GR"
},
{
"name": "Irish",
"code": "ga",
"longCode": "ga-IE"
},
{
"name": "Italian",
"code": "it",
"longCode": "it"
},
{
"name": "Japanese",
"code": "ja",
"longCode": "ja-JP"
},
{
"name": "Khmer",
"code": "km",
"longCode": "km-KH"
},
{
"name": "Norwegian (Bokmål)",
"code": "nb",
"longCode": "nb"
},
{
"name": "Norwegian (Bokmål)",
"code": "no",
"longCode": "no"
},
{
"name": "Persian",
"code": "fa",
"longCode": "fa"
},
{
"name": "Polish",
"code": "pl",
"longCode": "pl-PL"
},
{
"name": "Portuguese",
"code": "pt",
"longCode": "pt"
},
{
"name": "Portuguese (Angola preAO)",
"code": "pt",
"longCode": "pt-AO"
},
{
"name": "Portuguese (Brazil)",
"code": "pt",
"longCode": "pt-BR"
},
{
"name": "Portuguese (Moçambique preAO)",
"code": "pt",
"longCode": "pt-MZ"
},
{
"name": "Portuguese (Portugal)",
"code": "pt",
"longCode": "pt-PT"
},
{
"name": "Romanian",
"code": "ro",
"longCode": "ro-RO"
},
{
"name": "Russian",
"code": "ru",
"longCode": "ru-RU"
},
{
"name": "Simple German",
"code": "de-DE-x-simple-language",
"longCode": "de-DE-x-simple-language"
},
{
"name": "Slovak",
"code": "sk",
"longCode": "sk-SK"
},
{
"name": "Slovenian",
"code": "sl",
"longCode": "sl-SI"
},
{
"name": "Spanish",
"code": "es",
"longCode": "es"
},
{
"name": "Spanish",
"code": "es",
"longCode": "es"
},
{
"name": "Spanish (voseo)",
"code": "es",
"longCode": "es-AR"
},
{
"name": "Swedish",
"code": "sv",
"longCode": "sv"
},
{
"name": "Tagalog",
"code": "tl",
"longCode": "tl-PH"
},
{
"name": "Tamil",
"code": "ta",
"longCode": "ta-IN"
},
{
"name": "Ukrainian",
"code": "uk",
"longCode": "uk-UA"
}
]

@ -45,9 +45,29 @@ public class LanguageTool {
// https://languagetool.org/http-api/swagger-ui/#!/default/post_check // https://languagetool.org/http-api/swagger-ui/#!/default/post_check
String request = String request =
"text=" + URLEncoder.encode(text.toString(), StandardCharsets.UTF_8.name()) + "text=" + URLEncoder.encode(text.toString(), StandardCharsets.UTF_8.name()) +
"&language=auto" + "&language=auto";
"&preferredVariants=" + Locale.getDefault().toLanguageTag();
Log.i("LT request=" + request); // curl -X GET --header 'Accept: application/json' 'https://api.languagetool.org/v2/languages
String code = null;
JSONArray jlanguages;
Locale locale = Locale.getDefault();
try (InputStream is = context.getAssets().open("languagetool.json")) {
String json = Helper.readStream(is);
jlanguages = new JSONArray(json);
}
for (int i = 0; i < jlanguages.length(); i++) {
JSONObject jlanguage = jlanguages.getJSONObject(i);
String c = jlanguage.optString("longCode");
if (locale.toLanguageTag().equals(c) && c.contains("-")) {
code = c;
break;
}
}
if (code != null)
request += "&preferredVariants=" + code;
Log.i("LT locale=" + locale + " request=" + request);
URL url = new URL(LT_URI + "check"); URL url = new URL(LT_URI + "check");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();

Loading…
Cancel
Save