taoensso / tower

i18n & L10n library for Clojure/Script
https://www.taoensso.com/tower
Eclipse Public License 1.0
278 stars 24 forks source link

What's the usual way of declaring the HTML language when using tower? #47

Closed Frozenlock closed 10 years ago

Frozenlock commented 10 years ago

One should usually let the browser know what is the language of the document. (see http://nimbupani.com/declaring-languages-in-html-5.html)

How is that usually done with Tower?

ptaoussanis commented 10 years ago

Hey there,

If you're using the Ring middleware, you'll have some additional info in your Ring requests like a :locale and :t translation fn.

Note that the :locale isn't necessarily the language your users will end up seeing since that's dependant on what translations you actually have available in your dictionary. So a useful trick here may be to use the t translation fn while generating your HTML templates. Something like:

(str "<html lang=\"" (t :html-lang) "\">) ; => <html lang="en">, etc.

Then just make sure your dictionary has the necessary :html-lang keys. Does that make sense?

Frozenlock commented 10 years ago

Ah yes! I was worried about using the :locale from the request exactly because the user might just get a fallback language, but the :html-lang might just do it!