zaach / jsxgettext

Extract gettext calls from JavaScript, EJS, and other template formats.
Mozilla Public License 2.0
105 stars 56 forks source link

Support custom function names #93

Open ArmorDarks opened 9 years ago

ArmorDarks commented 9 years ago

Some projects uses another gettext function names, like, _t() for singular forms and _pt() for plurals, etc.

Is there any chances to see ability pass to jsxgettext object which will map custom function names to gettext(), ngettext() and so on?

grunt-xgettext partially implemented that feature, maybe something can be learned from it. Besides, there were issue about even further expending of that feature: https://github.com/arendjr/grunt-xgettext/issues/8

BYK commented 9 years ago

Haha, this is what I feared when we hard-coded the n prefix. I believe this is doable, just requires some more effort.

I'll try to get to this soon.

BYK commented 9 years ago

//cc @vrouet

ArmorDarks commented 9 years ago

Thanks a lot! :)

Well, in fact some libraries even use another position of arguments. Some going even further and providing chaining (like Jed).

But I guess ability to remap arguments, or define somehow completely custom function would be too hard task. grunt-xgettext tried to implement it, but, unfortunately, they didn't advance much further than just discussion.

BYK commented 9 years ago

Well, in fact some libraries even use another position of arguments. Some going even further and providing chaining (like Jed).

I think the promise of jsxgettext is to support GNU gettext interface as closely as possible. Anything non-standard should not make it into the core package. I even hate the custom template parsers but that needs a larger refactor.

ArmorDarks commented 9 years ago

I think the promise of jsxgettext is to support GNU gettext interface as closely as possible. Anything non-standard should not make it into the core package.

yeah, I completely agree

ArmorDarks commented 9 years ago

Maybe we can support it with regex?

Users which would need only basic functionality could map each function to custom name just with object and strings inside, but if someone will need something custom — regex to the rescue with named regex groups.

For sure we won't provide ready regex for non-trivial systems, like Jed, out of box.

For simpler cases we can also map arguments based on user's input. Here are some thought about it: https://github.com/arendjr/grunt-xgettext/issues/8

ArmorDarks commented 9 years ago

For the informations: native xgettext provides quite flexible way to set custom functions names and map arguments: http://poedit.net/trac/wiki/Doc/Keywords