Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse transform for extracting strings #3

Open
zuiderkwast opened this issue May 22, 2014 · 2 comments
Open

Parse transform for extracting strings #3

zuiderkwast opened this issue May 22, 2014 · 2 comments

Comments

@zuiderkwast
Copy link

The other gettext repo https://github.com/etnt/gettext has a parse transform for extracting strings (i.e. the job of xgettext). This could be more or less easily ported to gettexter. Then, it would be fairly easy to add support for binaries ?_(<<"foo">>) and handle Erlang-specific string syntax better than xgettext, s.t. adjacent string literals ?_("string" "42") and odd Erlang-specific escape sequences ?_("\x{128525}") (the 😍 symbol).

We are willing to implement this. Hopefully you'll be interested to merge a pull request in the following days or weeks....

@seriyps
Copy link
Owner

seriyps commented May 22, 2014

Yeah, I'll merge this, while still think it's not very good idea, since it requires some ".po" file writer as well. But, at the same time, I have no better solution.

I think it should be implemented not as parse transform, but by walking a tree(s), generated by combination of http://www.erlang.org/doc/man/erl_scan.html and http://www.erlang.org/doc/man/erl_parse.html (which is pretty common to parse_transform, but much more flexible), and be accessible not only as library, but also from command line (eg, bin/exgettext escript or so).

Plus it should be possible to extract messages not only to .po file, but as plain list of erlang terms (see how it's done in erlydtl https://github.com/erlydtl/erlydtl/blob/master/src/i18n/sources_parser.erl - it return a list of #phrase{}, which then may be converted to .po file or may be written to database or anything else).

Maybe we should have 2 different modules: one for phrase extraction and one for generating .po file from list of phrases - this way it may be used in ErlyDTL too.

@ghost
Copy link

ghost commented May 23, 2014

I've started to port the parse transform from etnt/gettext. It isn't well tested yet. I see what you mean that one should separate the compilation and extraction. But since all the parse_transform does is traversing the AST and dumping entries on the way it should be rather easy to adapt the code I've written so far to use with erl_scan/erl_parse. I'll check into that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants