i18n: add setting to force English language usage of the app.

master
Floens 7 years ago
parent 6ae6139b94
commit 088d01fa89
  1. 3
      Clover/app/src/main/java/org/floens/chan/Chan.java
  2. 3
      Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java
  3. 3
      Clover/app/src/main/java/org/floens/chan/ui/activity/StartActivity.java
  4. 17
      Clover/app/src/main/java/org/floens/chan/ui/controller/BehaviourSettingsController.java
  5. 30
      Clover/app/src/main/java/org/floens/chan/utils/LocaleUtils.java
  6. 2
      Clover/app/src/main/res/values/strings.xml

@ -34,6 +34,7 @@ import org.floens.chan.core.di.UserAgentProvider;
import org.floens.chan.core.manager.BoardManager;
import org.floens.chan.core.site.SiteService;
import org.floens.chan.utils.AndroidUtils;
import org.floens.chan.utils.LocaleUtils;
import org.floens.chan.utils.Logger;
import org.floens.chan.utils.Time;
@ -89,6 +90,8 @@ public class Chan extends Application implements UserAgentProvider, Application.
}
public void initialize() {
LocaleUtils.overrideLocaleToEnglishIfNeeded(this);
final long startTime = Time.startTiming();
registerActivityLifecycleCallbacks(this);

@ -90,6 +90,7 @@ public class ChanSettings {
private static Proxy proxy;
public static final BooleanSetting forceEnglishLocale;
private static final StringSetting theme;
public static final OptionsSetting<LayoutMode> layoutMode;
public static final StringSetting fontSize;
@ -162,6 +163,8 @@ public class ChanSettings {
static {
SettingProvider p = new SharedPreferencesSettingProvider(AndroidUtils.getPreferences());
forceEnglishLocale = new BooleanSetting(p, "preference_force_english_locale", false);
theme = new StringSetting(p, "preference_theme", "yotsuba");
layoutMode = new OptionsSetting<>(p, "preference_layout_mode", LayoutMode.class, LayoutMode.AUTO);

@ -60,6 +60,7 @@ import org.floens.chan.ui.helper.VersionHandler;
import org.floens.chan.ui.state.ChanState;
import org.floens.chan.ui.theme.ThemeHelper;
import org.floens.chan.utils.AndroidUtils;
import org.floens.chan.utils.LocaleUtils;
import org.floens.chan.utils.Logger;
import java.util.ArrayList;
@ -108,6 +109,8 @@ public class StartActivity extends AppCompatActivity implements NfcAdapter.Creat
return;
}
LocaleUtils.overrideLocaleToEnglishIfNeeded(this);
ThemeHelper.getInstance().setupContext(this);
imagePickDelegate = new ImagePickDelegate(this);

@ -28,6 +28,7 @@ import org.floens.chan.ui.helper.RefreshUIMessage;
import org.floens.chan.ui.settings.BooleanSettingView;
import org.floens.chan.ui.settings.IntegerSettingView;
import org.floens.chan.ui.settings.LinkSettingView;
import org.floens.chan.ui.settings.SettingView;
import org.floens.chan.ui.settings.SettingsController;
import org.floens.chan.ui.settings.SettingsGroup;
import org.floens.chan.ui.settings.StringSettingView;
@ -37,6 +38,8 @@ import de.greenrobot.event.EventBus;
import static org.floens.chan.Chan.injector;
public class BehaviourSettingsController extends SettingsController {
private SettingView forceEnglishSetting;
public BehaviourSettingsController(Context context) {
super(context);
}
@ -54,11 +57,25 @@ public class BehaviourSettingsController extends SettingsController {
buildPreferences();
}
@Override
public void onPreferenceChange(SettingView item) {
super.onPreferenceChange(item);
if (item == forceEnglishSetting) {
Toast.makeText(context, R.string.setting_force_english_locale_toggle_notice,
Toast.LENGTH_LONG).show();
}
}
private void populatePreferences() {
// General group
{
SettingsGroup general = new SettingsGroup(R.string.settings_group_general);
forceEnglishSetting = general.add(new BooleanSettingView(this,
ChanSettings.forceEnglishLocale,
R.string.setting_force_english_locale,
R.string.setting_force_english_locale_toggle_notice));
general.add(new BooleanSettingView(this,
ChanSettings.autoRefreshThread,
R.string.setting_auto_refresh_thread, 0));

@ -0,0 +1,30 @@
package org.floens.chan.utils;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import org.floens.chan.core.settings.ChanSettings;
import java.util.Locale;
public class LocaleUtils {
public static void overrideLocaleToEnglishIfNeeded(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 &&
ChanSettings.forceEnglishLocale.get()) {
setLocaleToEnglish(context);
}
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static void setLocaleToEnglish(Context context) {
Resources resources = context.getResources();
Configuration configuration = resources.getConfiguration();
configuration.setLocale(Locale.ENGLISH);
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
}
}

@ -459,6 +459,8 @@ Crash reports do not collect any personally identifiable information."
<!-- Behavior general group -->
<string name="settings_group_general">General</string>
<string name="setting_force_english_locale">Always use English for the language of the app</string>
<string name="setting_force_english_locale_toggle_notice">Language will be applied on the next app start.</string>
<string name="setting_auto_refresh_thread">Auto refresh threads</string>
<string name="setting_confirm_exit">Confirm before exit</string>
<string name="setting_controller_swipeable">Allow screens to be swiped away</string>

Loading…
Cancel
Save