2017-06-07 13:28:42 +00:00
|
|
|
var fs = require('fs');
|
|
|
|
var settings = require('./settings.js');
|
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
/**
|
2017-08-31 14:11:37 +00:00
|
|
|
* Returns template locale
|
|
|
|
* @param {String} template - Template name
|
|
|
|
* @param {String} countryCode - Language code
|
2017-06-07 13:28:42 +00:00
|
|
|
* @param {Object} cb - Callback
|
|
|
|
*/
|
|
|
|
load: function(template, countryCode, cb) {
|
|
|
|
var localeFile = path.join(__dirname, 'template', `${template}`, 'locale', `${countryCode}.json`);
|
|
|
|
var defaultLocaleFile = path.join(__dirname, 'template', `${template}`, 'locale', `${settings.app().defaultLanguage}.json`);
|
|
|
|
|
|
|
|
fs.stat(localeFile, (error, stats) => {
|
2017-08-31 14:11:37 +00:00
|
|
|
if (error) {
|
2017-06-07 13:28:42 +00:00
|
|
|
fs.stat(defaultLocaleFile, (error, stats) => {
|
|
|
|
if (error)
|
2017-08-31 14:11:37 +00:00
|
|
|
return cb({status: 'REJECT', data: {message: 'Translation not found for template ' + template + '.'}});
|
|
|
|
|
|
|
|
cb({status: 'ACCEPT', data: {locale: require(defaultLocaleFile)}});
|
2017-06-07 13:28:42 +00:00
|
|
|
});
|
2017-08-31 14:11:37 +00:00
|
|
|
} else {
|
|
|
|
cb({status: 'ACCEPT', data: {locale: require(localeFile)}});
|
|
|
|
}
|
2017-06-07 13:28:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|