ForgeTotal.js 5
en

Total.js 5

Translate a view into several languages

Total.js 5 · total5@0.0.19 localizationi18nviews Executed against Total.js 5

Wrap any text of a view in @(...) and Total.js replaces it with the translation for the current language. Translations live in resources/<language>.resource; each line is key : translation. The key is T plus the hash of the original text in base 36, which total5 can generate for you. Texts without a translation stay as written, so the view text acts as the default language.

LOCALIZE() decides the language of each request. Here it is read from the query string, but it can be a cookie, a header or a URL segment.

definitions/localization.js
LOCALIZE(function($) {
	return $.query.lang;
});
resources/sk.resource
// Total.js translation file
T4oxobw : Vitajte v obchode
views/index.html
@{layout('')}
<h1>@(Welcome to the shop)</h1>
controllers/default.js
exports.install = function() {
	ROUTE('GET /', home);
};

function home($) {
	$.view('index');
}