24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-02 21:17:12 +02:00

Fix loading translation files on R17

This commit is contained in:
Paweł Chmielowski 2014-04-15 16:16:12 +02:00 committed by Badlop
parent f93758a3cd
commit d97b4fd9ca

View File

@ -76,19 +76,38 @@ load_dir(Dir) ->
end. end.
load_file(Lang, File) -> load_file(Lang, File) ->
case file:consult(File) of case file:open(File, [read]) of
{ok, Terms} -> {ok, Fd} ->
lists:foreach(fun ({Orig, Trans}) -> epp:set_encoding(Fd, latin1),
load_file_loop(Fd, 1, File, Lang),
file:close(Fd);
Error ->
ExitText = iolist_to_binary([File, ": ",
file:format_error(Error)]),
?ERROR_MSG("Problem loading translation file ~n~s",
[ExitText]),
exit(ExitText)
end.
load_file_loop(Fd, Line, File, Lang) ->
case io:read(Fd, '', Line) of
{ok,{Orig, Trans}, NextLine} ->
Trans1 = case Trans of Trans1 = case Trans of
<<"">> -> Orig; <<"">> -> Orig;
_ -> Trans _ -> Trans
end, end,
ets:insert(translations, ets:insert(translations,
{{Lang, iolist_to_binary(Orig)}, {{Lang, iolist_to_binary(Orig)},
iolist_to_binary(Trans1)}) iolist_to_binary(Trans1)}),
end,
Terms); load_file_loop(Fd, NextLine, File, Lang);
%% Code copied from ejabberd_config.erl {ok,_, _NextLine} ->
ExitText = iolist_to_binary([File,
" approximately in the line ",
Line]),
?ERROR_MSG("Problem loading translation file ~n~s",
[ExitText]),
exit(ExitText);
{error, {error,
{_LineNumber, erl_parse, _ParseMessage} = Reason} -> {_LineNumber, erl_parse, _ParseMessage} = Reason} ->
ExitText = iolist_to_binary([File, ExitText = iolist_to_binary([File,
@ -102,7 +121,9 @@ load_file(Lang, File) ->
file:format_error(Reason)]), file:format_error(Reason)]),
?ERROR_MSG("Problem loading translation file ~n~s", ?ERROR_MSG("Problem loading translation file ~n~s",
[ExitText]), [ExitText]),
exit(ExitText) exit(ExitText);
{eof,_Line} ->
ok
end. end.
-spec translate(binary(), binary()) -> binary(). -spec translate(binary(), binary()) -> binary().