You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi. I've made an app that uses localizations, as described in the Flutter docs. I've tried to run the example project, and that implementation works. However, when implemented using the official Flutter guide, it doesn't work. I've added a complete runnable project that demonstrates this issue.
Other localized strings works as intended , but the static CountryLocalizations? of(BuildContext context) method in country_localizations.dart returns null, which means that none of the strings in the package are translated. I'm not completely sure what causes this issue, because the inner workings of the Flutter localizations still remains a mystery to me.
An example of a workaround fould be to return CountryLocalizations(Localizations.localeOf(context)) instead of Localizations.of<CountryLocalizations>(context, CountryLocalizations), but I don't know if this comes with some kind of cost. Thoughts?
The text was updated successfully, but these errors were encountered:
@tverra The package follows the official Flutter guide for localizations.
For each package that support localization the app must include the package's delegate in the list of the app delegates. So for country_picker package you have to add the CountryLocalizations.delegate in the list of your app delegates.
If you check the example from the Flutter docs, in this example the app import localizations for Material, Widgets, Cupertino and the app.
MaterialApp(
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
constLocale('en', ''), // English, no country codeconstLocale('ar', ''), // Arabic, no country codeconstLocale.fromSubtags(languageCode:'zh'), // Chinese *See Advanced Locales below*
],
)
You're right, I completely missed that. I haven't seen this approach in a Flutter package before. I'm using this package inside my own package, and it kinda seems like just getting the locale from the application context is a more elegant solution than needing the user of my package to add localization delegates for every translatable package their application depends on. But anyway, thanks!
Hi. I've made an app that uses localizations, as described in the Flutter docs. I've tried to run the example project, and that implementation works. However, when implemented using the official Flutter guide, it doesn't work. I've added a complete runnable project that demonstrates this issue.
Other localized strings works as intended , but the
static CountryLocalizations? of(BuildContext context)
method incountry_localizations.dart
returns null, which means that none of the strings in the package are translated. I'm not completely sure what causes this issue, because the inner workings of the Flutter localizations still remains a mystery to me.An example of a workaround fould be to return
CountryLocalizations(Localizations.localeOf(context))
instead ofLocalizations.of<CountryLocalizations>(context, CountryLocalizations)
, but I don't know if this comes with some kind of cost. Thoughts?The text was updated successfully, but these errors were encountered: