]> granicus.if.org Git - ejabberd/commitdiff
*** empty log message ***
authorAlexey Shchepin <alexey@process-one.net>
Mon, 6 Jan 2003 19:57:05 +0000 (19:57 +0000)
committerAlexey Shchepin <alexey@process-one.net>
Mon, 6 Jan 2003 19:57:05 +0000 (19:57 +0000)
SVN Revision: 30

src/ejabberd.erl
src/ejabberd.hrl
src/mod_disco.erl
src/mod_offline.erl
src/mod_register.erl
src/mod_vcard.erl
src/msgs/ru.msg [new file with mode: 0644]
src/translate.erl [new file with mode: 0644]

index e560d79cfe3b5363a4f7b65d249ae5b73ec144c2..3e100a6a65c3fa432aa05855d1237d01c3b37d17 100644 (file)
@@ -22,6 +22,7 @@ init() ->
     Port = open_port({spawn, expat_erl}, [binary]),
     db_init(),
     sha:start(),
+    translate:start(),
     ejabberd_auth:start(),
     ejabberd_router:start(),
     ejabberd_sm:start(),
index 08f06e3fbf9ad65a56416a961fe76579dfc3d5bc..fa26180014dc669c3acdbd7f53338a23f2bbe437 100644 (file)
@@ -18,3 +18,5 @@
 
 -define(MYNAME,"e.localhost").
 
