Fork me on GitHub

Erlang gettext hack

2009-04-14

I set out to improve gettext i18n in Erlang tonight. Given the erlang constant pool being optimized so that it returns references into it rather than “consing” a duplicate copy… do you see where this is going?

My result so far is just a proof of concept, too early to be released really. I just want to spread the word and show what the concept is:

  1. Parse gettext “.po” file
  2. Generate erlang module that exports Mod:gettext/1, taking an atom, returning a string.
  3. Compile said module
  4. Use I18N:gettext('Hello World') in source, but probably as ?_('Hello World') or ?__(I18N, 'Hello World'). The existing code uses the process dictionary to store the I18N table to use, and so can I.

I’ll get back when I have better code generation. Perhaps generating AST and compiling down to a .beam directly. Right now it generates source text and doesnt even escape strings.

Oh yeah, and a link: noss/erlang-gettext @ github