Add app language option
This commit is contained in:
1 parent
5ddd652076
commit
c23a502e9e
10 files changed
+174
-4
No files matched your search
@@ -16,15 +16,16 @@
|
||||
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.google.analytics.tracking.android.EasyTracker;
|
||||
import com.hippo.content.ContextLocalWrapper;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import java.util.Locale;
|
||||
|
||||
public abstract class EhActivity extends AppCompatActivity {
|
||||
|
||||
@@ -74,4 +75,26 @@ public abstract class EhActivity extends AppCompatActivity {
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context newBase) {
|
||||
Locale locale = null;
|
||||
String language = Settings.getAppLanguage();
|
||||
if (language != null && !language.equals("system")) {
|
||||
String[] split = language.split("-");
|
||||
if (split.length == 1) {
|
||||
locale = new Locale(split[0]);
|
||||
} else if (split.length == 2) {
|
||||
locale = new Locale(split[0], split[0]);
|
||||
} else if (split.length == 3) {
|
||||
locale = new Locale(split[0], split[0], split[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (locale != null) {
|
||||
newBase = ContextLocalWrapper.wrap(newBase, locale);
|
||||
}
|
||||
|
||||
super.attachBaseContext(newBase);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user