Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 48 lines (36 sloc) 2.168 kb
48fea22 Implement "trans" tag with support for .po files
Evan Miller authored
1 Generate gettext infrastructure
2 -------------------------------
3
4 Erlydtl allows templates to use i18n features based on gettext. Standard po
5 files can be used to generate i18ized templates. A template parser/po generator
6 is also provided.
7
8 1. In order to enable i18n you first, you'll need gettext library to be
9 available on your lib_path.
10
11 Library can be downloaded from http://github.com/noss/erlang-gettext
12
13 2. Then you'll need to add a parse target on your makefile (or the script
14 used to trigger template reparsing) trans:
15
16 erl -pa ./ebin ./deps/*/ebin -noshell -s reloader -run i18n_manager \
17 generate_pos "en,es" "./views/*/*.html,./views/*.html"
18 rm -rf $(GETTEXT_DIR)/lang/default-old
19 mv $(GETTEXT_DIR)/lang/default $(GETTEXT_DIR)/lang/default-old
20 cp -rf $(GETTEXT_DIR)/lang/$(GETTEXT_TMP_NAME) $(GETTEXT_DIR)/lang/default
21 rm -rf $(GETTEXT_DIR)/lang/$(GETTEXT_TMP_NAME)/*
22
23 Mind that GETTEXT_DIR and GETTEXT_TMP_NAME must be bound to existing
24 directories. Args passed to i18n_manager:generate_pos are locales that
25 will be supported (generating dir structure and po files) and
26 directories where generator will search for template files including
27 trans tags.
28
29 3. Before template parsing gettext server must be running and it must be
30 populated with the content of the po files. Consider adding this
31 snipplet to the code before template parsing
32
33 gettext_server:start(),
34 LoadPo =
35 fun(Lang)->
36 {_, Bin} = file:read_file("./lang/default/"++ Lang ++"/gettext.po"),
37 gettext:store_pofile(Lang, Bin)
38 end,
39 lists:map(LoadPo, ["es","en"]).
40
41 Here locales are the codes are provided to gettext. Those codes must be
42 a subset of the locales provided to po generation process.
43
44 4. Update strings. Edit po files on $(GETTEXT_DIR)/lang/default/$(LOCALE)/gettext.po
45 translating msgstr to the translated version of their corresponding msgstr.
46
47 5. Generate localized templates providing locale compile option.
Something went wrong with that request. Please try again.