twine
twine copied to clipboard
Created Flutter formatter to handle ".arb" files
TL;DR: need advice to finish developing a Flutter formatter.
Hi Sebastian, I am a mobile developer on a small Italian team that develops mostly native and we use twine on many projects to keep localizations strings aligned between iOS and Android, so first of all I want to thank you for creating this project: great job!
Anyway, now I'm working on a cross-platform project using Flutter and I think that twine would still be a good option to handle localizations in a single file, so I'm trying to implement a Flutter formatter to handle ".arb" files. These files have a syntax very similar to json so I'm taking inspiration from this pull request where I've seen you rightfully asked to also implement tests.
Keeping in mind that I have zero experience on Ruby, can you give me some advice on how to test my changes locally? Here are some questions:
- How can I run locally the modified twine with my added formatter? I tried simply
ruby twine.rb consume-localization-file flutter_import_test.txt app_en.arb
but it gives me error onrequire 'twine/formatters/flutter'
line. - How can I run tests locally? As you can see I added a
TestFlutterFormatter
ontest/test_formatters.rb
but I have no clue on how to run those tests... - The default examples of Flutter localization insert the language in the filename, not in the path, so the
default_file_name
makes less sense in this case. How should I handle it? Defaulting to "en" language?
Excuse me for my newbie questions, but I've only written short single-file scripts in Ruby until now, so I need some hints to understand this project architecture.
Thank you and have a nice day
Welcome! Thanks for your work, but please know that the recommended way to develop new formatters is actually using the plugin architecture which you can read more about at the end of the formatters documentation page.
- How can I run locally the modified twine with my added formatter? I tried simply
ruby twine.rb consume-localization-file flutter_import_test.txt app_en.arb
but it gives me error onrequire 'twine/formatters/flutter'
line.
You should be able to run twine locally by using the ./twine
executable located at the root of the repository. When I checkout your branch and run ./twine --help
I get the following error, which indicates a syntax error in your new code:
flutter.rb:80: syntax error, unexpected end-of-input, expecting `end' (SyntaxError)
- How can I run tests locally? As you can see I added a
TestFlutterFormatter
ontest/test_formatters.rb
but I have no clue on how to run those tests...
We use Bundler for dependency management in twine. You should be able to get unit tests up and running by executing the following:
bundle install
bundle exec rake test
- The default examples of Flutter localization insert the language in the filename, not in the path, so the
default_file_name
makes less sense in this case. How should I handle it? Defaulting to "en" language?
It's been a while since I've looked at the code, so I am not sure how well twine supports this. It's only really used in generate_all_localization_files
and generate_localization_archive
so you may not need it for your usecase. For you it might be fine to leave it as app.arb
.
Sorry, I didn't understand that the plugin architecture was the recommended one. So I guess I need to understand how to create a gem. Is there an example of an existing formatter plugin?
No worries! It's basically the same code but just hosted in your own repository. You are also welcome to fork twine and add it there for your own uses, but we are trying to avoid adding too many formatters to this repository because it's hard for us to support them.
https://github.com/appium/appium_twine is an example but I have not verified that it works.
Nice! I added it to a new sample plugins section in the documentation.