How to use the gettext-parser.mo function in gettext-parser

To help you get started, we’ve selected a few gettext-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Mailtrain-org / mailtrain / lib / translate.js View on Github external
[].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);
    }
});
github ttag-org / ttag / tests / loader.js View on Github external
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}`);
}
github stanford-oval / almond-cloud / util / i18n.js View on Github external
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}`);
    }
}
github gadael / gadael / modules / gettext.js View on Github external
function addTranslation(language) {
        let mo = gettextParser.mo.parse(fs.readFileSync('./po/server/'+language+'.mo'));
        gt.addTranslations(language, 'messages', mo);
    }
github i18next / i18next-gettext-converter / src / lib / json2gettext.js View on Github external
function i18nextToMo(locale, body, options = {}) {
  return i18nextToGettext(locale, body, GettextParser.mo, identity, options);
}
github i18next / i18next-gettext-converter / lib / gettextWrapper.js View on Github external
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) {
github Rafostar / gnome-shell-extension-cast-to-tv / node_scripts / gettext.js View on Github external
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 =>
	{

gettext-parser

Parse and compile gettext po and mo files to/from json, nothing more, nothing less

MIT
Latest version published 9 months ago

Package Health Score

72 / 100
Full package analysis