-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic fallbacks per instance #391
Comments
Overlap with #328 ? |
@shioyama that PR seems to have gone stale. Is there anything I can do to help move the process forward and get some sort of solution integrated into the library? What else is needed? I will be glad to help. |
@RobPando I'm working on a v1.0, and improving fallbacks fits in there. But I can't promise when that will be released, although I am putting time into it as you can see from the commit log. I'd love to ask for help, but the problem is that the interface for the fallbacks plugin right now is ugly and I'd like to take this opportunity to improve it with 1.0. I think supporting procs makes a lot of sense and I intend to add it. What would be maybe more useful than implementation right now is agreeing on what the API would look like. You've suggested: translate :title, fallbacks: -> { en: my_dynamic_attribute_from_current_model } The earlier PR (and what I would imagine) would be something where you define a proc which takes the locale, and then does something to get the fallback, like this: translate :title, fallbacks: ->(locale) { ... } Does that work for you? |
@shioyama Thanks, that should definitely work as well. Looking forward to it. |
Also it would be nice to have global dynamic fallbacks, just like Mobility.with_locale, but Mobility.with_fallbacks &block |
Just want to give a heads up I could easily implement this as my own plugin with Mobility 1.0.0, see #328 (comment) |
Context
I am in need of a way to dynamically set the fallbacks based on each instance/record. I currently have a default fallback establish for I18n which is fine, however I need some records to have another locale as default leaving the I18n empty or nil, it works fine, for example say my default fallback locale is
en
and I try to do something liketranslates :title, fallbacks: { en: :nl }
this works as expected, I can leave theen
title empty if I havenl
. However, it won't always benl
this can be other languages and here is where my problem is because each record has a field calleddefault_locale
which I need want to pull from in order to declare the fallback foren
I tried looking but cannot find a way to do this.Expected Behavior
Ideally the instance object and attributes would be available to me or have ways to dynamically set fallbacks for the attributes. like:
Actual Behavior
There is no scope to the current instance that would allow me to declare a fallback based on the models attribute. I also have not found any other method that allows this.
Possible Fix
Having a way to scope and access the attributes of an instance inside fallbacks or a way to declare dynamic fallbacks on locales for each instance.
The text was updated successfully, but these errors were encountered: