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
JIT-selecting preferred Locale from accepted locales list and available locales set/map #43
Comments
Hi Valentin,
Sure. Note that
The
What you're trying to do seems quite reasonable, and would be difficult with Tower currently - so in principle I am on board with adding support if we can do it in a way that's sensible... Let me think about this a little and I'll get back to you! Cheers :-) |
Thanks for the walkthrough, I'd been looking for Anyway, I'd be glad to contribute, let me know if I can help :). |
There's a large update pending on the dev branch. Any work on this will have to target that. There's some breaking API changes, so I've been reluctant to merge into master until I'm sure I'm satisfied with the changes.
I appreciate that, thank you. Am actually experimenting with this right now. It might be possible to get this working with only a minor change, but I'd like to confirm. Will definitely come back to you if there's something you could assist with. |
Okay, I've updated These'll be searched intelligently. From the updated README:
This works in both Clojure and ClojureScript versions of Tower. Also modified the Ring middleware to use all Accept-Language header languages in this way: dictionaries will automatically be searched for translation entries intelligently. Haven't tested this much (esp. the middleware), so feedback and/or bug reports welcome. Cheers! :-) |
Thank you, but I think the preference order is not quite right. In your example, I believe 1-3-2-4-5-6 is more relevant (If you value The examples in my first post can give you an idea of what I have in mind, if you want I can come up with a more complete one. Cheers, |
Sure, fixed: 244e082 |
Note that this search strategy does handle some forms of Accept-Language a bit strangely. For example, a I don't personally think that's a big issue though, since the Accept-Language choices are rarely intentionally specific to that extent. |
That's what I was thinking about when I said "more complete example", and indeed I think it's an issue. But I agree it's not an emergency, I suggest to file it as an improvement and take the time to think about it. |
Also, if we go down that road, that suggests changing the Ring middleware too, don't you think? |
Sure.
I don't follow, sorry? |
Well, for example we could make the Ring middleware attach to the request a translation (partial) function that uses the Locales list extracted from its accept-language header. From what I understand, the current Ring middleware selects "blindly" a best locale for the translations that will result from the request, and attaches a partial translation function for that purpose. But that new implementation of (handler (assoc request :locale (tower/locale-key loc)
:tconfig tconfig
:t (if tconfig
(partial tower/t accepted-locs tconfig)
(partial tower/t accepted-locs)))) in |
Ahh, gotcha. Yes, I actually made the change as part of the earlier 2.1.0 snapshot: All the commits on the |
My mistake, I wasn't looking at the right place. Fine then:) |
I find myself in a situation where I do not anticipate what locales are available to me (i.e the config is unanticipated) and I have a list of accepted locales in preference order (typically from an HTTP Accept-languages header). So I'd like to know, for a particular message, which is the best locale to choose from those that are bore available in my config and accepted. I posted on StackOverflow about this.
In other words, it'd be nice to be able to do something like
but you can't. And I cannot add that functionality in a proper way in my own application because I'd need access to the
loc-tree
function which is private.So I propose as a first step towards this to implement a
preferred-lang
function that may look like this :What do you think? Shall I give it a try and make a pull request from it?
The text was updated successfully, but these errors were encountered: