Skip to content

Latest commit

 

History

History
52 lines (39 loc) · 980 Bytes

README-generated.textile

File metadata and controls

52 lines (39 loc) · 980 Bytes

Generating modules

The new module gettext_generated is used like this:

1> gettext_generate:compile(se, "swedish.po").
{module,se}
2> gettext_generate:compile(es, "spanish.po").
{module,es}

This generated two modules, called se and es, from gettext dot-po files.

Lets say you have an application with text you want translated.

-module(example).
-export([run/0]).

gettext(Atom) ->
    case get(i18n_module) of
      undefined ->
       atom_to_list(Atom);
      Mod ->
       Mod:gettext(Atom)
    end.

run() ->
    io:format("~s~n", [gettext('Hello World')]).

When you run example:run() you want the translated string out.

13> put(i18n_module, se), example:run().
Hej V\344rld
ok
14> put(i18n_module, es), example:run().
Hola Mundo
ok

And of course, if you have no module set, it will fall back on converting the atom text to string directly.

16> erase(i18n_module), example:run().  
Hello World
ok

Voila!