mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 04:58:45 +00:00
Prevent showing notification megaphone if not translated.
This commit is contained in:
@@ -12,16 +12,20 @@ import java.util.Locale;
|
||||
/**
|
||||
* Gives access to English strings.
|
||||
*/
|
||||
public final class EnglishResourceUtil {
|
||||
public final class ResourceUtil {
|
||||
|
||||
private EnglishResourceUtil() {
|
||||
private ResourceUtil() {
|
||||
}
|
||||
|
||||
public static Resources getEnglishResources(@NonNull Context context) {
|
||||
return getResources(context, Locale.ENGLISH);
|
||||
}
|
||||
|
||||
public static Resources getResources(@NonNull Context context, @NonNull Locale locale) {
|
||||
Configuration configurationLocal = context.getResources().getConfiguration();
|
||||
|
||||
Configuration configurationEn = new Configuration(configurationLocal);
|
||||
configurationEn.setLocale(Locale.ENGLISH);
|
||||
configurationEn.setLocale(locale);
|
||||
|
||||
return context.createConfigurationContext(configurationEn)
|
||||
.getResources();
|
||||
@@ -24,7 +24,17 @@ public final class TranslationDetection {
|
||||
public TranslationDetection(@NonNull Context context) {
|
||||
this.resourcesLocal = context.getResources();
|
||||
this.configurationLocal = resourcesLocal.getConfiguration();
|
||||
this.resourcesEn = EnglishResourceUtil.getEnglishResources(context);
|
||||
this.resourcesEn = ResourceUtil.getEnglishResources(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context Can be Application context.
|
||||
* @param usersLocale Locale of user.
|
||||
*/
|
||||
public TranslationDetection(@NonNull Context context, @NonNull Locale usersLocale) {
|
||||
this.resourcesLocal = ResourceUtil.getResources(context.getApplicationContext(), usersLocale);
|
||||
this.configurationLocal = resourcesLocal.getConfiguration();
|
||||
this.resourcesEn = ResourceUtil.getEnglishResources(context);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,6 +54,15 @@ public final class TranslationDetection {
|
||||
return !stringEn.equals(stringLocal);
|
||||
}
|
||||
|
||||
public boolean textExistsInUsersLanguage(@StringRes int... resIds) {
|
||||
for (int resId : resIds) {
|
||||
if (!textExistsInUsersLanguage(resId)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean configSupportsEnglish() {
|
||||
if (configurationLocal.locale.getLanguage().equals("en")) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user