How to use i18next-conv - 7 common examples

To help you get started, we’ve selected a few i18next-conv 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 i18next / i18next-node / backends / gettext / sync.js View on Github external
fetchOne: function(lng, ns, callback) {
        var source = this.functions.applyReplacement(this.options.resGetPath, {lng: lng, ns: ns});

        var self = this;
        converter.addTextDomain(lng, source, {}, function(err, data) {
            // console.log(data);
            if (err) {
                callback(err);
                return;
            }

            converter.parseJSON(lng, data, {}, function(err, json) {
                if (err) {
                    callback(err);
                } else {
                    self.functions.log('loaded file: ' + source);
                    callback(null, json);
                }
            });
        });
    },
github i18next / i18next-node / backends / gettext / sync.js View on Github external
converter.addTextDomain(lng, source, {}, function(err, data) {
            // console.log(data);
            if (err) {
                callback(err);
                return;
            }

            converter.parseJSON(lng, data, {}, function(err, json) {
                if (err) {
                    callback(err);
                } else {
                    self.functions.log('loaded file: ' + source);
                    callback(null, json);
                }
            });
        });
    },
github queicherius / i18next-po-loader / index.js View on Github external
module.exports = function (source) {
  this.cacheable && this.cacheable()
  var callback = this.async()

  // Parse the language out of the file
  var language = source.match(/Language: ([\w]*)/)
  language = language ? language[1] : 'en'

  // Convert to i18next format (already stringified)
  converter.gettextToI18next(language, source, options).then(function (data) {
    callback(null, "module.exports = " + data + ";")
  })
}
github chialab / rna-cli / lib / Bundlers / plugins / rollup-plugin-po / rollup-plugin-po.js View on Github external
let translationId = path.join(
                lang,
                path.basename(id, '.po')
            );

            /**
             * Translation asset data.
             * @type {TranslationAsset}
             */
            let translation = this.translations[translationId] = this.translations[translationId] || {
                asset: this.emitAsset(`${translationId}.json`),
                data: {},
            };

            // convert .po file into JSON
            let json = await gettextToI18next(lang, fs.readFileSync(id));

            // merge with previous data
            translation.data = Object.assign({}, translation.data, JSON.parse(json));

            // just export the asset url
            return `export default import.meta.ROLLUP_ASSET_URL_${translation.asset};`;
        },
github locize / locize-cli / convertToFlatFormat.js View on Github external
const convertToFlatFormat = (opt, data, lng, cb) => {
  if (!cb) {
    cb = lng;
    lng = undefined;
  }
  try {
    if (opt.format === 'json' || opt.format === 'flat') {
      cb(null, flatten(JSON.parse(data.toString())));
      return;
    }
    if (opt.format === 'po' || opt.format === 'gettext') {
      try {
        gettextToI18next(opt.referenceLanguage, data.toString(), {
          persistMsgIdPlural: true,
          ignoreCtx: true
        }).then((ret) => {
          try {
            cb(null, flatten(JSON.parse(ret.toString())));
          } catch (err) {
            cb(err);
          }
        }, cb);
      } catch (err) {
        cb(err);
      }
      return;
    }
    if (opt.format === 'po_i18next' || opt.format === 'gettext_i18next') {
      try {
github locize / locize-cli / convertToDesiredFormat.js View on Github external
if (opt.format === 'flat') {
      cb(null, JSON.stringify(flatten(data), null, 2));
      return;
    }
    if (opt.format === 'po' || opt.format === 'gettext') {
      const flatData = flatten(data);

      const gettextOpt = {
        project: 'locize',
        language: lng,
        potCreationDate: lastModified,
        poRevisionDate: lastModified,
        ctxSeparator: '_ is default but we set it to something that is never found!!!',
        persistMsgIdPlural: true
      };
      i18nextToPo(lng, JSON.stringify(flatData), gettextOpt).then((ret) => {
        cb(null, ret.toString());
      }, cb);
      return;
    }
    if (opt.format === 'po_i18next' || opt.format === 'gettext_i18next') {
      i18nextToPo(lng, JSON.stringify(flatten(data)), {
        project: 'locize',
        language: lng,
        potCreationDate: lastModified,
        poRevisionDate: lastModified
      }).then((ret) => {
        cb(null, ret.toString());
      }, cb);
      return;
    }
    if (opt.format === 'csv') {
github locize / locize-cli / convertToDesiredFormat.js View on Github external
const gettextOpt = {
        project: 'locize',
        language: lng,
        potCreationDate: lastModified,
        poRevisionDate: lastModified,
        ctxSeparator: '_ is default but we set it to something that is never found!!!',
        persistMsgIdPlural: true
      };
      i18nextToPo(lng, JSON.stringify(flatData), gettextOpt).then((ret) => {
        cb(null, ret.toString());
      }, cb);
      return;
    }
    if (opt.format === 'po_i18next' || opt.format === 'gettext_i18next') {
      i18nextToPo(lng, JSON.stringify(flatten(data)), {
        project: 'locize',
        language: lng,
        potCreationDate: lastModified,
        poRevisionDate: lastModified
      }).then((ret) => {
        cb(null, ret.toString());
      }, cb);
      return;
    }
    if (opt.format === 'csv') {
      opt.getNamespace(opt, opt.referenceLanguage, namespace, (err, refNs) => {
        if (err) return cb(err);

        const js2CsvData = Object.keys(flatten(data)).reduce((mem, k) => {
          const value = data[k] || '';
          const line = {

i18next-conv

converts .mo and .po files to i18next's json format and vice versa.

MIT
Latest version published 6 months ago

Package Health Score

71 / 100
Full package analysis