Flutter easy localization Source path does not exist

Viewed 5206

I'm trying to add Spanish to my flutter project with easy_localization i added JSON files of US and ES and added the path to it in runApp function as I try to generate keys with flutter

pub run easy_localization:generate
runApp(EasyLocalization(
      supportedLocales: [Locale('en', 'US'), Locale('es', 'ES')],
      path: 'assets/translations/',
      fallbackLocale: Locale('en', 'US'),
      child: MyApp()));
6 Answers

simply just put the path of the folder where localization files are, in my case.

flutter pub run easy_localization:generate --source-dir ./assets/translations

In case someone get the same error while generating locale_keys.g.dart use the below code:

flutter pub run easy_localization:generate -S assets/translations -f keys -o locale_keys.g.dart

try the following code :

flutter pub run easy_localization:generate -s assets/translations

Remove /(forwad slash symbol) from path Like path:"assets/translations"

that's it.

Make sure translations file path is given properly in below command, also add locale_keys.g.dart to generate a file with the same name.

flutter pub run easy_localization:generate --source-dir ./assets/translations -f keys -o locale_keys.g.dart

Usage:

import 'package:easy_localization/easy_localization.dart';

LocaleKeys.Name /// Similar way find your keys which declared inside .json file

try the following code:

flutter pub run easy_localization:generate -O lib/core/lang -f keys -o locale_keys.g.dart --source-dir ./assets/lang
Related