How to use the i18next-conv.gettextToI18next function in i18next-conv

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 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 {

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