mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-20 16:15:59 +01:00
Replace translate:mark/1 with ?T() macro
This commit is contained in:
parent
48f2adde98
commit
adfb924808
1
include/translate.hrl
Normal file
1
include/translate.hrl
Normal file
@ -0,0 +1 @@
|
|||||||
|
-define(T(S), <<S>>).
|
@ -42,6 +42,7 @@
|
|||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
-include("eldap.hrl").
|
-include("eldap.hrl").
|
||||||
-include("xmpp.hrl").
|
-include("xmpp.hrl").
|
||||||
|
-include("translate.hrl").
|
||||||
|
|
||||||
-define(PROCNAME, ejabberd_mod_vcard_ldap).
|
-define(PROCNAME, ejabberd_mod_vcard_ldap).
|
||||||
|
|
||||||
@ -324,31 +325,31 @@ default_vcard_map() ->
|
|||||||
{<<"PHOTO">>, <<"%s">>, [<<"jpegPhoto">>]}].
|
{<<"PHOTO">>, <<"%s">>, [<<"jpegPhoto">>]}].
|
||||||
|
|
||||||
default_search_fields() ->
|
default_search_fields() ->
|
||||||
[{translate:mark(<<"User">>), <<"%u">>},
|
[{?T("User"), <<"%u">>},
|
||||||
{translate:mark(<<"Full Name">>), <<"displayName">>},
|
{?T("Full Name"), <<"displayName">>},
|
||||||
{translate:mark(<<"Given Name">>), <<"givenName">>},
|
{?T("Given Name"), <<"givenName">>},
|
||||||
{translate:mark(<<"Middle Name">>), <<"initials">>},
|
{?T("Middle Name"), <<"initials">>},
|
||||||
{translate:mark(<<"Family Name">>), <<"sn">>},
|
{?T("Family Name"), <<"sn">>},
|
||||||
{translate:mark(<<"Nickname">>), <<"%u">>},
|
{?T("Nickname"), <<"%u">>},
|
||||||
{translate:mark(<<"Birthday">>), <<"birthDay">>},
|
{?T("Birthday"), <<"birthDay">>},
|
||||||
{translate:mark(<<"Country">>), <<"c">>},
|
{?T("Country"), <<"c">>},
|
||||||
{translate:mark(<<"City">>), <<"l">>},
|
{?T("City"), <<"l">>},
|
||||||
{translate:mark(<<"Email">>), <<"mail">>},
|
{?T("Email"), <<"mail">>},
|
||||||
{translate:mark(<<"Organization Name">>), <<"o">>},
|
{?T("Organization Name"), <<"o">>},
|
||||||
{translate:mark(<<"Organization Unit">>), <<"ou">>}].
|
{?T("Organization Unit"), <<"ou">>}].
|
||||||
|
|
||||||
default_search_reported() ->
|
default_search_reported() ->
|
||||||
[{translate:mark(<<"Full Name">>), <<"FN">>},
|
[{?T("Full Name"), <<"FN">>},
|
||||||
{translate:mark(<<"Given Name">>), <<"FIRST">>},
|
{?T("Given Name"), <<"FIRST">>},
|
||||||
{translate:mark(<<"Middle Name">>), <<"MIDDLE">>},
|
{?T("Middle Name"), <<"MIDDLE">>},
|
||||||
{translate:mark(<<"Family Name">>), <<"LAST">>},
|
{?T("Family Name"), <<"LAST">>},
|
||||||
{translate:mark(<<"Nickname">>), <<"NICK">>},
|
{?T("Nickname"), <<"NICK">>},
|
||||||
{translate:mark(<<"Birthday">>), <<"BDAY">>},
|
{?T("Birthday"), <<"BDAY">>},
|
||||||
{translate:mark(<<"Country">>), <<"CTRY">>},
|
{?T("Country"), <<"CTRY">>},
|
||||||
{translate:mark(<<"City">>), <<"LOCALITY">>},
|
{?T("City"), <<"LOCALITY">>},
|
||||||
{translate:mark(<<"Email">>), <<"EMAIL">>},
|
{?T("Email"), <<"EMAIL">>},
|
||||||
{translate:mark(<<"Organization Name">>), <<"ORGNAME">>},
|
{?T("Organization Name"), <<"ORGNAME">>},
|
||||||
{translate:mark(<<"Organization Unit">>), <<"ORGUNIT">>}].
|
{?T("Organization Unit"), <<"ORGUNIT">>}].
|
||||||
|
|
||||||
parse_options(Host, Opts) ->
|
parse_options(Host, Opts) ->
|
||||||
MyHosts = gen_mod:get_opt_hosts(Host, Opts, <<"vjud.@HOST@">>),
|
MyHosts = gen_mod:get_opt_hosts(Host, Opts, <<"vjud.@HOST@">>),
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
-include("xmpp.hrl").
|
-include("xmpp.hrl").
|
||||||
-include("mod_vcard.hrl").
|
-include("mod_vcard.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
|
-include("translate.hrl").
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% API
|
%%% API
|
||||||
@ -95,32 +96,32 @@ search(LServer, Data, AllowReturnAll, MaxMatch) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
search_fields(_LServer) ->
|
search_fields(_LServer) ->
|
||||||
[{translate:mark(<<"User">>), <<"user">>},
|
[{?T("User"), <<"user">>},
|
||||||
{translate:mark(<<"Full Name">>), <<"fn">>},
|
{?T("Full Name"), <<"fn">>},
|
||||||
{translate:mark(<<"Name">>), <<"first">>},
|
{?T("Name"), <<"first">>},
|
||||||
{translate:mark(<<"Middle Name">>), <<"middle">>},
|
{?T("Middle Name"), <<"middle">>},
|
||||||
{translate:mark(<<"Family Name">>), <<"last">>},
|
{?T("Family Name"), <<"last">>},
|
||||||
{translate:mark(<<"Nickname">>), <<"nick">>},
|
{?T("Nickname"), <<"nick">>},
|
||||||
{translate:mark(<<"Birthday">>), <<"bday">>},
|
{?T("Birthday"), <<"bday">>},
|
||||||
{translate:mark(<<"Country">>), <<"ctry">>},
|
{?T("Country"), <<"ctry">>},
|
||||||
{translate:mark(<<"City">>), <<"locality">>},
|
{?T("City"), <<"locality">>},
|
||||||
{translate:mark(<<"Email">>), <<"email">>},
|
{?T("Email"), <<"email">>},
|
||||||
{translate:mark(<<"Organization Name">>), <<"orgname">>},
|
{?T("Organization Name"), <<"orgname">>},
|
||||||
{translate:mark(<<"Organization Unit">>), <<"orgunit">>}].
|
{?T("Organization Unit"), <<"orgunit">>}].
|
||||||
|
|
||||||
search_reported(_LServer) ->
|
search_reported(_LServer) ->
|
||||||
[{translate:mark(<<"Jabber ID">>), <<"jid">>},
|
[{?T("Jabber ID"), <<"jid">>},
|
||||||
{translate:mark(<<"Full Name">>), <<"fn">>},
|
{?T("Full Name"), <<"fn">>},
|
||||||
{translate:mark(<<"Name">>), <<"first">>},
|
{?T("Name"), <<"first">>},
|
||||||
{translate:mark(<<"Middle Name">>), <<"middle">>},
|
{?T("Middle Name"), <<"middle">>},
|
||||||
{translate:mark(<<"Family Name">>), <<"last">>},
|
{?T("Family Name"), <<"last">>},
|
||||||
{translate:mark(<<"Nickname">>), <<"nick">>},
|
{?T("Nickname"), <<"nick">>},
|
||||||
{translate:mark(<<"Birthday">>), <<"bday">>},
|
{?T("Birthday"), <<"bday">>},
|
||||||
{translate:mark(<<"Country">>), <<"ctry">>},
|
{?T("Country"), <<"ctry">>},
|
||||||
{translate:mark(<<"City">>), <<"locality">>},
|
{?T("City"), <<"locality">>},
|
||||||
{translate:mark(<<"Email">>), <<"email">>},
|
{?T("Email"), <<"email">>},
|
||||||
{translate:mark(<<"Organization Name">>), <<"orgname">>},
|
{?T("Organization Name"), <<"orgname">>},
|
||||||
{translate:mark(<<"Organization Unit">>), <<"orgunit">>}].
|
{?T("Organization Unit"), <<"orgunit">>}].
|
||||||
|
|
||||||
remove_user(LUser, LServer) ->
|
remove_user(LUser, LServer) ->
|
||||||
US = {LUser, LServer},
|
US = {LUser, LServer},
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
-include("mod_vcard.hrl").
|
-include("mod_vcard.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
-include("ejabberd_sql_pt.hrl").
|
-include("ejabberd_sql_pt.hrl").
|
||||||
|
-include("translate.hrl").
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% API
|
%%% API
|
||||||
@ -150,32 +151,32 @@ search(LServer, Data, AllowReturnAll, MaxMatch) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
search_fields(_LServer) ->
|
search_fields(_LServer) ->
|
||||||
[{translate:mark(<<"User">>), <<"user">>},
|
[{?T("User"), <<"user">>},
|
||||||
{translate:mark(<<"Full Name">>), <<"fn">>},
|
{?T("Full Name"), <<"fn">>},
|
||||||
{translate:mark(<<"Name">>), <<"first">>},
|
{?T("Name"), <<"first">>},
|
||||||
{translate:mark(<<"Middle Name">>), <<"middle">>},
|
{?T("Middle Name"), <<"middle">>},
|
||||||
{translate:mark(<<"Family Name">>), <<"last">>},
|
{?T("Family Name"), <<"last">>},
|
||||||
{translate:mark(<<"Nickname">>), <<"nick">>},
|
{?T("Nickname"), <<"nick">>},
|
||||||
{translate:mark(<<"Birthday">>), <<"bday">>},
|
{?T("Birthday"), <<"bday">>},
|
||||||
{translate:mark(<<"Country">>), <<"ctry">>},
|
{?T("Country"), <<"ctry">>},
|
||||||
{translate:mark(<<"City">>), <<"locality">>},
|
{?T("City"), <<"locality">>},
|
||||||
{translate:mark(<<"Email">>), <<"email">>},
|
{?T("Email"), <<"email">>},
|
||||||
{translate:mark(<<"Organization Name">>), <<"orgname">>},
|
{?T("Organization Name"), <<"orgname">>},
|
||||||
{translate:mark(<<"Organization Unit">>), <<"orgunit">>}].
|
{?T("Organization Unit"), <<"orgunit">>}].
|
||||||
|
|
||||||
search_reported(_LServer) ->
|
search_reported(_LServer) ->
|
||||||
[{translate:mark(<<"Jabber ID">>), <<"jid">>},
|
[{?T("Jabber ID"), <<"jid">>},
|
||||||
{translate:mark(<<"Full Name">>), <<"fn">>},
|
{?T("Full Name"), <<"fn">>},
|
||||||
{translate:mark(<<"Name">>), <<"first">>},
|
{?T("Name"), <<"first">>},
|
||||||
{translate:mark(<<"Middle Name">>), <<"middle">>},
|
{?T("Middle Name"), <<"middle">>},
|
||||||
{translate:mark(<<"Family Name">>), <<"last">>},
|
{?T("Family Name"), <<"last">>},
|
||||||
{translate:mark(<<"Nickname">>), <<"nick">>},
|
{?T("Nickname"), <<"nick">>},
|
||||||
{translate:mark(<<"Birthday">>), <<"bday">>},
|
{?T("Birthday"), <<"bday">>},
|
||||||
{translate:mark(<<"Country">>), <<"ctry">>},
|
{?T("Country"), <<"ctry">>},
|
||||||
{translate:mark(<<"City">>), <<"locality">>},
|
{?T("City"), <<"locality">>},
|
||||||
{translate:mark(<<"Email">>), <<"email">>},
|
{?T("Email"), <<"email">>},
|
||||||
{translate:mark(<<"Organization Name">>), <<"orgname">>},
|
{?T("Organization Name"), <<"orgname">>},
|
||||||
{translate:mark(<<"Organization Unit">>), <<"orgunit">>}].
|
{?T("Organization Unit"), <<"orgunit">>}].
|
||||||
|
|
||||||
remove_user(LUser, LServer) ->
|
remove_user(LUser, LServer) ->
|
||||||
ejabberd_sql:sql_transaction(
|
ejabberd_sql:sql_transaction(
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
-behaviour(gen_server).
|
-behaviour(gen_server).
|
||||||
|
|
||||||
-export([start_link/0, reload/0, translate/2, mark/1]).
|
-export([start_link/0, reload/0, translate/2]).
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||||
terminate/2, code_change/3]).
|
terminate/2, code_change/3]).
|
||||||
@ -219,10 +219,6 @@ translate(Msg) ->
|
|||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec mark(binary()) -> binary().
|
|
||||||
mark(Msg) ->
|
|
||||||
Msg.
|
|
||||||
|
|
||||||
ascii_tolower(B) ->
|
ascii_tolower(B) ->
|
||||||
iolist_to_binary(ascii_tolower_s(binary_to_list(B))).
|
iolist_to_binary(ascii_tolower_s(binary_to_list(B))).
|
||||||
|
|
||||||
|
@ -6,25 +6,13 @@ main([Dir]) ->
|
|||||||
Txts =
|
Txts =
|
||||||
filelib:fold_files(
|
filelib:fold_files(
|
||||||
Dir, ".+\.beam\$", false,
|
Dir, ".+\.beam\$", false,
|
||||||
fun(FileIn, Res) ->
|
fun(BeamFile, Res) ->
|
||||||
case get_forms(FileIn) of
|
Mod = mod(BeamFile),
|
||||||
{ok, Forms} ->
|
ErlFile = filename:join("src", Mod ++ ".erl"),
|
||||||
Tree = erl_syntax:form_list(Forms),
|
case get_forms(BeamFile, ErlFile) of
|
||||||
Mod = mod(FileIn),
|
{ok, BeamForms, ErlForms} ->
|
||||||
erl_syntax_lib:fold_subtrees(
|
process_forms(BeamForms, Mod, application) ++
|
||||||
fun(Form, Acc) ->
|
process_forms(ErlForms, Mod, macro) ++ Res;
|
||||||
case erl_syntax:type(Form) of
|
|
||||||
function ->
|
|
||||||
case map(Form, Mod) of
|
|
||||||
[] ->
|
|
||||||
Acc;
|
|
||||||
Vars ->
|
|
||||||
Vars ++ Acc
|
|
||||||
end;
|
|
||||||
_ ->
|
|
||||||
Acc
|
|
||||||
end
|
|
||||||
end, [], Tree) ++ Res;
|
|
||||||
_Err ->
|
_Err ->
|
||||||
Res
|
Res
|
||||||
end
|
end
|
||||||
@ -40,12 +28,31 @@ main([Dir]) ->
|
|||||||
end, dict:new(), Txts),
|
end, dict:new(), Txts),
|
||||||
generate_pot(Dict).
|
generate_pot(Dict).
|
||||||
|
|
||||||
map(Tree, Mod) ->
|
process_forms(Forms, Mod, Type) ->
|
||||||
|
Tree = erl_syntax:form_list(Forms),
|
||||||
|
erl_syntax_lib:fold_subtrees(
|
||||||
|
fun(Form, Acc) ->
|
||||||
|
case erl_syntax:type(Form) of
|
||||||
|
function ->
|
||||||
|
case map(Form, Mod, Type) of
|
||||||
|
[] ->
|
||||||
|
Acc;
|
||||||
|
Vars ->
|
||||||
|
Vars ++ Acc
|
||||||
|
end;
|
||||||
|
_ ->
|
||||||
|
Acc
|
||||||
|
end
|
||||||
|
end, [], Tree).
|
||||||
|
|
||||||
|
map(Tree, Mod, Type) ->
|
||||||
Vars = erl_syntax_lib:fold(
|
Vars = erl_syntax_lib:fold(
|
||||||
fun(Form, Acc) ->
|
fun(Form, Acc) ->
|
||||||
case erl_syntax:type(Form) of
|
case erl_syntax:type(Form) of
|
||||||
application ->
|
Type when Type == application ->
|
||||||
analyze_app(Form, Mod) ++ Acc;
|
analyze_app(Form, Mod) ++ Acc;
|
||||||
|
Type when Type == macro ->
|
||||||
|
analyze_macro(Form, Mod) ++ Acc;
|
||||||
_ ->
|
_ ->
|
||||||
Acc
|
Acc
|
||||||
end
|
end
|
||||||
@ -130,8 +137,7 @@ analyze_app(Form, Mod) ->
|
|||||||
{xmpp, "err_" ++ _, 2, [T|_]} -> T;
|
{xmpp, "err_" ++ _, 2, [T|_]} -> T;
|
||||||
{xmpp, "serr_" ++ _, 2, [T|_]} -> T;
|
{xmpp, "serr_" ++ _, 2, [T|_]} -> T;
|
||||||
{xmpp, "mk_text", 2, [T|_]} -> T;
|
{xmpp, "mk_text", 2, [T|_]} -> T;
|
||||||
{translate, "translate", 2, [_,T|_]} -> T;
|
{translate, "translate", 2, [_,T|_]} -> T
|
||||||
{translate, "mark", 1, [T]} -> T
|
|
||||||
end,
|
end,
|
||||||
Pos = erl_syntax:get_pos(Txt),
|
Pos = erl_syntax:get_pos(Txt),
|
||||||
case erl_syntax:type(Txt) of
|
case erl_syntax:type(Txt) of
|
||||||
@ -165,6 +171,24 @@ analyze_app(Form, Mod) ->
|
|||||||
[]
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
analyze_macro(Form, Mod) ->
|
||||||
|
try
|
||||||
|
Name = erl_syntax:macro_name(Form),
|
||||||
|
variable = erl_syntax:type(Name),
|
||||||
|
'T' = erl_syntax:variable_name(Name),
|
||||||
|
[Txt] = erl_syntax:macro_arguments(Form),
|
||||||
|
string = erl_syntax:type(Txt),
|
||||||
|
Pos = erl_syntax:get_pos(Txt),
|
||||||
|
try [{list_to_binary(erl_syntax:string_value(Txt)), Pos}]
|
||||||
|
catch _:_ ->
|
||||||
|
log("~s:~p: not a binary: ~s~n",
|
||||||
|
[Mod, Pos, erl_prettypr:format(Txt)]),
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
catch _:{badmatch, _} ->
|
||||||
|
[]
|
||||||
|
end.
|
||||||
|
|
||||||
generate_pot(Dict) ->
|
generate_pot(Dict) ->
|
||||||
io:format("~s~n~n", [pot_header()]),
|
io:format("~s~n~n", [pot_header()]),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
@ -213,20 +237,64 @@ pot_header() ->
|
|||||||
io_lib:nl()).
|
io_lib:nl()).
|
||||||
|
|
||||||
mod(Path) ->
|
mod(Path) ->
|
||||||
filename:rootname(filename:basename(Path)) ++ ".erl".
|
filename:rootname(filename:basename(Path)).
|
||||||
|
|
||||||
log(Format, Args) ->
|
log(Format, Args) ->
|
||||||
io:format(standard_error, Format, Args).
|
io:format(standard_error, Format, Args).
|
||||||
|
|
||||||
get_forms(File) ->
|
get_forms(BeamFile, ErlFile) ->
|
||||||
|
try
|
||||||
|
{ok, BeamForms} = get_beam_forms(BeamFile),
|
||||||
|
{ok, ErlForms} = get_erl_forms(ErlFile),
|
||||||
|
{ok, BeamForms, ErlForms}
|
||||||
|
catch _:{badmatch, error} ->
|
||||||
|
error
|
||||||
|
end.
|
||||||
|
|
||||||
|
get_beam_forms(File) ->
|
||||||
case beam_lib:chunks(File, [abstract_code]) of
|
case beam_lib:chunks(File, [abstract_code]) of
|
||||||
{ok, {_, List}} ->
|
{ok, {_, List}} ->
|
||||||
case lists:keyfind(abstract_code, 1, List) of
|
case lists:keyfind(abstract_code, 1, List) of
|
||||||
{abstract_code, {raw_abstract_v1, Abstr}} ->
|
{abstract_code, {raw_abstract_v1, Abstr}} ->
|
||||||
{ok, Abstr};
|
{ok, Abstr};
|
||||||
_ ->
|
_Err ->
|
||||||
|
log("failed to get abstract code from ~s~n", [File]),
|
||||||
error
|
error
|
||||||
end;
|
end;
|
||||||
_ ->
|
Err ->
|
||||||
|
log("failed to read chunks from ~s: ~p~n", [File, Err]),
|
||||||
|
error
|
||||||
|
end.
|
||||||
|
|
||||||
|
get_erl_forms(Path) ->
|
||||||
|
case file:open(Path, [read]) of
|
||||||
|
{ok, Fd} ->
|
||||||
|
parse(Path, Fd, 1, []);
|
||||||
|
{error, Why} ->
|
||||||
|
log("failed to read ~s: ~s~n", [Path, file:format_error(Why)]),
|
||||||
|
error
|
||||||
|
end.
|
||||||
|
|
||||||
|
parse(Path, Fd, Line, Acc) ->
|
||||||
|
{ok, Pos} = file:position(Fd, cur),
|
||||||
|
case epp_dodger:parse_form(Fd, Line) of
|
||||||
|
{ok, Form, NewLine} ->
|
||||||
|
{ok, NewPos} = file:position(Fd, cur),
|
||||||
|
{ok, RawForm} = file:pread(Fd, Pos, NewPos - Pos),
|
||||||
|
file:position(Fd, {bof, NewPos}),
|
||||||
|
AnnForm = erl_syntax:set_ann(Form, RawForm),
|
||||||
|
parse(Path, Fd, NewLine, [AnnForm|Acc]);
|
||||||
|
{eof, _} ->
|
||||||
|
{ok, NewPos} = file:position(Fd, cur),
|
||||||
|
if NewPos > Pos ->
|
||||||
|
{ok, RawForm} = file:pread(Fd, Pos, NewPos - Pos),
|
||||||
|
Form = erl_syntax:text(""),
|
||||||
|
AnnForm = erl_syntax:set_ann(Form, RawForm),
|
||||||
|
{ok, lists:reverse([AnnForm|Acc])};
|
||||||
|
true ->
|
||||||
|
{ok, lists:reverse(Acc)}
|
||||||
|
end;
|
||||||
|
Err ->
|
||||||
|
log("failed to parse ~s: ~p~n", [Path, Err]),
|
||||||
error
|
error
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user