简体   繁体   中英

looking to translate the page to another language. localization example of total js?.Does it translate the whole page/welcome message?

// Total.js translation file // Created: 2014-12-18 10:32

// index.html

T80818744        : Titulok
T-52966915       : Ahoj svet!
T-1870230665     : Total.js je webový framework pre Node.js

// IMPORTANT: This line was created manually

message : Priame čítanie

Total.js can translate only phrases wrapped in @(TEXT TO LOCALIZE) . First you need to define Total.js delegate onLocale which can set the language for each request:

F.onLocale = function(req) {

    // req.query.*
    // req.cookie('cookie_name');
    // req.headers['*']

    switch (req.query.langauge) {
        case 'sk':
        case 'cz':
        case 'ru':
            return req.query.langauge;
    }

    return 'en';
};
  • framework tries to find a resource file in the form /resources/YOURLANGUAGE.resource
  • if the file exists then the framework applies localization
  • otherwise the framework will use a default resource called: default.resource (if exists)
  • otherwise the framework use the phrases defined in views

How to create a resource file with localization?

I have prepared great utilites for localization, just install Total.js framework as a global library from NPM: $ sudo npm install -g total.js

$ cd yourapp
$ totaljs --translate

Total.js terminal app will create translate.resource file. Localize this file and copy it to /resources/YOURLANGUAGE.resource and restart app. That's all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM