ttag-org / ttag

:orange_book: simple approach for javascript localization
https://ttag.js.org/
MIT License
345 stars 44 forks source link

ngettext definition not in resulting .po-file #200

Open aldipower opened 4 years ago

aldipower commented 4 years ago

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 commented 4 years ago

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.

AlexMost commented 4 years ago

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

aldipower commented 4 years ago

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.

AlexMost commented 4 years ago

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

aldipower commented 4 years ago

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

aldipower commented 4 years ago

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.