README_I18N 2.1 KB

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