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
1 changed files with 48 additions and 27 deletions

View File

@ -76,33 +76,54 @@ 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),
Trans1 = case Trans of load_file_loop(Fd, 1, File, Lang),
<<"">> -> Orig; file:close(Fd);
_ -> Trans Error ->
end, ExitText = iolist_to_binary([File, ": ",
ets:insert(translations, file:format_error(Error)]),
{{Lang, iolist_to_binary(Orig)}, ?ERROR_MSG("Problem loading translation file ~n~s",
iolist_to_binary(Trans1)}) [ExitText]),
end, exit(ExitText)
Terms); end.
%% Code copied from ejabberd_config.erl
{error, load_file_loop(Fd, Line, File, Lang) ->
{_LineNumber, erl_parse, _ParseMessage} = Reason} -> case io:read(Fd, '', Line) of
ExitText = iolist_to_binary([File, {ok,{Orig, Trans}, NextLine} ->
" approximately in the line ", Trans1 = case Trans of
file:format_error(Reason)]), <<"">> -> Orig;
?ERROR_MSG("Problem loading translation file ~n~s", _ -> Trans
[ExitText]), end,
exit(ExitText); ets:insert(translations,
{error, Reason} -> {{Lang, iolist_to_binary(Orig)},
ExitText = iolist_to_binary([File, ": ", iolist_to_binary(Trans1)}),
file:format_error(Reason)]),
?ERROR_MSG("Problem loading translation file ~n~s", load_file_loop(Fd, NextLine, File, Lang);
[ExitText]), {ok,_, _NextLine} ->
exit(ExitText) ExitText = iolist_to_binary([File,
" approximately in the line ",
Line]),
?ERROR_MSG("Problem loading translation file ~n~s",
[ExitText]),
exit(ExitText);
{error,
{_LineNumber, erl_parse, _ParseMessage} = Reason} ->
ExitText = iolist_to_binary([File,
" approximately in the line ",
file:format_error(Reason)]),
?ERROR_MSG("Problem loading translation file ~n~s",
[ExitText]),
exit(ExitText);
{error, Reason} ->
ExitText = iolist_to_binary([File, ": ",
file:format_error(Reason)]),
?ERROR_MSG("Problem loading translation file ~n~s",
[ExitText]),
exit(ExitText);
{eof,_Line} ->
ok
end. end.
-spec translate(binary(), binary()) -> binary(). -spec translate(binary(), binary()) -> binary().