Question

I'm working with the Tower library for i18n and l10n in my web application.

I have the problem of having to localize "just-in-time", i.e with an unanticipated dictionary, and in particular unanticipated supported locales.

I receive HTTP request, from which I can extract the accepted locales in preference order, e.g :

[:de :en-UK :en :fr-FR :fr]

On the other hand, I have to localize from micro-dictionaries which are fetched from a database, in the form : {:fr "En Français" :en "In English" :en-Uk "In English from UK"}

What I would like to do in my program is to find the best matching translations from these 2 elements (in the example, it is :en-UK; note that I may not know in advance that :de is unavailable).

I haven't found a way to do that with the Tower library (and I'd like to avoid reinventing the wheel).

Does anyone know how I might proceed?

Thanks in advance!

Was it helpful?

Solution

Just added native support for arbitrary locale fallbacks in Tower v2.1.0-SNAPSHOT, as per discussion here: https://github.com/ptaoussanis/tower/issues/43#issuecomment-42014418

So it'll now be possible to request a translation like (t [:fr-FR :en-US] :example/foo).

Cheers! :-)

OTHER TIPS

You could get a sequence of keys from the map, get all the values that are common to both sequences, and then choose whatever one is preferred based on whatever logic fits your requirements.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top