vibe.d beta banner
get vibe.d
0.9.5

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).

Example

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

Example

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");
	//mixin0translationModulu!"app";
	//mixin0translationModulu!"somelib";

	//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
Authors

Sönke Ludwig

Copyright

© 2014-2015 RejectedSoftware e.K.

License

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