Skip to content

Commit ae2a1b1

Browse files
authored
Send locales to flutter including default locale (#38)
Signed-off-by: Boram Bae <[email protected]>
1 parent 1c3084e commit ae2a1b1

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

shell/platform/tizen/channels/localization_channel.cc

+36-18
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,48 @@ 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();
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);
3352
}
3453
}
54+
}
3555

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());
4162

42-
for (auto it : flutterLocales) {
43-
DestroyFlutterLocale(it);
44-
}
63+
for (auto it : flutter_locales) {
64+
DestroyFlutterLocale(it);
4565
}
46-
47-
SendPlatformResolvedLocale();
4866
}
4967

5068
void LocalizationChannel::SendPlatformResolvedLocale() {

0 commit comments

Comments
 (0)