Welcome to localize_it, yet another package for localizing your app.
This package is dedicated to everyone who had to localize a whole app from scratch. Flutter is awesome, but localizing your app can cause serious pain and demotivation.
We may have to:
- configure your localization for each project from scratch
- think of a
keyfor each String we want to localize
contexteverywhere we want to localize
- hire a Translation Service Provider for proper translation
Implementing all of this can take extra hours or days of extra work, which can be frustrating because it is also rather simple work but a lot.
Localize_it tries to fix that by doing all the annoying work for you, allowing you to focus on developing your app and make it globally available.
How to use
For a Flutter project:
flutter pub add localize_it_annotation flutter pub add --dev build_runner flutter pub add --dev localize_it
For a Dart project:
dart pub add localize_it_annotation dart pub add --dev build_runner dart pub add --dev localize_it
This installs three packages:
- build_runner, the tool to run code-generators
- localize_it, the code generator
- localize_it_annotation, a package containing annotations for localize_it.
2. localize_it x GetX
To get the most out of this package make sure to install GetX as well.
With that you can simply call
.tr behind every
String you want to translate.
This also gives you access to multiple other utils. See more on GetX.
3. Setup Config file (with VSCode Extension)
Next Step is to setup a config-file. Writing code by yourself? Haha.
Lucky for you there is a VSCode-Extension.
After installling it you can simply call
localize_it: Create anywhere inside your
|Supports all the currently available Source Languages (
|Should not contain
|Supports all the currently available Target Languages (
|via the DeepL API.|
|If no key is provided (empty String), all marked Strings (end with
|in your project will get translated to
|to enable Localization.|
||By default localize_it is searching for
|See prefer_single_quotes for more info.|
|However if you prefer using double quotes in your project you can do this|
5. Disable generate
build_runner to work you must disable
generate in your
flutter: # generate: true
See more on this issue.
You're ready to go!
Make sure to
clean your project before calling the
flutter clean flutter pub get
build_runner do the rest for you:
flutter pub run build_runner build --delete-conflicting-outputs
This will find all
Strings that end with
.tr in your project and localize them depending on your
Good to know
You can always change the translated text in your localization filels. The change/adjust will NOT be overritten when calling the script again.
You can call the script as often you want. Only the newly added
Stringswill be translated. This increases performance and makes sure that you don't reach your DeepL API limit.
Stringsthat you removed from your projects but are still in your
localizationswill be removed once you call the script again.
- Add Support to differenciate American/British English
- Having a ",\n" inside a
Stringthat should get localized will break the generator