i have 2 Buttons where i can change the language. If i click the following code will executed.
this buttons are in my settings.dart file not in the main
onPressed: (context) async { await context.setLocale(const Locale('en', 'US'));
},
in the Debug console it says:
[π Easy Localization] [INFO] Locale en_US changed
[π Easy Localization] [INFO] Locale en_US saved
[π Easy Localization] [DEBUG] Build
[π Easy Localization] [DEBUG] Init Localization Delegate
[π Easy Localization] [DEBUG] Init provider
but
[π Easy Localization] [DEBUG] Load Localization Delegate
2
[π Easy Localization] [DEBUG] Load asset from assets/lang
is missing.
This is the configuration in my main:
void main() async {
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
runApp(
EasyLocalization(
startLocale: const Locale('de', 'DE'),
supportedLocales: const [Locale('en', 'US'), Locale('de', 'DE')],
path: 'assets/lang', // Pfad zu den Γbersetzungsdateien
fallbackLocale: const Locale(
'de', 'DE'),
Maybe someone can help me
2
Answers
Thank you for your fast answer: in the pubspec.yaml its correct configured:
the direction is also correct:
the startLocale is also loading correctly:
Make sure that the translation files are placed in the correct directory under the ‘assets’ folder
assets/
lang/
en_US.json
de_DE.json
Ensure that you have properly configured your pubspec.yaml
flutter:
assets:
– assets/lang/
Next,
Check that you are initializing Easy Localization correctly in your main.dart file
void main() async {
WidgetsFlutterBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
runApp(
EasyLocalization(
startLocale: const Locale(‘de’, ‘DE’),
supportedLocales: const [Locale(‘en’, ‘US’), Locale(‘de’, ‘DE’)],
path: ‘assets/lang’, // Path to the translation files
fallbackLocale: const Locale(‘de’, ‘DE’),
// …
),
);
}