help translations
This commit is contained in:
parent
4e5796ea3e
commit
c8c7e1546f
11 changed files with 1044 additions and 347 deletions
|
|
@ -32,11 +32,11 @@ tasks.register('copyDictionaries', Copy) {
|
|||
}
|
||||
|
||||
tasks.register('convertHelp') {
|
||||
inputs.file HELP_MARKDOWN
|
||||
outputs.file HELP_HTML
|
||||
inputs.dir HELP_MARKDOWN_DIR
|
||||
outputs.dir HELP_HTML_DIR
|
||||
|
||||
doLast {
|
||||
markdownToHTML(HELP_MARKDOWN, HELP_HTML)
|
||||
convertHelpDocs(HELP_MARKDOWN_DIR, HELP_HTML_DIR)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ tasks.register('updateManifest') {
|
|||
clean {
|
||||
delete LANGUAGES_OUTPUT_DIR
|
||||
delete DICTIONARIES_OUTPUT_DIR
|
||||
delete HELP_HTML
|
||||
delete HELP_HTML_DIR
|
||||
}
|
||||
|
||||
// using the exported Closures directly causes weird values, hence the extra wrappers here
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ def ROOT_DIR = "${project.rootDir}/app"
|
|||
def MAIN_ASSETS_DIR = "${ROOT_DIR}/src/main/assets"
|
||||
def FULL_VERSION_ASSETS_DIR = "${ROOT_DIR}/src/full/assets"
|
||||
|
||||
ext.HELP_MARKDOWN = "${project.rootDir}/docs/user-manual.md"
|
||||
ext.HELP_HTML = "${MAIN_ASSETS_DIR}/help.html"
|
||||
ext.HELP_MARKDOWN_DIR = "${project.rootDir}/docs/help"
|
||||
ext.HELP_HTML_DIR = "${MAIN_ASSETS_DIR}/help"
|
||||
|
||||
ext.LANGUAGES_INPUT_DIR = "${ROOT_DIR}/${LANGUAGES_DIR_NAME}"
|
||||
ext.DEFINITIONS_INPUT_DIR = "${LANGUAGES_INPUT_DIR}/${DEFINITIONS_DIR_NAME}"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,10 @@
|
|||
ext.markdownToHTML = { markdownPath, htmlPath ->
|
||||
ext.convertHelpDocs = {markdownDir, htmlDir ->
|
||||
fileTree(markdownDir).getFiles().parallelStream().forEach { File markdownPath ->
|
||||
markdownToHtml(markdownPath.path, "${htmlDir}/${markdownPath.name.replaceAll("\\.md\$", ".html")}")
|
||||
}
|
||||
}
|
||||
|
||||
static markdownToHtml(markdownPath, htmlPath) {
|
||||
def text = new File(markdownPath).text
|
||||
|
||||
text = convertHeaders(text)
|
||||
|
|
@ -63,7 +69,7 @@ static convertHeaders(markdown) {
|
|||
}
|
||||
|
||||
def header = line.replaceAll("^#+", "").trim()
|
||||
def anchor = header.toLowerCase().replaceAll("[^a-z0-9]+", "-").replaceAll("[\\-]+\$", "")
|
||||
def anchor = header.toLowerCase().replaceAll("[^\\d\\p{L}]+", "-").replaceAll("[\\-]+\$", "")
|
||||
|
||||
return "<h${headerNumber} id=\"${anchor}\">${header}</h${headerNumber}>"
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -3,12 +3,14 @@ package io.github.sspanak.tt9.preferences;
|
|||
import android.content.res.AssetManager;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import io.github.sspanak.tt9.ui.WebViewActivity;
|
||||
import io.github.sspanak.tt9.util.Logger;
|
||||
import io.github.sspanak.tt9.util.SystemSettings;
|
||||
|
||||
public class HelpActivity extends WebViewActivity {
|
||||
@Override
|
||||
|
|
@ -18,9 +20,8 @@ public class HelpActivity extends WebViewActivity {
|
|||
|
||||
@Override
|
||||
protected String getText() {
|
||||
AssetManager assets = getAssets();
|
||||
try {
|
||||
InputStream stream = assets.open("help.html");
|
||||
InputStream stream = getHelpFileStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String line;
|
||||
|
|
@ -29,8 +30,19 @@ public class HelpActivity extends WebViewActivity {
|
|||
}
|
||||
return builder.toString();
|
||||
} catch (Exception e) {
|
||||
Logger.e(getClass().getSimpleName(), "Failed opening the help.html file.");
|
||||
Logger.e(getClass().getSimpleName(), "Failed opening the help HTML document.");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private InputStream getHelpFileStream() throws IOException {
|
||||
AssetManager assets = getAssets();
|
||||
String systemLanguage = SystemSettings.getLocale().replaceFirst("_\\w+$", "");
|
||||
|
||||
try {
|
||||
return assets.open("help/help." + systemLanguage + ".html");
|
||||
} catch (IOException ignored) {
|
||||
return assets.open("help/help.en.html");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ public class MainSettingsScreen extends BaseScreenFragment {
|
|||
public void onCreate() {
|
||||
createSettingsSection();
|
||||
createAboutSection();
|
||||
updateHelpButtonDescription();
|
||||
resetFontSize(false);
|
||||
}
|
||||
|
||||
|
|
@ -51,6 +52,18 @@ public class MainSettingsScreen extends BaseScreenFragment {
|
|||
}
|
||||
|
||||
|
||||
private void updateHelpButtonDescription() {
|
||||
Preference help = findPreference("screen_help");
|
||||
if (help == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String systemLanguage = SystemSettings.getLocale().replaceAll("_\\w+$", "");
|
||||
boolean missingLanguage = !systemLanguage.equals("en") && !systemLanguage.equals("es") && !systemLanguage.equals("ru");
|
||||
help.setSummary(missingLanguage ? "English only" : "");
|
||||
}
|
||||
|
||||
|
||||
private void createSettingsSection() {
|
||||
boolean isTT9On = SystemSettings.isTT9Enabled(activity);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import android.provider.Settings;
|
|||
import android.view.inputmethod.InputMethodInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.Locale;
|
||||
|
|
@ -41,6 +42,7 @@ public class SystemSettings {
|
|||
return false;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static String getLocale() {
|
||||
Locale locale = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? LocaleList.getDefault().get(0) : Locale.getDefault();
|
||||
String country = locale.getCountry();
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
<Preference
|
||||
app:key="screen_help"
|
||||
app:summary="English only"
|
||||
app:title="@string/pref_help">
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue