aboutsummaryrefslogtreecommitdiff
path: root/src/translate.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/translate.erl')
-rw-r--r--src/translate.erl82
1 files changed, 51 insertions, 31 deletions
diff --git a/src/translate.erl b/src/translate.erl
index 9dba065f9..846b33e06 100644
--- a/src/translate.erl
+++ b/src/translate.erl
@@ -17,10 +17,9 @@
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
-%%% You should have received a copy of the GNU General Public License
-%%% along with this program; if not, write to the Free Software
-%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-%%% 02111-1307 USA
+%%% You should have received a copy of the GNU General Public License along
+%%% with this program; if not, write to the Free Software Foundation, Inc.,
+%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
%%%
%%%----------------------------------------------------------------------
@@ -77,33 +76,54 @@ load_dir(Dir) ->
end.
load_file(Lang, File) ->
- case file:consult(File) of
- {ok, Terms} ->
- lists:foreach(fun ({Orig, Trans}) ->
- Trans1 = case Trans of
- <<"">> -> Orig;
- _ -> Trans
- end,
- ets:insert(translations,
- {{Lang, iolist_to_binary(Orig)},
- iolist_to_binary(Trans1)})
- end,
- Terms);
- %% Code copied from ejabberd_config.erl
- {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)
+ case file:open(File, [read]) of
+ {ok, Fd} ->
+ io:setopts(Fd, [{encoding,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
+ <<"">> -> Orig;
+ _ -> Trans
+ end,
+ ets:insert(translations,
+ {{Lang, iolist_to_binary(Orig)},
+ iolist_to_binary(Trans1)}),
+
+ load_file_loop(Fd, NextLine, File, Lang);
+ {ok,_, _NextLine} ->
+ 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.
-spec translate(binary(), binary()) -> binary().