5package io.flutter.embedding.engine.systemchannels;
7import androidx.annotation.NonNull;
8import androidx.annotation.Nullable;
9import androidx.annotation.VisibleForTesting;
11import io.flutter.embedding.engine.dart.DartExecutor;
12import io.flutter.plugin.common.JSONMethodCodec;
13import io.flutter.plugin.common.MethodCall;
14import io.flutter.plugin.common.MethodChannel;
15import java.util.ArrayList;
17import java.util.Locale;
18import org.json.JSONException;
19import org.json.JSONObject;
23 private static final String TAG =
"LocalizationChannel";
28 @NonNull @VisibleForTesting
29 public final MethodChannel.MethodCallHandler
handler =
33 if (localizationMessageHandler ==
null) {
39 String method =
call.method;
41 case "Localization.getStringResource":
42 JSONObject arguments =
call.<JSONObject>arguments();
44 String
key = arguments.getString(
"key");
45 String localeString =
null;
46 if (arguments.has(
"locale")) {
47 localeString = arguments.getString(
"locale");
49 result.success(localizationMessageHandler.getStringResource(
key, localeString));
50 }
catch (JSONException exception) {
51 result.error(
"error", exception.getMessage(),
null);
73 this.localizationMessageHandler = localizationMessageHandler;
78 Log.
v(
TAG,
"Sending Locales to Flutter.");
81 for (Locale locale : locales) {
85 + locale.getLanguage()
91 data.add(locale.getLanguage());
92 data.add(locale.getCountry());
93 data.add(locale.getScript());
94 data.add(locale.getVariant());
static void v(@NonNull String tag, @NonNull String message)
final MethodChannel channel
final MethodChannel.MethodCallHandler handler
LocalizationChannel(@NonNull DartExecutor dartExecutor)
void sendLocales(@NonNull List< Locale > locales)
void setLocalizationMessageHandler( @Nullable LocalizationMessageHandler localizationMessageHandler)
static final JSONMethodCodec INSTANCE
void setMethodCallHandler(final @Nullable MethodCallHandler handler)
void invokeMethod(@NonNull String method, @Nullable Object arguments)
String getStringResource(@NonNull String key, @NonNull String locale)
std::shared_ptr< const fml::Mapping > data