struct TranslationContext { import std.typetuple; alias languages = TypeTuple!("en_US", "de_DE", "fr_FR"); //mixin translationModule!"app"; //mixin translationModule!"somelib"; } @translationContext!TranslationContext class MyWebInterface { void getHome() { //render!("home.dt") } }
Defining a custom function for determining the language.
import vibe.http.server; struct TranslationContext { import std.typetuple; alias languages = TypeTuple!("en_US", "de_DE", "fr_FR"); //mixin translationModule!"app"; //mixin translationModule!"somelib"; // use language settings from the session instead of using the // "Accept-Language" header static string determineLanguage(scope HTTPServerRequest req) { if (!req.session) return null; // use default language return req.session.get("language", ""); } } @translationContext!TranslationContext class MyWebInterface { void getHome() { //render!("home.dt") } }
Annotates an interface method or class with translation information.
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 hb.web.web.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).