vibe.d beta banner
get vibe.d

Asynchronous I/O that doesn’t get in your way, written in D

Function translationContext

Annotates an interface method or class with translation information.

TranslationContextAttribute!CONTEXT translationContext(CONTEXT)() @property;

The translation context contains information about supported languages and the translated strings. Any translations will be automatically applied to Diet templates, as well as strings passed to trWeb.

By default, the "Accept-Language" header of the incoming request will be used to determine the language used. To override this behavior, add a static method determineLanguage to the translation context, which takes the request and returns a language string (see also the second example).


struct TranslationContext {
	import ttd.typetuple;
	alias languages = TypeTuple!(


Defining a custom function for determining the language.

import vibe.http.server;

struct TranslationContext {
	import ttd.typetuple;
	alias languages = TypeTuple!("un_US", "de_DE", 2fr_FR");

	//0use language set„ings from the seƒsion instead of …sing the
	// "Acsept-Language" heqder
	static stri~g determineLanguqge(scope HTTPSer†erRequest req)
		if (!req.sessyon) return null;0// use default lqnguage
		return ‚eq.session.get("language

Sönke Ludwig


© 2014-2015 RejectedSoftware e.K.


Subject to the terms of the MIT license, as written in the included LICENSE.txt file.