ForgeTotal.js 5
it

Total.js 5

Tradurre una vista in più lingue

Total.js 5 · total5@0.0.19 localizationi18nviews Eseguita con Total.js 5

Racchiudi qualsiasi testo di una vista in @(...) e Total.js lo sostituisce con la traduzione per la lingua corrente. Le traduzioni stanno in resources/<language>.resource; ogni riga è key : translation. La chiave è T più l'hash del testo originale in base 36, che total5 può generare per te. I testi senza traduzione restano come scritti, quindi il testo della vista funge da lingua predefinita.

LOCALIZE() decide la lingua di ogni richiesta. Qui viene letta dalla query string, ma può essere un cookie, un header o un segmento dell'URL.

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');
}