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
Improve i18n/locale support #534
Comments
I built a multi-lang app with Not sure why we need a |
An example is this:- I have a loop which is sending out mails. The language of the mail depends upon the language of the recipient. I do have multiple messages*.properties, but how does that help in this case? I can use Locale.setDefault("xx") prior to template.apply(), but it's not thread-safe, so sometimes the mail goes out in the wrong language (Locale is changed on another thread) So, I have to "hard code" the locale into the template {{i18n "hello" locale="fr" bundle="messages"}} resulting in multiple templates. |
are you using Suppose there is a Template template = ...;
for (Recipient r : recipients) {
template.apply(r);
}
Does it work? |
Ah, OK, that's what I'm missing. Let me give that a shot and see if it works (it should I think) |
I can't get your suggestion to work unfortunately, the lang from the Recipient (as per your example) just gets ignored, and I always get the default bundle. I can only get it to work if I hard-code the locale e.g. locale="fr", and then it works. |
that isn't possible! what expression did you for In my example |
Maybe I'm completely missing something, but here are my files... i18n/mailbundle_fr.propertieshello=bonjour i18n/mailbundle.propertieshello=hello res/mailtemplate2.hbs{{{i18n "hello" bundle="i18n/mailbundle" locale=r.lang}}} test Recipient.javapublic class Recipient { HandlebarsTest.java
outputhello test |
Yea it should work... will try it later today and get back to you |
Thanks, I appreciate it! |
oh wait! I see the problem, there is no
you have a to use
👍 |
That did the trick! Thanks! |
cool, glad it works! Also, I invite you to try: http://jooby.org |
Unless I'm missing something, there doesn't seem to be a easy way of supporting multiple locales within the same template, which results in needing multiple templates.
Using Locale.setDefault('xx') in Java is not thread-safe, so not a solution.
What I'd like ideally would be to have an alternative method signature to template.apply() which accepted a Locale object.
e.g. public String apply(Object context, Locale locale)
The text was updated successfully, but these errors were encountered: