changed the way to change language, now is «NewPipe's language» selector

This commit is contained in:
bopol 2020-01-09 09:40:05 +01:00
parent dea1e0dcb9
commit 3ad0e313ca
10 changed files with 209 additions and 29 deletions

View file

@ -7,6 +7,11 @@ import android.content.res.Resources;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.PluralsRes;
import androidx.annotation.StringRes;
import org.ocpsoft.prettytime.PrettyTime;
import org.ocpsoft.prettytime.units.Decade;
@ -21,10 +26,6 @@ import java.util.Date;
import java.util.List;
import java.util.Locale;
import androidx.annotation.NonNull;
import androidx.annotation.PluralsRes;
import androidx.annotation.StringRes;
/*
* Created by chschtsch on 12/29/15.
*
@ -226,4 +227,21 @@ public class Localization {
conf.setLocale(loc);
res.updateConfiguration(conf, dm);
}
public static Locale getAppLanguage(Context context) {
SharedPreferences prefs = androidx.preference.PreferenceManager.getDefaultSharedPreferences(context);
String lang = prefs.getString("newpipes_language_key", "en");
Locale loc;
if (lang.equals("system")) {
loc = Locale.getDefault();
} else if (lang.matches(".*-.*")) {
String[] localisation = lang.split("-");
lang = localisation[0];
String country = localisation[1];
loc = new Locale(lang, country);
} else {
loc = new Locale(lang);
}
return loc;
}
}