@@ -21,30 +21,50 @@ LocalizationChannel::LocalizationChannel(FLUTTER_API_SYMBOL(FlutterEngine)
21
21
LocalizationChannel::~LocalizationChannel () {}
22
22
23
23
void LocalizationChannel::SendLocales () {
24
+ const char * defualt_locale = nullptr ;
25
+ FlutterLocale* flutter_locale = nullptr ;
26
+ std::vector<FlutterLocale*> flutter_locales;
27
+
28
+ int ret = i18n_ulocale_set_default (getenv (" LC_TIME" ));
29
+ ret = i18n_ulocale_get_default (&defualt_locale);
30
+ if (ret != I18N_ERROR_NONE) {
31
+ FT_LOGE (" i18n_ulocale_get_default() failed." );
32
+ return ;
33
+ }
34
+
35
+ std::string without_encoding_type (defualt_locale);
36
+ auto n = without_encoding_type.find (' .' );
37
+ without_encoding_type.erase (n, without_encoding_type.length () - n);
38
+
39
+ flutter_locale = GetFlutterLocale (without_encoding_type.data ());
40
+ if (flutter_locale) {
41
+ FT_LOGD (" Choose Default locale[%s]" , without_encoding_type.data ());
42
+ flutter_locales.push_back (flutter_locale);
43
+ }
44
+
24
45
int32_t count = i18n_ulocale_count_available ();
25
46
if (count > 0 ) {
26
- FlutterLocale* flutterLocale = nullptr ;
27
- std::vector<FlutterLocale*> flutterLocales;
28
47
for (int i = 0 ; i < count; i++) {
29
48
const char * locale = i18n_ulocale_get_available (i);
30
- flutterLocale = GetFlutterLocale (locale);
31
- if (flutterLocale) {
32
- flutterLocales.push_back (flutterLocale);
49
+ if (without_encoding_type.compare (locale) != 0 ) {
50
+ flutter_locale = GetFlutterLocale (locale);
51
+ if (flutter_locale) {
52
+ flutter_locales.push_back (flutter_locale);
53
+ }
33
54
}
34
55
}
35
56
57
+ FT_LOGD (" Send %zu available locales" , flutter_locales.size ());
36
58
// send locales to engine
37
59
FlutterEngineUpdateLocales (
38
60
flutter_engine_,
39
- const_cast <const FlutterLocale**>(flutterLocales .data ()),
40
- flutterLocales .size ());
61
+ const_cast <const FlutterLocale**>(flutter_locales .data ()),
62
+ flutter_locales .size ());
41
63
42
- for (auto it : flutterLocales ) {
64
+ for (auto it : flutter_locales ) {
43
65
DestroyFlutterLocale (it);
44
66
}
45
67
}
46
-
47
- SendPlatformResolvedLocale ();
48
68
}
49
69
50
70
void LocalizationChannel::SendPlatformResolvedLocale () {
0 commit comments