RejectedSoftware Forums

Sign up

Diet templates are not being localized despite having the translation context working right

Hi,

I can't seem to be able to get Diet templates to be localized properly using the built-in "&" syntax as demonstrated in the example. Calling trWeb() however works fine, so I'm a bit lost on what I did wrong.

@translationContext!MyTranslations
public class MyController {
	public void index(HTTPServerRequest req, HTTPServerResponse res) {
		res.render!("view.dt");
	}
}
h1& Welcome
h2= trWeb("Welcome")

The end result is:

<h1> Welcome </h1>
<h2> Bienvenue </h2>

I can see that trWeb does find the translation context properly, uses the correct language and translates my string fine, but the & operator in the templates doesn't. I tried using renderCompat as well with no change at all.

I'm using the latest vibe.d (0.9.23) and latest dmd (2.067.0).

Any ideas?

Re: Diet templates are not being localized despite having the translation context working right

Am 17.04.2015 um 22:35 schrieb Maxime Poulin:

Hi,

I can't seem to be able to get Diet templates to be localized properly using the built-in "&" syntax as demonstrated in the example. Calling trWeb() however works fine, so I'm a bit lost on what I did wrong.

@translationContext!MyTranslations
public class MyController {
	public void index(HTTPServerRequest req, HTTPServerResponse res) {
		res.render!("view.dt");
	}
}

The compile-time translation is currently a feature of
vibe.web.web.render and doesn't work with the low level render, so
the following should work:

@translationContext!MyTranslations
public class MyController {
	public void index() {
		render!("view.dt");
	}
}

There should probably a warning message for this situation. I'll look
into that.

Re: Diet templates are not being localized despite having the translation context working right

On Fri, 17 Apr 2015 22:43:31 +0200, Sönke Ludwig wrote:

Am 17.04.2015 um 22:35 schrieb Maxime Poulin:
The compile-time translation is currently a feature of
vibe.web.web.render and doesn't work with the low level render, so
the following should work:

@translationContext!MyTranslations
public class MyController {
	public void index() {
		render!("view.dt");
	}
}

It worked, thanks!

There should probably a warning message for this situation. I'll look
into that.

A warning would indeed be pretty nice in this situation. A way to manually pass a translation context to the parser would also be cool and make things a bit clearer. I don't have a use case for it (yet), but I'm thinking about compileDietFile and compileDietString when the output is not a web request, like a file or a pipe to a PDF generating program such as wkhtmltopdf.

Anyway, all good for now, thanks for the very fast response!