Why doesn't Flutter generate localization files?

When it comes to generating localization files in Flutter, the root of the problem depends on the approach used for localization. There are two main generators used for localization in Flutter: gen_l10n and Flutter Intl.

The most common reason why gen_l10n doesn't generate the needed localization files is that it is not properly configured. One of the common mistakes that people make is putting the l10n.yaml file in the wrong directory, like the lib folder instead of the project root. Moreover, the gen_l10n by default generates the localization files as a synthetic package in the <project_dir>.dart_tool/flutter_gen/gen_l10n folder. If you don't see the localization files in the project, check if they're in this folder. Also, you can always manually invoke generation by running the flutter gen-l10n command and check if there are any errors in the console.

For Flutter Intl, the main reason why it may not generate localization code is after upgrading Flutter, there might be a problem with the cache. However, reactivating the globally activated intl_utils package can solve this problem.

Flutter internationalization tutorial:

Copyrights 2024 © Localizely