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

Commit 9bf3ae6

Browse files
committed
Fix invalid Unix locale to Flutter locale (BCP-47) mapping
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
1 parent 39f7720 commit 9bf3ae6

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

shell/platform/linux/fl_engine.cc

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,29 +86,37 @@ static void parse_locale(const gchar* locale,
8686
// Locales are in the form "language[_territory][.codeset][@modifier]"
8787
gchar* match = strrchr(l, '@');
8888
if (match != nullptr) {
89-
*modifier = g_strdup(match + 1);
89+
if (modifier != nullptr) {
90+
*modifier = g_strdup(match + 1);
91+
}
9092
*match = '\0';
91-
} else {
93+
} else if (modifier != nullptr) {
9294
*modifier = nullptr;
9395
}
9496

9597
match = strrchr(l, '.');
9698
if (match != nullptr) {
97-
*codeset = g_strdup(match + 1);
99+
if (codeset != nullptr) {
100+
*codeset = g_strdup(match + 1);
101+
}
98102
*match = '\0';
99-
} else {
103+
} else if (codeset != nullptr) {
100104
*codeset = nullptr;
101105
}
102106

103107
match = strrchr(l, '_');
104108
if (match != nullptr) {
105-
*territory = g_strdup(match + 1);
109+
if (territory != nullptr) {
110+
*territory = g_strdup(match + 1);
111+
}
106112
*match = '\0';
107-
} else {
113+
} else if (territory != nullptr) {
108114
*territory = nullptr;
109115
}
110116

111-
*language = l;
117+
if (language != nullptr) {
118+
*language = l;
119+
}
112120
}
113121

114122
// Passes locale information to the Flutter engine.
@@ -118,29 +126,23 @@ static void setup_locales(FlEngine* self) {
118126
// Helper array to take ownership of the strings passed to Flutter.
119127
g_autoptr(GPtrArray) locale_strings = g_ptr_array_new_with_free_func(g_free);
120128
for (int i = 0; languages[i] != nullptr; i++) {
121-
gchar *language, *territory, *codeset, *modifier;
122-
parse_locale(languages[i], &language, &territory, &codeset, &modifier);
129+
gchar *language, *territory;
130+
parse_locale(languages[i], &language, &territory, nullptr, nullptr);
123131
if (language != nullptr) {
124132
g_ptr_array_add(locale_strings, language);
125133
}
126134
if (territory != nullptr) {
127135
g_ptr_array_add(locale_strings, territory);
128136
}
129-
if (codeset != nullptr) {
130-
g_ptr_array_add(locale_strings, codeset);
131-
}
132-
if (modifier != nullptr) {
133-
g_ptr_array_add(locale_strings, modifier);
134-
}
135137

136138
FlutterLocale* locale =
137139
static_cast<FlutterLocale*>(g_malloc0(sizeof(FlutterLocale)));
138140
g_ptr_array_add(locales_array, locale);
139141
locale->struct_size = sizeof(FlutterLocale);
140142
locale->language_code = language;
141143
locale->country_code = territory;
142-
locale->script_code = codeset;
143-
locale->variant_code = modifier;
144+
locale->script_code = nullptr;
145+
locale->variant_code = nullptr;
144146
}
145147
FlutterLocale** locales =
146148
reinterpret_cast<FlutterLocale**>(locales_array->pdata);

0 commit comments

Comments
 (0)