Extract all strings from dart to arb in Flutter

Photo by NeONBRAND on Unsplash

Flutter’s internationalisation is a solid approach to support localisation in the apps. However there is no easy way to extract strings from the dart codes into the arbs. The Flutter Intl plugin supports exporting strings using the IDE’s context menu but that is only available for single strings. So I created a code we can run to extract almost all strings from the codes.

Technical Details

What it does is that it searches for double and single qouted strings in a line and fetches the word/sentence in between.

Things you can do with the library code

Extract Strings to arb

  • Open strings_to_arb.dart
  • Make sure write = true at line 67.
  • In Android studio , run strings_to_arb by right clicking -> run
  • This will show the list of strings that are still present in the Dart files, keep in mind some strings do not need to be copied. It will copy all the strings to the outputFilename mentioned in the file, by default it is intl_en.arb.dart.

Find all strings present in the codes

  • Open strings_to_arb.dart
  • Make sure write = false at line 67.
  • In Android studio , run strings_to_arb by right clicking -> run
  • This will show the list of strings that are still present in the Dart files, keep in mind some strings do not need to be copied.
  • Install Flutter Intl plugin in Android Studio. After installing that plugin, it should show an extract to arb view action whenever we are over a string. (the left bulb icon) . Use that to extract all remaining strings.

Skip Folders and Files that you want to manually extract

Modify the variable skipFiles at line 71

To skip folders: add the names of the folders in the strings_to_arb.dart

To skip files: add the name of the file along with its extension.

var skipFiles = ["strings_to_arb.dart", "models", "generated"];

The above code with skip the strings_to_arb.dart file and ‘models’ and ‘generated’ folders.

Thanks for reading, let me know if I should create a video for it. Like my article and start my repos. Thanks

--

--

--

Lead Android Developer, Flutter Lover

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The receptionist, security guard, decorator and delivery person — NCVO’s front controller

What is Test-Driven Development? — A Quick Simple Explanation of the Mindset Behind TDD

Flutter x Bitrise

Implementing XKCD’s Map Reactions: Part 1

Prioritizing and Planning a Way Out of Technical Debt

Programmer’s Google Fast

The Final Standard Egg Sale

Django; Customizing Built-in User Model

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nabil Mosharraf Hossain

Nabil Mosharraf Hossain

Lead Android Developer, Flutter Lover

More from Medium

What is Google Flutter? | Everything You Need To Know About Flutter

Introduction to Android/Flutter app’s security with DummyCastle library.

Track Dialog States in Flutter #FlutterTips

Use Provider for navigating between screens in Drawer items in Flutter