Closed ArmorDarks closed 7 years ago
@andris9 I know that you don't have much time those days to support node-gettext
. Will you though accept any PRs, or you won't have time to review them neither?
Or maybe you'll recommend to switch to another l10n library and depreciate node-gettext
? Since well... there were no updates for quite a while and it seems to be dead...
Yeah, node-gettext and gettext-parser are more or less abandoned by now. I'm willing to give these over to anyone who is willing to maintain them.
In v2
there will be a withGettextEvents(Gettext)
enhancer that you can use to do whatever you want with errors occurring inside Gettext
.
Usage would look something like this:
import Gettext from 'node-gettext'
import withGettextEvents from 'node-gettext/events'
import allTranslations from './translations.js'
const GettextWithEvents = withGettextEvents(Gettext)
// Configure a Gettext instance
const gt = new GettextWithEvents()
for (const locale in allTranslations) {
gt.addTranslations(locale, 'messages', allTranslations[locale])
}
gt.setLocale('en-EN')
// Listen for 'error' events
gt.on('error', error => { /* do something with the error */ })
gt.once('error', error => { /* react only once to errors */ })
// gt will now emit an 'error' event
gt.gettext('An unrecognized message')
I think general approach is quite nice.
However, I slightly dislike withGettextEvents
— does events makes code indeed much heavier and slower, that we need to make it as an enhancer instead of an option?
Also, will on error
work well everywhere? Maybe it should be replaced with more specific on missing
, since we might get real errors
in future, and we'll end up with mixed true errors
and alerts about missing strings.
Errors are now being emitted in 2.0.0-rc.0
.
Yeah, I saw that when switched to upcoming 2.0.0 branch, though, didn't have time to check how it was implemented.
So, you decided to ditch out withGettextEvents
and integrate emitters natively? If so, that's great. You've made node-gettext
great again 👍 .
I think we can close this issue then.
Just as a side note, maybe it worth add mitt as event emitter. I compared current emitter code, at it seems to be very similar, but mitt have few nice features and maintained by other community (so that we can less care about supporting emitters part in node-gettext
). Just saying.
mitt
is nice, but it's all so simple anyways. If we want to support *
handlers, we might utilise it.
It seems to be no way to catch any error or warnings when requested string is absent in specified language, or in default language, when it fallbacks to original string.
It would be much more helpful to know when something is missing.
Thanks in advance!