summaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java17
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/LocaleHelper.java72
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java2
-rw-r--r--main/src/main/res/values-de/bools.xml8
-rw-r--r--main/src/main/res/values/bools.xml1
-rwxr-xr-xmain/src/main/res/values/strings.xml2
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/activities/BaseActivity.java13
-rw-r--r--main/src/ui/res/xml/general_settings.xml7
8 files changed, 117 insertions, 5 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java b/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java
index 92bfb61f..b8e3d646 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java
@@ -10,12 +10,14 @@ import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
+import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Build;
import android.os.StrictMode;
import android.os.strictmode.Violation;
+import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import java.util.concurrent.Executors;
@@ -35,7 +37,9 @@ public class ICSOpenVPNApplication extends Application {
if("robolectric".equals(Build.FINGERPRINT))
return;
+ LocaleHelper.setDesiredLocale(this);
super.onCreate();
+
PRNGFixes.apply();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
@@ -48,6 +52,13 @@ public class ICSOpenVPNApplication extends Application {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AppRestrictions.getInstance(this).checkRestrictions(this);
}
+
+
+ }
+
+ @Override
+ protected void attachBaseContext(Context base) {
+ super.attachBaseContext(LocaleHelper.updateResources(base));
}
private void enableStrictModes() {
@@ -74,6 +85,12 @@ public class ICSOpenVPNApplication extends Application {
}
+ @Override
+ public void onConfigurationChanged(@NonNull Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ LocaleHelper.onConfigurationChange(this);
+ }
+
@RequiresApi(api = Build.VERSION_CODES.P)
public void logViolation(Violation v) {
String name = Application.getProcessName();
diff --git a/main/src/main/java/de/blinkt/openvpn/core/LocaleHelper.java b/main/src/main/java/de/blinkt/openvpn/core/LocaleHelper.java
new file mode 100644
index 00000000..2b0c1975
--- /dev/null
+++ b/main/src/main/java/de/blinkt/openvpn/core/LocaleHelper.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2012-2021 Arne Schwabe
+ * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
+ */
+
+package de.blinkt.openvpn.core;
+
+import android.content.Context;
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.os.Build;
+
+import java.util.Locale;
+
+public class LocaleHelper {
+ static private Locale desiredLocale = null;
+
+ public static void setDesiredLocale(Context c)
+ {
+ Locale current = Locale.getDefault();
+ boolean defForce = true;
+ if (current.getLanguage().equals(new Locale("de").getLanguage()))
+ defForce = false;
+
+ boolean allow_translation = Preferences.getDefaultSharedPreferences(c).getBoolean("allow_translation", defForce);
+
+ if (!allow_translation)
+ desiredLocale = new Locale("en", current.getCountry());
+ }
+
+ public static Context updateResources(Context context) {
+ if (desiredLocale == null)
+ return context;
+
+ Locale.setDefault(desiredLocale);
+
+ Resources res = context.getResources();
+ Configuration config = new Configuration(res.getConfiguration());
+ if (Build.VERSION.SDK_INT >= 17) {
+ config.setLocale(desiredLocale);
+ context = context.createConfigurationContext(config);
+ } else {
+ config.locale = desiredLocale;
+ res.updateConfiguration(config, res.getDisplayMetrics());
+ }
+ return context;
+ }
+
+ public static void onConfigurationChange(Context context)
+ {
+ Resources res = context.getResources();
+
+ Locale current;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
+ current = res.getConfiguration().getLocales().get(0);
+ else
+ current = res.getConfiguration().locale;
+
+
+ if (current == desiredLocale)
+ return;
+
+ Configuration config = new Configuration(res.getConfiguration());
+
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
+ config.setLocale(desiredLocale);
+ else
+ config.locale = desiredLocale;
+
+ res.updateConfiguration(config, res.getDisplayMetrics());
+ }
+}
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java
index e4123838..f72c759f 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java
@@ -490,7 +490,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
if (proxyType == Connection.ProxyType.ORBOT) {
VpnStatus.updateStateString("WAIT_ORBOT", "Waiting for Orbot to start", R.string.state_waitorbot, ConnectionStatus.LEVEL_CONNECTING_NO_SERVER_REPLY_YET);
OrbotHelper orbotHelper = OrbotHelper.get(mOpenVPNService);
- if (!orbotHelper.checkTorReceier(mOpenVPNService))
+ if (!OrbotHelper.checkTorReceier(mOpenVPNService))
VpnStatus.logError("Orbot does not seem to be installed!");
mResumeHandler.postDelayed(orbotStatusTimeOutRunnable, ORBOT_TIMEOUT_MS);
diff --git a/main/src/main/res/values-de/bools.xml b/main/src/main/res/values-de/bools.xml
new file mode 100644
index 00000000..4b03945d
--- /dev/null
+++ b/main/src/main/res/values-de/bools.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ ~ Copyright (c) 2012-2021 Arne Schwabe
+ ~ Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
+ -->
+
+<resources>
+ <bool name="allowTranslationDefault">true</bool>
+</resources> \ No newline at end of file
diff --git a/main/src/main/res/values/bools.xml b/main/src/main/res/values/bools.xml
index d38f0c84..9cab9760 100644
--- a/main/src/main/res/values/bools.xml
+++ b/main/src/main/res/values/bools.xml
@@ -6,4 +6,5 @@
<resources>
<bool name="supportFileScheme">true</bool>
+ <bool name="allowTranslationDefault">false</bool>
</resources> \ No newline at end of file
diff --git a/main/src/main/res/values/strings.xml b/main/src/main/res/values/strings.xml
index 0fa36c05..3d91c58b 100755
--- a/main/src/main/res/values/strings.xml
+++ b/main/src/main/res/values/strings.xml
@@ -510,5 +510,7 @@
<string name="compat_mode_label">Compatibility mode</string>
<string name="loadossllegacy">Load OpenSSL legacy provider</string>
<string name="bf_cbc_requires_legacy">Profiles uses BF-CBC which depends on OpenSSL legacy provider (not enabled).</string>
+ <string name="allow_translations_title">Allow community contributed translations</string>
+ <string name="allow_translatiosn_summary">Allows the English to be translated with translations contributed by the community. Requires a restart of the app to activate.</string>
</resources>
diff --git a/main/src/ui/java/de/blinkt/openvpn/activities/BaseActivity.java b/main/src/ui/java/de/blinkt/openvpn/activities/BaseActivity.java
index 0e143042..cca8b155 100644
--- a/main/src/ui/java/de/blinkt/openvpn/activities/BaseActivity.java
+++ b/main/src/ui/java/de/blinkt/openvpn/activities/BaseActivity.java
@@ -6,12 +6,16 @@
package de.blinkt.openvpn.activities;
import android.app.UiModeManager;
+import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.Window;
+import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
+import de.blinkt.openvpn.core.LocaleHelper;
+
public abstract class BaseActivity extends AppCompatActivity {
boolean isAndroidTV() {
final UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
@@ -29,12 +33,13 @@ public abstract class BaseActivity extends AppCompatActivity {
}
@Override
- protected void onResume() {
- super.onResume();
+ protected void attachBaseContext(Context base) {
+ super.attachBaseContext(LocaleHelper.updateResources(base));
}
@Override
- protected void onPause() {
- super.onPause();
+ public void onConfigurationChanged(@NonNull Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ LocaleHelper.onConfigurationChange(this);
}
}
diff --git a/main/src/ui/res/xml/general_settings.xml b/main/src/ui/res/xml/general_settings.xml
index 5c2ff8aa..dcaafde2 100644
--- a/main/src/ui/res/xml/general_settings.xml
+++ b/main/src/ui/res/xml/general_settings.xml
@@ -13,6 +13,13 @@
android:summary="@string/show_log_summary"
android:title="@string/show_log_window"/>
+ <CheckBoxPreference
+ android:defaultValue="@bool/allowTranslationDefault"
+ android:key="allow_translation"
+ android:title="@string/allow_translations_title"
+ android:summary="@string/allow_translatiosn_summary"
+ />
+
<CheckBoxPreference
android:defaultValue="false"