Skip to content

Commit

Permalink
Remove get_stacktrace/0; update docs about locales location in priv/
Browse files Browse the repository at this point in the history
  • Loading branch information
seriyps committed Dec 19, 2022
1 parent e951cda commit 0ff7094
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Mark your translatable strings with:
-include_lib("gettexter/include/shortcuts.hrl").

main(Name, What, N) ->
gettexter:bindtextdomain(?GETTEXT_DOMAIN, "/../locales"), % from where load locales
gettexter:bindtextdomain(?GETTEXT_DOMAIN, "/../priv/locales"), % from where load locales
gettexter:textdomain(?GETTEXT_DOMAIN), % domain for current process
gettexter:setlocale(lc_messages, "en"), % locale for current process

Expand All @@ -58,7 +58,7 @@ that this only work for string literals and not binaries.
```bash
export APP=my_app

xgettext -o locale/${APP}.pot --package-name=${APP} -d ${APP} --sort-by-file -L C \
xgettext -o priv/locale/${APP}.pot --package-name=${APP} -d ${APP} --sort-by-file -L C \
--keyword='NO_' --keyword='_' --keyword='N_:1,2' \
--keyword='P_:1c,2' --keyword='NP_:1c,2,3' \
--keyword='D_:2' --keyword='DN_:2,3' --keyword='DP_:2c,3' --keyword='DNP_:2c,3,4' \
Expand All @@ -69,20 +69,20 @@ xgettext -o locale/${APP}.pot --package-name=${APP} -d ${APP} --sort-by-file -L
Initialize new locale's .po file by `msginit`

```bash
mkdir -p locale/ru/LC_MESSAGES/
msginit -i locale/${APP}.pot -o locale/ru/LC_MESSAGES/${APP}.po --locale=ru
mkdir -p priv/locale/ru/LC_MESSAGES/
msginit -i priv/locale/${APP}.pot -o priv/locale/ru/LC_MESSAGES/${APP}.po --locale=ru
```

Or actualize existing locale's .po file by `msgmerge`

```bash
msgmerge -U locale/ru/LC_MESSAGES/${APP}.po locale/${APP}.pot
msgmerge -U priv/locale/ru/LC_MESSAGES/${APP}.po priv/locale/${APP}.pot
```

When translations are finished, generate locale's binary .mo files by `msgfmt`

```bash
msgfmt --check -o locale/ru/LC_MESSAGES/${APP}.mo locale/ru/LC_MESSAGES/${APP}.po
msgfmt --check -o priv/locale/ru/LC_MESSAGES/${APP}.mo priv/locale/ru/LC_MESSAGES/${APP}.po
```
It's **strongly recommended** to not add .mo files to your repository! So, add
`*.mo` to .gitignore / .hgignore and generate them in compile-time (by rebar
Expand Down Expand Up @@ -264,7 +264,7 @@ Template:
```
.po file
```po
#file: locale/ru/LC_MESSAGES/test_app.po + compiled .mo
#file: priv/locale/ru/LC_MESSAGES/test_app.po + compiled .mo
msgid ""
msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
Expand Down
3 changes: 1 addition & 2 deletions src/gettexter.app.src
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{application, gettexter,
[
{description, "GNU gettext compatible translation library"},
{vsn, "0.0.6"},
{vsn, "0.0.7"},
{registered, []},
{applications, [
kernel,
Expand All @@ -10,7 +10,6 @@
{mod, { gettexter_app, []}},
{env, []},

{maintainers, ["Sergey Prokhorov"]},
{licenses, ["Apache 2.0"]},
{links, [{"Github", "https://github.com/seriyps/gettexter"}]}
]}.
3 changes: 1 addition & 2 deletions src/gettexter_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ handle_call({ensure_loaded, Domain, Locale}, _From, State) ->
false ->
try
load_locale(?TAB, Domain, Locale)
catch Type:Reason ->
catch Type:Reason:Trace ->
%% cleanup possible partial load
Trace = erlang:get_stacktrace(),
catch unload_locale(?TAB, Domain, Locale),
{error, {Type, Reason, Trace}}
end
Expand Down

0 comments on commit 0ff7094

Please sign in to comment.