55
66#include " flutter_tizen_engine.h"
77
8- #ifndef __X64_SHELL__
9- #include < utils_i18n.h>
10- #endif
11-
128#include < algorithm>
139#include < string>
1410#include < vector>
1511
12+ #include " flutter/shell/platform/tizen/system_utils.h"
1613#include " flutter/shell/platform/tizen/tizen_log.h"
1714
1815namespace flutter {
@@ -35,17 +32,9 @@ constexpr double kProfileFactor = 2.0;
3532constexpr double kProfileFactor = 1.0 ;
3633#endif
3734
38- #ifndef __X64_SHELL__
39- struct LocaleInfo {
40- std::string language;
41- std::string country;
42- std::string script;
43- std::string variant;
44- };
45-
46- // Converts a LocaleInfo struct to a FlutterLocale struct. |info| must outlive
35+ // Converts a LanguageInfo struct to a FlutterLocale struct. |info| must outlive
4736// the returned value, since the returned FlutterLocale has pointers into it.
48- FlutterLocale CovertToFlutterLocale (const LocaleInfo & info) {
37+ FlutterLocale CovertToFlutterLocale (const LanguageInfo & info) {
4938 FlutterLocale locale = {};
5039 locale.struct_size = sizeof (FlutterLocale);
5140 locale.language_code = info.language .c_str ();
@@ -60,7 +49,6 @@ FlutterLocale CovertToFlutterLocale(const LocaleInfo& info) {
6049 }
6150 return locale;
6251}
63- #endif
6452
6553} // namespace
6654
@@ -416,64 +404,13 @@ void FlutterTizenEngine::OnVsync(intptr_t baton,
416404}
417405
418406void FlutterTizenEngine::SetupLocales () {
419- #ifndef __X64_SHELL__
420- i18n_ulocale_set_default (getenv (" LANG" ));
421-
422- const char * locale_id;
423- int ret = i18n_ulocale_get_default (&locale_id);
424- if (ret != I18N_ERROR_NONE) {
425- FT_LOGE (" i18n_ulocale_get_default() failed." );
426- return ;
427- }
428- std::string preferred_locale (locale_id);
429- preferred_locale = preferred_locale.substr (0 , preferred_locale.find (" ." ));
430-
431- std::vector<LocaleInfo> locales;
432- int32_t count = i18n_ulocale_count_available ();
433- locales.reserve (count);
434- for (int i = 0 ; i < count; i++) {
435- LocaleInfo locale;
436- int ret;
437- char buffer[128 ] = {0 };
438- int32_t size;
439-
440- // The "language" field is required.
441- locale_id = i18n_ulocale_get_available (i);
442- ret = i18n_ulocale_get_language (locale_id, buffer, sizeof (buffer), &size);
443- if (ret != I18N_ERROR_NONE || size == 0 ) {
444- continue ;
445- }
446- locale.language = std::string (buffer, size);
447-
448- // "country", "script", and "variant" are optional.
449- size = i18n_ulocale_get_country (locale_id, buffer, sizeof (buffer), &ret);
450- if (ret == I18N_ERROR_NONE && size > 0 ) {
451- locale.country = std::string (buffer, size);
452- }
453- size = i18n_ulocale_get_script (locale_id, buffer, sizeof (buffer));
454- if (size > 0 ) {
455- locale.script = std::string (buffer, size);
456- }
457- size = i18n_ulocale_get_variant (locale_id, buffer, sizeof (buffer));
458- if (size > 0 ) {
459- locale.variant = std::string (buffer, size);
460- }
461-
462- if (preferred_locale.compare (locale_id) == 0 ) {
463- locales.insert (locales.begin (), locale);
464- } else {
465- locales.push_back (locale);
466- }
467- }
468- FT_LOGI (" Found %zu locales." , locales.size ());
469-
470- // The locale list should be converted into the FlutterLocale list, and again
471- // to the FlutterLocale* list.
407+ std::vector<LanguageInfo> languages = GetPreferredLanguageInfo ();
472408 std::vector<FlutterLocale> flutter_locales;
473- flutter_locales.reserve (locales .size ());
474- for (const auto & info : locales ) {
409+ flutter_locales.reserve (languages .size ());
410+ for (const auto & info : languages ) {
475411 flutter_locales.push_back (CovertToFlutterLocale (info));
476412 }
413+ // Convert the locale list to the locale pointer list that must be provided.
477414 std::vector<const FlutterLocale*> flutter_locale_list;
478415 flutter_locale_list.reserve (flutter_locales.size ());
479416 std::transform (
@@ -483,7 +420,6 @@ void FlutterTizenEngine::SetupLocales() {
483420
484421 embedder_api_.UpdateLocales (engine_, flutter_locale_list.data (),
485422 flutter_locale_list.size ());
486- #endif
487423}
488424
489425void FlutterTizenEngine::NotifyLowMemoryWarning () {
0 commit comments