GithubHelp home page GithubHelp logo

Comments (6)

eemeli avatar eemeli commented on June 2, 2024

Could you provide a full minimal example of what triggers this error? It's really rather hard to diagnose with just that.

from gettext-to-messageformat.

Eutrepe avatar Eutrepe commented on June 2, 2024
const FS = require('fs');
const MessageFormat = require('@messageformat/core');

// i18n START
const Lang: string = 'en'; // for demo hardcoded
const EscStr = '&-p-&';
let i18n: any = {};
if (Lang) {
  const poFile = `i18n/${Lang}.po`;
  try {
    let po = FS.readFileSync(poFile, 'utf8');

    const { parsePo } = require('gettext-to-messageformat');
    const { headers, pluralFunction, translations } = parsePo(po.replace(/%(?![s|n|1])/g, EscStr));
    const mf = new MessageFormat('en', { [headers.language]: pluralFunction });
    i18n = mf.compile(translations); 
  } catch (e: any) {
    console.error(e);
  }
}
// i18n END

from gettext-to-messageformat.

eemeli avatar eemeli commented on June 2, 2024

@Eutrepe Could you also share at least a partial .po file that triggers this error?

from gettext-to-messageformat.

Eutrepe avatar Eutrepe commented on June 2, 2024

Yes, of course

msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"X-Generator: Poedit 2.4.2\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language: en\n"

msgid "test"
msgstr "Test text"

from gettext-to-messageformat.

eemeli avatar eemeli commented on June 2, 2024

Ah, you're calling the wrong function, mf.compile(...) rather than compileModule(mf, ...). This API change was a part of the v3 release, see here for update instructions: https://github.com/messageformat/messageformat/releases/tag/messageformat%403.0.0-beta.1

from gettext-to-messageformat.

Eutrepe avatar Eutrepe commented on June 2, 2024

Thank you, I checked today, sorry for the inconvenience. Everything is fine with your plugin

from gettext-to-messageformat.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.