Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
[].concat(config.language || []).forEach(lang => {
let data;
let file = path.join(__dirname, '..', 'languages', lang + '.mo');
try {
data = gettextParser.mo.parse(fs.readFileSync(file));
} catch (E) {
// ignore
}
if (data) {
gt.addTranslations(lang, lang, data);
gt.setTextDomain(lang);
gt.setLocale(lang);
log.info('LANG', 'Loaded language file for %s', lang);
}
});
export function loadFile(filepath) {
const fileContent = fs.readFileSync(filepath);
if (path.extname(filepath) === '.mo') {
return gParser.mo.parse(fileContent);
}
if (path.extname(filepath) === '.po') {
return gParser.po.parse(fileContent);
}
throw new Error(`Unsupported filetype ${filepath}`);
}
function loadTextdomainDirectory(gt, locale, domain, modir) {
assert(fs.existsSync(modir));
let split = locale.split(/[-_.@]/);
let mo = modir + '/' + split.join('_') + '.mo';
while (!fs.existsSync(mo) && split.length) {
split.pop();
mo = modir + '/' + split.join('_') + '.mo';
}
if (split.length === 0) {
console.error(`No translations found in ${domain} for locale ${locale}`);
return;
}
try {
let loaded = gettextParser.mo.parse(fs.readFileSync(mo), 'utf-8');
gt.addTranslations(locale, domain, loaded);
} catch(e) {
console.log(`Failed to load translations for ${locale}/${domain}: ${e.message}`);
}
}
function addTranslation(language) {
let mo = gettextParser.mo.parse(fs.readFileSync('./po/server/'+language+'.mo'));
gt.addTranslations(language, 'messages', mo);
}
function i18nextToMo(locale, body, options = {}) {
return i18nextToGettext(locale, body, GettextParser.mo, identity, options);
}
var f = function(err, data) {
var res = (path.extname(target) === '.po' || path.extname(target) === '.pot') ? GettextParser.po.compile(data) : GettextParser.mo.compile(data);
callback(err, res);
};
if (options.base) {
var fs = require('fs');
var path = require('path');
var Gettext = require('node-gettext');
var moParser = require('gettext-parser').mo;
const extLocaleDir = path.join(__dirname + '/../locale');
const translationsDir = (fs.existsSync(extLocaleDir)) ? extLocaleDir : '/usr/share/locale';
const domain = 'cast-to-tv';
var gt = new Gettext();
exports.locales = [];
exports.initTranslations = function()
{
gt.setTextDomain(domain);
exports.locales = fs.readdirSync(translationsDir);
exports.locales.forEach(locale =>
{