bholloway / react-i18n-interpolation

String interpolation of translated text and react components
MIT License
1 stars 2 forks source link

Take whole instance of gettext instead of separate functions #5

Closed nkbt closed 7 years ago

nkbt commented 7 years ago

For example node-gettext.

I would expect factory to work somewhat like:

{
  gettext: gettextFactory({gettext: nodeGettext}),
  ngettext: ngettextFactory({gettext: nodeGettext})
}

Currently passing separate function require to bind gettext instance or use lambdas like:

{
  gettext: gettextFactory({gettext: (...args) => nodeGettext.gettext(...args)}),
  ngettext: ngettextFactory({ngettext: (...args) => nodeGettext.ngettext(...args)})
}

Ideally I would expect something like:

const whatever = gettextFactory({gettext: nodeGettext});

console.log(whatever.gettext`Bla`);
console.log(whatever.ngettext(10)`One foo|{{count: 10}} foos`);
bholloway commented 7 years ago

Based on #10 this becomes

import {factory} from 'react-i18n-interpolation';

const whatever = factory({gettext: nodeGettext});
... // rest as above
nkbt commented 7 years ago

👍