forked from ChicagoBoss/ChicagoBoss
-
Notifications
You must be signed in to change notification settings - Fork 0
Internationalization
kotedo edited this page May 4, 2012
·
5 revisions
First, create your base application. Good, now create the files for the languages you want to support.
Example: German and English
Create two files in priv/lang and name them
- strings.de.po
- strings.en.po
The content of the file strings.de.po is fairly simple and straight forward:
msgid "firstname"
msgstr "Vorname"
msgid "lastname"
msgstr "Nachname"
msgid "street"
msgstr "Strasse"
msgid "List of Employees"
msgstr "Liste aller Angestellten"
msgid "Create a new Employee"
msgstr "Neuen Angestellten anlegen"
Then create the second one, name it strings.en.po and add these values to it:
msgid "firstname"
msgstr "Firstname"
msgid "lastname"
msgstr "Lastname"
msgid "street"
msgstr "Address"
msgid "List of Employees"
msgstr "List of all Employees"
msgid "Create a new Employee"
msgstr "Create a new Employee"
Almost done. Now create a view file that references the texts in the translation files:
{% trans "firstname" %} {% trans "lastname" %}
{% trans "List of Employees"%}
{% trans "Create a new Employee" %}
<a href="/english">English</a>
<a href="/german">German</a>
Final step: Set the language in the view
-module(cbatest_main_controller, [Req, SessionID]).
-compile([export_all]).
index('GET', []) ->
{ok, [], [{"Content-Language", boss_session:get_session_data(SessionID, locale)}]}.
english('GET', []) ->
boss_session:set_session_data(SessionID, locale, "en"),
{redirect, [{action, "index"}]}.
german('GET', []) ->
boss_session:set_session_data(SessionID, locale, "de"),
{redirect, [{action, "index"}]}.
Should you use cb_admin in your application, then you can make use of the "Lang Center" section of cb_admin. It offers automatic translations into many languages at once. It might not always be the 100% correct (Google-)translation but at least it get you started.