skip to Main Content

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


  1. Chosen as BEST ANSWER

    Thank you for your fast answer: in the pubspec.yaml its correct configured:

    flutter:
      uses-material-design: true
      assets:
        - assets/lang/
    

    the direction is also correct:

    assets/lang/de-DE.json
    assets/lang/en-EN.json
    

    the startLocale is also loading correctly:

    [🌎 Easy Localization] [INFO] Start locale loaded de_DE
    [🌎 Easy Localization] [DEBUG] Build
    [🌎 Easy Localization] [DEBUG] Init Localization Delegate
    [🌎 Easy Localization] [DEBUG] Init provider
    [🌎 Easy Localization] [DEBUG] Load Localization Delegate
    2
    [🌎 Easy Localization] [DEBUG] Load asset from assets/lang
    

  2. 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’),
    // …
    ),
    );
    }

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search