wikimedia / banana-i18n

banana-i18n - Javascript Internationalization library
https://wikimedia.github.io/banana-i18n/
MIT License
80 stars 27 forks source link

add function to allow users to register their own parser hooks #46

Closed siddharthvp closed 3 years ago

siddharthvp commented 3 years ago

A simple contrived example would be:

Which makes

This can be used practically for a lot of purposes, particularly for operations that require some data to be available which can be fetched from the client script. For example on mediawiki sites, a client script could add a hook for formatting dates using the month names fetched from MediaWiki API.

Let me know what you think about this. Another less explicit way of allowing these hooks would be to export the BananaEmitter class, so that clients can directly modify its prototype.

siddharthvp commented 3 years ago

@santhoshtr any thoughts?

santhoshtr commented 3 years ago

This looks like a good idea to me. Your PR make sense too. This is more or less in alignment with the extend option available in jquery.i18n(https://github.com/wikimedia/jquery.i18n#extending-the-parser).

Could you please add some test too?

Also, documentation(README.md)

siddharthvp commented 3 years ago

Done: updated documentation (adapted from jquery-i18n documentation), added tests and typescript type.