Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #3
In this PR we move away from using the
Rosetta.locale
global to scope translations for a given key to a given locale.The design and its pros and cons were previously explained in #3.
While working on #10, it became clear that we needed dedicated getters and setters for scoped translations. Things like:
A new
Translated
module is introduced, heavily inspired by what's been implemented in ActiveStorage in Rails itself. The main advantage of this design is that we can defer the setup of thehas_one
association when the parent model is saved.Additionnal logic can be implemented in
Rosetta::Translated::Create
andRosetta::Translated::Delete
to account for future needs and design evolution.Finally, the main blocker for implementing this was that we know available locales only at runtime. This is fine for existing locales, but new locales would not be associated to the TranslationKey model.
This is fixed by adding a listener to the after a new locale is created. Translated model are notified of the newly created locale and appropriate associations are setup.
rosetta/app/models/rosetta/locale.rb
Lines 36 to 38 in dc0efb0
Note: the corollary is that locale codes can't be updated after the locale is created.