-
Notifications
You must be signed in to change notification settings - Fork 84
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
Return locale from backend read/write methods #305
base: master
Are you sure you want to change the base?
Conversation
ed9fa9b
to
6241068
Compare
@pwim Interested to get your thoughts on this. I'm making an api change for a v1.0 release that I'm planning somewhere in the next month or so. The change is that backends will now return the locale along with the value from a Attribute getters/setters would not change (obviously), so I believe most users would be unaffected, but I'm hesitating about how to return the locale. The code in this PR returns a pair: locale, value = post.title_backend.read(:en) I originally was going to return Any thoughts? |
What the person on StackOverflow wants to do seems like an edge case. I'd want to better understand how they are using the "Content-Language" header before proceeding. That being said, if you are going forward with exposing the language of the translation, I'd consider if it makes sense for |
That particular use case is not really so important. The use case for "I want to know if this is a fallback or the original translation" is pretty clear. I myself have needed that, for example showing a value in an interface which allows you to translate them: if it's not available, show the fallback but indicate it has not yet been translated. But you currently can't do that with Mobility. Other plugins could also use this, e.g. knowing whether a value is the default or the actual translation, if a value was cached or not (for debugging), etc.
Yeah I thought of that. There is actually already a similar object: mobility/lib/mobility/backend.rb Lines 220 to 226 in 209a968
I agree that might work, my concern there would be that plugins would have to modify the object passed back to them, and not sure how clean that would be. But then again, the changes with destructuring arrays in this PR are not so clean either... |
This makes sense. Though I don't think it specifically requires knowing what fallback is used, just whether or not their is a translation for a given locale.
Perhaps if I saw an example of how a plugin would use it, I could give better feedback, but I'm missing how a plugin would need to treat a translation object differently than an array. Rather than modifying the object itself, it should just be able to create a new instance instead (as presumably it would be doing if it worked with arrays). |
Yes, but if we're going to return a boolean, we might as well return the actual locale, since this is actually simpler. Users can then do what they want with it.
Yes true. I'm still thinking about how to implement this, but if it's in it should be in for 1.0 since it's a major API change. |
This is a major API change coming for v1.0. Backends will now return the locale and value from
read
andwrite
methods. This allows for better handling when using things like fallbacks, e.g. see the issue here.This will not change the normal model getter/setter methods, so most applications will be unaffected.