ttag icon indicating copy to clipboard operation
ttag copied to clipboard

ngettext definition not in resulting .po-file

Open aldipower opened this issue 4 years ago • 6 comments

Hi,

I have the following code-block in my application, which is not detected by the parser and thus not included in the resulting .po-file:

import { ngettext, msgid } from 'ttag.macro';

export const timespanTypePluralNameFunc = {
  [TimespanType.WEEK]: count => ngettext(msgid`Woche`, `Wochen`, count),
  [TimespanType.MONTH]: count => ngettext(msgid`Monat`, `Monate`, count),
  [TimespanType.YEAR]: count => ngettext(msgid`Jahr`, `Jahre`, count),
};

Other functions with ngettext are working perfectly fine, f.ex. this is included and working:

  import { ngettext, msgid } from 'ttag.macro';

  getDaysLine() {
    const { days = 0 } = this.props.entry;

    return (
      <span>
        {days} {ngettext(msgid`Tag`, `Tage`, days)}
      </span>
    );
  }

Maybe it's not a bug and I do not understand the upper scope correctly? It is really unexpected anyway.


Acutally it is include in the .po file, but only as singular form:

#: src/maps/index.js:75
msgid "Woche"
msgstr "Woche"

aldipower avatar May 26 '20 10:05 aldipower

OK, the problem is that I already defined a singular definition of "Woche" somewhere else.

export const timespanTypeNameMap = {
  [TimespanType.WEEK]: t`Woche`,
}

So this seems to be conflicting then and the latter 'ngettext' gets ignored without warning..


Ok, sorry to be overhasty, this wasn't the problem. Even if I remove the singular variants, the plural still does not show up.

aldipower avatar May 26 '20 10:05 aldipower

Hi @aldipower! Seems like a bug, need to check that. Let's clarify the reproduce case. If I've got your point, this code block is not extracted by ttag-cli:

import { ngettext, msgid } from 'ttag.macro';

export const timespanTypePluralNameFunc = {
  [TimespanType.WEEK]: count => ngettext(msgid`Woche`, `Wochen`, count),
  [TimespanType.MONTH]: count => ngettext(msgid`Monat`, `Monate`, count),
  [TimespanType.YEAR]: count => ngettext(msgid`Jahr`, `Jahre`, count),
};

It's CRA? You can also try to add --discover option to ttag-cli. https://github.com/ttag-org/ttag-cli#update-opts-pofile-src

AlexMost avatar May 26 '20 11:05 AlexMost

Hi @AlexMost !

Yes, it's CRA with ttag.macro.

Exactly, the above code block isn't extracted and does not show up in the .po. Interesstingly, when I change

[TimespanType.WEEK]: count => ngettext(msgid`Woche`, `Wochen`, count),

to

[TimespanType.WEEK]: count => ngettext(msgid`WocheTEST`, `WochenTEST`, count),

it shows up as expected.

When I run it with --discover ngettext it doesn't make any difference.

aldipower avatar May 26 '20 14:05 aldipower

Hm, that sound's interesting. I will appreciate if you could create some example repo. That would simplify the reproduce case for me.

AlexMost avatar May 26 '20 14:05 AlexMost

Yes, let me try to reproduce it in a clean repo. Please hold the line. ;) Could take me a while..

aldipower avatar May 26 '20 14:05 aldipower

Ok @AlexMost, that was easy to reproduce.

https://github.com/aldipower/ttag-test

Plural forms of src/test-map/index.js should show up in i18n/en.po after running npm run i18n-update, but the do not.

aldipower avatar May 26 '20 14:05 aldipower