27 lines
1020 B
JavaScript
27 lines
1020 B
JavaScript
var fs = require('fs');
|
|
var settings = require('./settings.js');
|
|
var path = require('path');
|
|
|
|
module.exports = {
|
|
/**
|
|
* Devuelve las claves de idioma de una plantilla
|
|
* @param {String} template - Nombre de la plantilla
|
|
* @param {String} countryCode - Código de idioma
|
|
* @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) => {
|
|
if (error)
|
|
fs.stat(defaultLocaleFile, (error, stats) => {
|
|
if (error)
|
|
cb(null, 'Translation not found for template ' + template + '.');
|
|
return cb(require(defaultLocaleFile));
|
|
});
|
|
return cb(require(localeFile));
|
|
});
|
|
}
|
|
};
|