Skip to content

Commit e9e15bf

Browse files
committed
Send locales to flutter includeing default locale
Signed-off-by: Boram Bae <[email protected]>
1 parent 7a6dd58 commit e9e15bf

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

shell/platform/tizen/channels/localization_channel.cc

+30-10
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,50 @@ LocalizationChannel::LocalizationChannel(FLUTTER_API_SYMBOL(FlutterEngine)
2121
LocalizationChannel::~LocalizationChannel() {}
2222

2323
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+
2445
int32_t count = i18n_ulocale_count_available();
2546
if (count > 0) {
26-
FlutterLocale* flutterLocale = nullptr;
27-
std::vector<FlutterLocale*> flutterLocales;
2847
for (int i = 0; i < count; i++) {
2948
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+
}
3354
}
3455
}
3556

57+
FT_LOGD("Send %zu available locales", flutter_locales.size());
3658
// send locales to engine
3759
FlutterEngineUpdateLocales(
3860
flutter_engine_,
39-
const_cast<const FlutterLocale**>(flutterLocales.data()),
40-
flutterLocales.size());
61+
const_cast<const FlutterLocale**>(flutter_locales.data()),
62+
flutter_locales.size());
4163

42-
for (auto it : flutterLocales) {
64+
for (auto it : flutter_locales) {
4365
DestroyFlutterLocale(it);
4466
}
4567
}
46-
47-
SendPlatformResolvedLocale();
4868
}
4969

5070
void LocalizationChannel::SendPlatformResolvedLocale() {

0 commit comments

Comments
 (0)