Skip to content

Send locales to flutter includeing default locale #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions shell/platform/tizen/channels/localization_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,48 @@ LocalizationChannel::LocalizationChannel(FLUTTER_API_SYMBOL(FlutterEngine)
LocalizationChannel::~LocalizationChannel() {}

void LocalizationChannel::SendLocales() {
const char* defualt_locale = nullptr;
FlutterLocale* flutter_locale = nullptr;
std::vector<FlutterLocale*> flutter_locales;

int ret = i18n_ulocale_set_default(getenv("LC_TIME"));
ret = i18n_ulocale_get_default(&defualt_locale);
if (ret != I18N_ERROR_NONE) {
FT_LOGE("i18n_ulocale_get_default() failed.");
return;
}

std::string without_encoding_type(defualt_locale);
auto n = without_encoding_type.find('.');
without_encoding_type.erase(n, without_encoding_type.length() - n);

flutter_locale = GetFlutterLocale(without_encoding_type.data());
if (flutter_locale) {
FT_LOGD("Choose Default locale[%s]", without_encoding_type.data());
flutter_locales.push_back(flutter_locale);
}

int32_t count = i18n_ulocale_count_available();
if (count > 0) {
FlutterLocale* flutterLocale = nullptr;
std::vector<FlutterLocale*> flutterLocales;
for (int i = 0; i < count; i++) {
const char* locale = i18n_ulocale_get_available(i);
flutterLocale = GetFlutterLocale(locale);
if (flutterLocale) {
flutterLocales.push_back(flutterLocale);
for (int i = 0; i < count; i++) {
const char* locale = i18n_ulocale_get_available(i);
if (without_encoding_type.compare(locale) != 0) {
flutter_locale = GetFlutterLocale(locale);
if (flutter_locale) {
flutter_locales.push_back(flutter_locale);
}
}
}

// send locales to engine
FlutterEngineUpdateLocales(
flutter_engine_,
const_cast<const FlutterLocale**>(flutterLocales.data()),
flutterLocales.size());
FT_LOGD("Send %zu available locales", flutter_locales.size());
// send locales to engine
FlutterEngineUpdateLocales(
flutter_engine_,
const_cast<const FlutterLocale**>(flutter_locales.data()),
flutter_locales.size());

for (auto it : flutterLocales) {
DestroyFlutterLocale(it);
}
for (auto it : flutter_locales) {
DestroyFlutterLocale(it);
}

SendPlatformResolvedLocale();
}

void LocalizationChannel::SendPlatformResolvedLocale() {
Expand Down