On Sun, 23 Apr 2017 12:37:47 GMT, Sönke Ludwig wrote:

On Sat, 15 Apr 2017 13:32:26 GMT, yes9111 wrote:

This is a more of a question related to D & templates than vibe and i18n, but I hope you guys can help me out. I need i18n on my website and had the idea of using different translationcontexts for different WebInterface controllers. Each web interface class provides the same languages to support but uses translation PO files.

Question 1 - Is it ok to have multiple translation files specified for a single translation context?

Yes, multiple mixin translationModule!"..."; statements should work as expected.

Question 2 - Is it ok to specify multiple translation contexts for a single app?

Only a single allocation context is supported per interface class, but different interface classes can use different translation contexts. Might be interesting to add support for easy context composition in cases where this is not sufficient/convenient.

Question 3 - I was thinking of making a struct template to make it easy but I'm getting lost on d templates. Whats the proper way of coding this?

struct TranslationContext(string[] contextFiles){
	import std.typetuple;
	enum enforceExistingKeys = true;

	alias languages = TypeTuple!("en_US", "de_DE");

	foreach(context; contextFiles){
		mixin translationModule!context;
	}
}

The desired effect is that I can use

@translateContext!TranslationContext!(["foo", "bar"])
class WebInterface{ ... }

Thanks

This should basically work, but foreach currently has some limitations (issue 4085, issue 1642). The simplest alternative is to use a string mixin:

struct TranslationContext(string[] contextFiles){
	// ...

	import std.format : format;
	mixin(format("%(mixin translationModule!%s;%);", strs));
}

The usage example above was missing a pair of clamps, but should otherwise work: @translationContext!(TranslationContext!(["foo", "bar"]))

Perfect, thanks!