Flutter Package with Intl Localization

Gerrel
2 min readDec 27, 2019

--

By finding this article you probably found out that the Dart Intl localization package does not support having localizations in your package. But we can solve this with a small patch.

When you’ve followed the steps of ‘Flutter: Localization Quick Start’ you will end up with some generated .dart and .arb files. Open the messages_all.dart and add the patch below.

(* when generating localization files use ‘no-use-deferred-loading’ option)

In step 2 of the Quick start you’ve added ‘localizable.dart’, but we need to replace it with the code below so that the class uses our patch.

So the code changes make sure that the message lookup is not initialized globally in the app, but is handled by our own class (Localizable). We have added the class ‘_Intl’ and reference it with the property ‘final _Intl Intl’ to intercept the Intl.message call. You’re string references need to call ‘Intl.message’ because calling it anything else will cause it to be ignored by the Intl package .arb file generator!

When you add your flutter package to your flutter app you do need to export your localization delegate. Like the code below.

And like all other packages with localizations you need to add the delegate to your app like below.

And thats it. You can now create flutter packages with embedded Intl localizations.

--

--

Gerrel

Native mobile app developer (Android/Flutter/iOS)