126 lines
5.1 KiB
Java
126 lines
5.1 KiB
Java
package io.flutter.plugin.localization;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.Configuration;
|
|
import android.os.LocaleList;
|
|
import android.util.Base64;
|
|
import io.flutter.embedding.engine.systemchannels.LocalizationChannel;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class LocalizationPlugin {
|
|
private final Context context;
|
|
private final LocalizationChannel localizationChannel;
|
|
final LocalizationChannel.LocalizationMessageHandler localizationMessageHandler;
|
|
|
|
public LocalizationPlugin(Context context, LocalizationChannel localizationChannel) {
|
|
LocalizationChannel.LocalizationMessageHandler localizationMessageHandler = new LocalizationChannel.LocalizationMessageHandler(this) { // from class: io.flutter.plugin.localization.LocalizationPlugin.1
|
|
private static byte a = 6;
|
|
private static int c = 0;
|
|
private static int d = 1;
|
|
final LocalizationPlugin this$0;
|
|
|
|
private void b(String str, Object[] objArr) {
|
|
byte[] decode = Base64.decode(str, 0);
|
|
byte[] bArr = new byte[decode.length];
|
|
for (int i = 0; i < decode.length; i++) {
|
|
bArr[i] = (byte) (decode[(decode.length - i) - 1] ^ a);
|
|
}
|
|
objArr[0] = new String(bArr, StandardCharsets.UTF_8);
|
|
}
|
|
|
|
{
|
|
this.this$0 = this;
|
|
}
|
|
|
|
@Override // io.flutter.embedding.engine.systemchannels.LocalizationChannel.LocalizationMessageHandler
|
|
public String getStringResource(String str, String str2) {
|
|
int i = 2 % 2;
|
|
Context context2 = this.this$0.context;
|
|
if (str2 != null) {
|
|
Locale localeFromString = LocalizationPlugin.localeFromString(str2);
|
|
Configuration configuration = new Configuration(this.this$0.context.getResources().getConfiguration());
|
|
configuration.setLocale(localeFromString);
|
|
context2 = this.this$0.context.createConfigurationContext(configuration);
|
|
}
|
|
int identifier = context2.getResources().getIdentifier(str, "string", this.this$0.context.getPackageName());
|
|
if (identifier == 0) {
|
|
return null;
|
|
}
|
|
int i2 = c + 109;
|
|
d = i2 % 128;
|
|
int i3 = i2 % 2;
|
|
String string = context2.getResources().getString(identifier);
|
|
if (!string.startsWith(",*,)")) {
|
|
return string;
|
|
}
|
|
int i4 = d + 61;
|
|
c = i4 % 128;
|
|
int i5 = i4 % 2;
|
|
Object[] objArr = new Object[1];
|
|
b(string.substring(4), objArr);
|
|
return ((String) objArr[0]).intern();
|
|
}
|
|
};
|
|
this.localizationMessageHandler = localizationMessageHandler;
|
|
this.context = context;
|
|
this.localizationChannel = localizationChannel;
|
|
localizationChannel.setLocalizationMessageHandler(localizationMessageHandler);
|
|
}
|
|
|
|
public Locale resolveNativeLocale(List<Locale> list) {
|
|
if (list == null || list.isEmpty()) {
|
|
return null;
|
|
}
|
|
ArrayList arrayList = new ArrayList();
|
|
LocaleList locales = this.context.getResources().getConfiguration().getLocales();
|
|
int size = locales.size();
|
|
for (int i = 0; i < size; i++) {
|
|
Locale locale = locales.get(i);
|
|
String language = locale.getLanguage();
|
|
if (!locale.getScript().isEmpty()) {
|
|
language = language + "-" + locale.getScript();
|
|
}
|
|
if (!locale.getCountry().isEmpty()) {
|
|
language = language + "-" + locale.getCountry();
|
|
}
|
|
arrayList.add(new Locale.LanguageRange(language));
|
|
arrayList.add(new Locale.LanguageRange(locale.getLanguage()));
|
|
arrayList.add(new Locale.LanguageRange(locale.getLanguage() + "-*"));
|
|
}
|
|
Locale lookup = Locale.lookup(arrayList, list);
|
|
return lookup != null ? lookup : list.get(0);
|
|
}
|
|
|
|
public void sendLocalesToFlutter(Configuration configuration) {
|
|
ArrayList arrayList = new ArrayList();
|
|
LocaleList locales = configuration.getLocales();
|
|
int size = locales.size();
|
|
for (int i = 0; i < size; i++) {
|
|
arrayList.add(locales.get(i));
|
|
}
|
|
this.localizationChannel.sendLocales(arrayList);
|
|
}
|
|
|
|
public static Locale localeFromString(String str) {
|
|
String str2;
|
|
String[] split = str.replace('_', '-').split("-", -1);
|
|
String str3 = split[0];
|
|
String str4 = "";
|
|
int i = 1;
|
|
if (split.length <= 1 || split[1].length() != 4) {
|
|
str2 = "";
|
|
} else {
|
|
str2 = split[1];
|
|
i = 2;
|
|
}
|
|
if (split.length > i && split[i].length() >= 2 && split[i].length() <= 3) {
|
|
str4 = split[i];
|
|
}
|
|
return new Locale(str3, str4, str2);
|
|
}
|
|
}
|