When managing application code, with layout and so stuff, having to handle additionaly arb translation files can be a real burden, especially when it involves several languages.
this helps you to solve this via a few operations, done in a loop every 5 seconds.
- Text translations extraction
It is somehow common to use _"..." strings to mark strings for translations when using
tools like gettext,
arb-utiluses this to detect what should be sent to arb files.- Goes through all the
.dartfiles in$(project.root)/liband searches for _"..." strings(Take note of the double quote). - generates a valid dart variable name of the text, like helloWorld then add's the key and it's string value to the [template-arb-file], the latter auto-sync will do add it in the other files.
- then replaces the string in the original file with
AppLocalizationscall.
- Goes through all the
- Arb files synchronization
- Goes through all the arb files and copies every missing key to the other, prepending with a '#'.
- Rebuld localizations
- If the arb files mtime have changed it runs using `flutter gen-l10n --project-dir=$(project.root)``.
First, make sure you have julia installed, or install from https://julialang.com/download. You can clone the repo with:
git clone https://github.com/recordbreakersorg/arb-util.gitgh repo clone recordbreakersorg/arb-util
Then to run the script, run the app change working directory to your project root.
if you have fish run:
/path/to/repo/manage.fish run
else manually run:
julia /path/ro/repo/src/main.jl
With julia installed, go to the cloned project and run:
./manage.fish compile, runs on my low-end pc in 11m 15s seconds and produces an ~224.9MB
executable.
Then running ./manage.fish run will detect the executable and use it.
!NOTE: adding the compiled executable to path may result in errors. Prefer creating a shell script to run it using it's full path.
!NOTE: Make sure you run the script in a compatible flutter project else you may get ugly errors.
Not implemented
Trimmed compilation uses to take less than a minute on similar projects, but the JSON package seems not to work well with juliac.jl, still looking for a fix...
Go to your project root(make sure to commit to prevent any loss... Crashes are still
possible and not well handled.), then run arb-util.
Then just code, to add a translation simply prepend any string literal in a .dart source
file in lib/, save and wait 8secs, arb-util's log will alert you it noticed the change and
the arb files will be updated. If you use neovim like me you just need to focus another
buffer or window before returning so as not to overwrite the changes.
- Add config file.
- Add import
AppLocalizationswhen not imported. - Allow customized
AppLocalizationscall. - Allow diferent arb translations folder location.
- Implement ai translation of the strings for other arb files.
- Use file content hash to check for modificaitons instead of mtime.