@@ -21,30 +21,48 @@ 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
- if (count > 0 ) {
26
- FlutterLocale* flutterLocale = nullptr ;
27
- std::vector<FlutterLocale*> flutterLocales;
28
- for (int i = 0 ; i < count; i++) {
29
- const char * locale = i18n_ulocale_get_available (i);
30
- flutterLocale = GetFlutterLocale (locale);
31
- if (flutterLocale) {
32
- flutterLocales.push_back (flutterLocale);
46
+ for (int i = 0 ; i < count; i++) {
47
+ const char * locale = i18n_ulocale_get_available (i);
48
+ if (without_encoding_type.compare (locale) != 0 ) {
49
+ flutter_locale = GetFlutterLocale (locale);
50
+ if (flutter_locale) {
51
+ flutter_locales.push_back (flutter_locale);
33
52
}
34
53
}
54
+ }
35
55
36
- // send locales to engine
37
- FlutterEngineUpdateLocales (
38
- flutter_engine_,
39
- const_cast <const FlutterLocale**>(flutterLocales.data ()),
40
- flutterLocales.size ());
56
+ FT_LOGD (" Send %zu available locales" , flutter_locales.size ());
57
+ // send locales to engine
58
+ FlutterEngineUpdateLocales (
59
+ flutter_engine_,
60
+ const_cast <const FlutterLocale**>(flutter_locales.data ()),
61
+ flutter_locales.size ());
41
62
42
- for (auto it : flutterLocales) {
43
- DestroyFlutterLocale (it);
44
- }
63
+ for (auto it : flutter_locales) {
64
+ DestroyFlutterLocale (it);
45
65
}
46
-
47
- SendPlatformResolvedLocale ();
48
66
}
49
67
50
68
void LocalizationChannel::SendPlatformResolvedLocale () {
0 commit comments