Localizations #42
-
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 An example of a workaround fould be to return |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
@tverra The package follows the official Flutter guide for localizations. 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: [
const Locale('en', ''), // English, no country code
const Locale('ar', ''), // Arabic, no country code
const Locale.fromSubtags(languageCode: 'zh'), // Chinese *See Advanced Locales below*
],
) So in your example project change the code to: MaterialApp(
title: 'Localizations Demo',
localizationsDelegates: [
CountryLocalizations.delegate,
...AppLocalizations.localizationsDelegates
],
supportedLocales: AppLocalizations.supportedLocales,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
); |
Beta Was this translation helpful? Give feedback.
-
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! |
Beta Was this translation helpful? Give feedback.
@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 theCountryLocalizations.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.