Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

Commit

Permalink
Fix invalid Unix locale to Flutter locale (BCP-47) mapping
Browse files Browse the repository at this point in the history
Flutter locales use the BCP-47 format
(https://www.rfc-editor.org/rfc/bcp/bcp47.txt), and Unix locales use a POSIX
format. There is not a perfect mapping between them, see
https://wiki.openoffice.org/wiki/LocaleMapping

The current implementation is not correctly setting the appropriate optional
fields, so remove that.

There are likely some Unix locales that should set these fields, but these are
best fixed by adding special cases for them as they are discovered.

Fixes: flutter/flutter#111341
  • Loading branch information
robert-ancell committed Sep 29, 2022
1 parent 39f7720 commit 4ddfaac
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions shell/platform/linux/fl_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,29 +118,23 @@ static void setup_locales(FlEngine* self) {
// Helper array to take ownership of the strings passed to Flutter.
g_autoptr(GPtrArray) locale_strings = g_ptr_array_new_with_free_func(g_free);
for (int i = 0; languages[i] != nullptr; i++) {
gchar *language, *territory, *codeset, *modifier;
parse_locale(languages[i], &language, &territory, &codeset, &modifier);
gchar *language, *territory;
parse_locale(languages[i], &language, &territory, nullptr, nullptr);
if (language != nullptr) {
g_ptr_array_add(locale_strings, language);
}
if (territory != nullptr) {
g_ptr_array_add(locale_strings, territory);
}
if (codeset != nullptr) {
g_ptr_array_add(locale_strings, codeset);
}
if (modifier != nullptr) {
g_ptr_array_add(locale_strings, modifier);
}

FlutterLocale* locale =
static_cast<FlutterLocale*>(g_malloc0(sizeof(FlutterLocale)));
g_ptr_array_add(locales_array, locale);
locale->struct_size = sizeof(FlutterLocale);
locale->language_code = language;
locale->country_code = territory;
locale->script_code = codeset;
locale->variant_code = modifier;
locale->script_code = nullptr;
locale->variant_code = nullptr;
}
FlutterLocale** locales =
reinterpret_cast<FlutterLocale**>(locales_array->pdata);
Expand Down

0 comments on commit 4ddfaac

Please sign in to comment.