alexanderwallin / node-gettext

A JavaScript implementation of gettext, a localization framework.
Other
188 stars 37 forks source link

Emit notifications about missing translations #23

Closed ArmorDarks closed 7 years ago

ArmorDarks commented 9 years ago

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!

ArmorDarks commented 8 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...

andris9 commented 8 years ago

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.

alexanderwallin commented 7 years ago

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')
ArmorDarks commented 7 years ago

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.

alexanderwallin commented 7 years ago

Errors are now being emitted in 2.0.0-rc.0.

ArmorDarks commented 7 years ago

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.

ArmorDarks commented 7 years ago

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.

alexanderwallin commented 7 years ago

mitt is nice, but it's all so simple anyways. If we want to support * handlers, we might utilise it.