Show reset to system language in system language

This commit is contained in:
M66B 2022-02-14 16:14:27 +01:00
parent c023196fc0
commit fc446325e2
2 changed files with 9 additions and 4 deletions

View File

@ -28,6 +28,7 @@ import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import android.content.res.Resources;
import android.database.sqlite.SQLiteDatabaseCorruptException;
import android.graphics.Paint;
import android.graphics.Typeface;
@ -514,10 +515,11 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
ibResetLanguage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(view.getContext())
Locale system = Resources.getSystem().getConfiguration().locale;
new AlertDialog.Builder(v.getContext())
.setIcon(R.drawable.twotone_help_24)
.setTitle(R.string.title_advanced_language_system)
.setMessage(R.string.title_advanced_english_hint)
.setTitle(system.getDisplayName(system))
.setMessage(Helper.getString(v.getContext(), system, R.string.title_advanced_english_hint))
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

View File

@ -1538,9 +1538,12 @@ public class Helper {
static String getString(Context context, String language, int resid, Object... formatArgs) {
if (language == null)
return context.getString(resid, formatArgs);
return getString(context, new Locale(language), resid, formatArgs);
}
static String getString(Context context, Locale locale, int resid, Object... formatArgs) {
Configuration configuration = new Configuration(context.getResources().getConfiguration());
configuration.setLocale(new Locale(language));
configuration.setLocale(locale);
Resources res = context.createConfigurationContext(configuration).getResources();
return res.getString(resid, formatArgs);
}