mirror of
https://github.com/processone/ejabberd.git
synced 2024-06-26 22:35:31 +02:00
b542249f11
(thanks to Sergei Golovan) * src/translate.erl: Likewise * src/ejabberd_app.erl: Added "log_path" configuration parameter (thanks to Sergei Golovan) * src/**/Makefile.win32: Updated (thanks to Sergei Golovan) * src/**/*.c: Updated (thanks to Sergei Golovan) * src/configure.erl: Added writing of version to Makefile.inc (thanks to Sergei Golovan) * doc/guide.tex: Updated link to expat (thanks to Sergei Golovan) SVN Revision: 223
78 lines
1.6 KiB
Erlang
78 lines
1.6 KiB
Erlang
%%%----------------------------------------------------------------------
|
|
%%% File : translate.erl
|
|
%%% Author : Alexey Shchepin <alexey@sevcom.net>
|
|
%%% Purpose :
|
|
%%% Created : 6 Jan 2003 by Alexey Shchepin <alexey@sevcom.net>
|
|
%%% Id : $Id$
|
|
%%%----------------------------------------------------------------------
|
|
|
|
-module(translate).
|
|
-author('alexey@sevcom.net').
|
|
|
|
-export([start/0,
|
|
load_dir/1,
|
|
load_file/2,
|
|
translate/2]).
|
|
|
|
-include("ejabberd.hrl").
|
|
|
|
start() ->
|
|
ets:new(translations, [named_table, public]),
|
|
Dir =
|
|
case os:getenv("EJABBERD_MSGS_PATH") of
|
|
false ->
|
|
case code:lib_dir(ejabberd) of
|
|
{error, _} ->
|
|
?MSGS_DIR;
|
|
Path ->
|
|
filename:join([Path, "msgs"])
|
|
end;
|
|
Path ->
|
|
Path
|
|
end,
|
|
load_dir(Dir),
|
|
ok.
|
|
|
|
load_dir(Dir) ->
|
|
case file:list_dir(Dir) of
|
|
{ok, Files} ->
|
|
MsgFiles = lists:filter(
|
|
fun(FN) ->
|
|
case string:len(FN) > 4 of
|
|
true ->
|
|
string:substr(FN,
|
|
string:len(FN) - 3) == ".msg";
|
|
_ ->
|
|
false
|
|
end
|
|
end, Files),
|
|
lists:foreach(
|
|
fun(FN) ->
|
|
load_file(string:substr(FN, 1, string:len(FN) - 4),
|
|
Dir ++ "/" ++ FN)
|
|
end, MsgFiles),
|
|
ok;
|
|
{error, Reason} ->
|
|
?ERROR_MSG("~p", [Reason])
|
|
end.
|
|
|
|
load_file(Lang, File) ->
|
|
case file:consult(File) of
|
|
{ok, Terms} ->
|
|
lists:foreach(fun({Orig, Trans}) ->
|
|
ets:insert(translations,
|
|
{{Lang, Orig}, Trans})
|
|
end, Terms);
|
|
{error, Reason} ->
|
|
exit(file:format_error(Reason))
|
|
end.
|
|
|
|
translate(Lang, Msg) ->
|
|
case ets:lookup(translations, {Lang, Msg}) of
|
|
[{_, Trans}] ->
|
|
Trans;
|
|
_ ->
|
|
Msg
|
|
end.
|
|
|