+-define(MSGS_DIR, "msgs").
+
index b49ef1be8d9c34369b38493e0474f8a7fc3cd427..4c05791ca58b070ccc18aaf1c428ee8c80d56b67 100644 (file)
@@ -46,6 +46,7 @@ register_feature(Feature) ->
     ets:insert(disco_features, {Feature}).
 
 process_local_iq_items(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
+    Lang = xml:get_tag_attr_s("xml:lang", SubEl),
     case Type of
        set ->
            {iq, ID, error, XMLNS, [SubEl, {xmlelement, "error",
@@ -64,11 +65,11 @@ process_local_iq_items(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
                       Domains ++
                       [{xmlelement, "item",
                         [{"jid", jlib:jid_to_string(To)},
-                         {"name", "Online Users"},
+                         {"name", translate:translate(Lang, "Online Users")},
                          {"node", "online users"}], []},
                        {xmlelement, "item",
                         [{"jid", jlib:jid_to_string(To)},
-                         {"name", "All Users"},
+                         {"name", translate:translate(Lang, "All Users")},
                          {"node", "all users"}], []}]
                      }]};
                "online users" ->
index e6d340f100f28234dcc3c31a16b2aea731fdda8b..a08e05a01496912fca3c419ae2e1c519095d008b 100644 (file)
@@ -3,6 +3,7 @@
 %%% Author  : Alexey Shchepin <alexey@sevcom.net>
 %%% Purpose : 
 %%% Created :  5 Jan 2003 by Alexey Shchepin <alexey@sevcom.net>
+%%% Id      : $Id$
 %%%----------------------------------------------------------------------
 
 -module(mod_offline).
index 457ca31fcb3a294810a7b306c24f80e4bc2ddea8..3f4c1c42e5b66f2a5b53c3fc559f9fdce9106523 100644 (file)
@@ -57,15 +57,15 @@ process_iq(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
                    end
            end;
        get ->
-           {iq, ID, error, XMLNS, [{xmlelement,
-                                    "query",
-                                    [{"xmlns", "jabber:iq:register"}],
-                                    [{xmlelement, "instructions", [],
-                                      {xmlcdata,
-                                       "Choose a username and password "
-                                       "to register with this server."}},
-                                     {xmlelement, "username", [], []},
-                                     {xmlelement, "password", [], []}]}]}
+           {iq, ID, result, XMLNS, [{xmlelement,
+                                     "query",
+                                     [{"xmlns", "jabber:iq:register"}],
+                                     [{xmlelement, "instructions", [],
+                                       [{xmlcdata,
+                                         "Choose a username and password "
+                                         "to register with this server."}]},
+                                      {xmlelement, "username", [], []},
+                                      {xmlelement, "password", [], []}]}]}
     end.
 
 
index 48a58c02ecaeb530af951e6af026f951a8e332ee..be88e9ccdfc95541a3ce685eb1bdef78dfd47848 100644 (file)
@@ -166,18 +166,19 @@ set_vcard(LUser, VCARD) ->
 
 -define(TLFIELD(Type, Label, Var),
        {xmlelement, "field", [{"type", Type},
-                              {"label", Label},
+                              {"label", translate:translate(Lang, Label)},
                               {"var", Var}], []}).
 
 
 -define(FORM,
        [{xmlelement, "instructions", [],
-         [{xmlcdata, "You need a x:data capable client to search"}]},
+         [{xmlcdata, translate:translate(Lang, "You need a x:data capable client to search")}]},
         {xmlelement, "x", [{"xmlns", ?NS_XDATA}, {"type", "form"}],
-         [{xmlelement, "title", [], [{xmlcdata, "Users Search"}]},
+         [{xmlelement, "title", [],
+           [{xmlcdata, translate:translate(Lang, "Users Search")}]},
           {xmlelement, "instructions", [],
-           [{xmlcdata, "Fill in fields to search "
-             "for any matching Jabber User"}]},
+           [{xmlcdata, translate:translate(Lang, "Fill in fields to search "
+                                           "for any matching Jabber User")}]},
           ?TLFIELD("text-single", "User", "user"),
           ?TLFIELD("text-single", "Full Name", "fn"),
           ?TLFIELD("text-single", "Name", "given"),
@@ -205,6 +206,7 @@ do_route(From, To, Packet) ->
            IQ = jlib:iq_query_info(Packet),
            case IQ of
                {iq, ID, Type, ?NS_SEARCH, SubEl} ->
+                   Lang = xml:get_tag_attr_s("xml:lang", SubEl),
                    case Type of
                        set ->
                            XDataEl = find_xdata_el(SubEl),
@@ -231,7 +233,7 @@ do_route(From, To, Packet) ->
                                                   [{xmlelement, "x",
                                                     [{"xmlns", ?NS_XDATA},
                                                      {"type", "result"}],
-                                                    search_result(XData)
+                                                    search_result(Lang, XData)
                                                    }]}]},
                                            ejabberd_router:route(
                                              To, From, jlib:iq_to_xml(ResIQ))
@@ -309,10 +311,12 @@ find_xdata_el1([_ | Els]) ->
     find_xdata_el1(Els).
 
 -define(LFIELD(Label, Var),
-       {xmlelement, "field", [{"label", Label}, {"var", Var}], []}).
+       {xmlelement, "field", [{"label", translate:translate(Lang, Label)},
+                              {"var", Var}], []}).
 
-search_result(Data) ->
-    [{xmlelement, "title", [], [{xmlcdata, "Users Search Results"}]},
+search_result(Lang, Data) ->
+    [{xmlelement, "title", [],
+      [{xmlcdata, translate:translate(Lang, "Users Search Results")}]},
      {xmlelement, "reported", [],
       [?LFIELD("JID", "jid"),
        ?LFIELD("Full Name", "fn"),
diff --git a/src/msgs/ru.msg b/src/msgs/ru.msg
new file mode 100644 (file)
index 0000000..27b837c
--- /dev/null
@@ -0,0 +1,32 @@
+% $Id$
+
+% mod_disco.erl
+{"Online Users", "Подключённые пользователи"}.
+{"All Users", "Все пользователи"}.
+
+
+% mod_vcard.erl
+{"You need a x:data capable client to search",
+ "Чтобы воспользоваться поиском, Вам нужен x:data-совместимый клиент"}.
+{"Users Search", "Поиск пользователей"}.
+{"Fill in fields to search for any matching Jabber User",
+ "Заполните поля для поиска пользователя Jabber"}.
+{"Users Search Results", "Результат поиска пользователей"}.
+
+{"User",              "Пользователь"}.
+{"Full Name",        "Полное имя"}.
+{"Name",             "Имя"}.
+{"Middle Name",       "Отчество"}.
+{"Family Name",       "Фамилия"}.
+{"Nickname",         "Псевдоним"}.
+{"Birthday",         "День рождения"}.
+{"Country",          "Страна"}.
+{"City",             "Город"}.
+{"email",            "email"}.
+{"Organization Name", "Название организации"}.
+{"Organization Unit", "Отдел организации"}.
+
+
+% Local Variables:
+% mode: erlang
+% End:
diff --git a/src/translate.erl b/src/translate.erl
new file mode 100644 (file)
index 0000000..0c6d49e
--- /dev/null
@@ -0,0 +1,62 @@
+%%%----------------------------------------------------------------------
+%%% 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]),
+    load_dir(?MSGS_DIR),
+    ok.
+
+load_dir(Dir) ->
+    {ok, Files} = file:list_dir(Dir),
+    MsgFiles = lists:filter(
+                fun(FN) ->
+                        string:substr(FN, string:len(FN) - 3) == ".msg"
+                end, Files),
+    lists:foreach(
+      fun(FN) ->
+             load_file(string:substr(FN, 1, string:len(FN) - 4),
+                       Dir ++ "/" ++ FN)
+      end, MsgFiles),
+    ok.
+
+load_file(Lang, File) ->
+    {ok, Bin} = file:read_file(File),
+    Content = binary_to_list(Bin),
+    parse(Lang, Content).
+
+
+parse(Lang, String) ->
+    case erl_scan:tokens([], String, 0) of
+       {done, Result, Left} ->
+           {ok, Tokens, _} = Result,
+           {ok, Term} = erl_parse:parse_term(Tokens),
+           {Orig, Trans} = Term,
+           ets:insert(translations, {{Lang, Orig}, Trans}),
+           parse(Lang, Left);
+       _ ->
+           ok
+    end.
+
+translate(Lang, Msg) ->
+    case ets:lookup(translations, {Lang, Msg}) of
+       [{_, Trans}] ->
+           Trans;
+       _ ->
+           Msg
+    end.
+