Skip to content

Commit 704a926

Browse files
authored
Merge pull request #4481 from esl/translations_as_a_service
Translations as a service
2 parents 249ba9e + 8f4011d commit 704a926

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+122
-99
lines changed

doc/configuration/Services.md

Lines changed: 5 additions & 0 deletions

include/mod_vcard.hrl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
-export_type([vcard_search/0]).
1717

1818
-define(TLFIELD(Type, Label, Var),
19-
#{var => Var, type => Type, label => translate:translate(Lang, Label)}).
19+
#{var => Var, type => Type, label => service_translations:do(Lang, Label)}).
2020

2121
-define(FIELD(Var, Val),
2222
#{var => Var, values => [Val]}).
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/config/mongoose_config_spec.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,8 @@ services() ->
732732

733733
configurable_services() ->
734734
[service_mongoose_system_metrics,
735-
service_domain_db].
735+
service_domain_db,
736+
service_translations].
736737

737738
%% path: (host_config[].)modules
738739
modules() ->

src/ejabberd_app.erl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ do_start() ->
6161
mongoose_config:start(),
6262
mongoose_internal_databases:init(),
6363
mongoose_graphql:init(),
64-
translate:start(),
6564
mongoose_graphql_commands:start(),
6665
mongoose_logs:set_global_loglevel(mongoose_config:get_opt(loglevel)),
6766
mongoose_deprecations:start(),

src/http_upload/mod_http_upload.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ subdomain_pattern(HostType) ->
236236

237237
-spec my_disco_name(ejabberd:lang()) -> binary().
238238
my_disco_name(Lang) ->
239-
translate:translate(Lang, <<"HTTP File Upload">>).
239+
service_translations:do(Lang, <<"HTTP File Upload">>).
240240

241241

242242
-spec compose_iq_reply(IQ :: jlib:iq(),

src/jlib.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ stanza_error(Code, Type, Condition) ->
407407
, Lang :: ejabberd:lang()
408408
, Text :: binary()) -> exml:element().
409409
stanza_errort(Code, Type, Condition, Lang, Text) ->
410-
Txt = translate:translate(Lang, Text),
410+
Txt = service_translations:do(Lang, Text),
411411
#xmlel{ name = <<"error">>
412412
, attrs = #{<<"code">> => Code, <<"type">> => Type}
413413
, children = [ #xmlel{ name = Condition
@@ -432,7 +432,7 @@ stream_error(Condition) ->
432432
, Lang :: ejabberd:lang()
433433
, Text :: binary()) -> exml:element().
434434
stream_errort(Condition, Lang, Text) ->
435-
Txt = translate:translate(Lang, Text),
435+
Txt = service_translations:do(Lang, Text),
436436
#xmlel{ name = <<"stream:error">>
437437
, children = [ #xmlel{ name = Condition
438438
, attrs = #{<<"xmlns">> => ?NS_STREAMS} }

src/mod_adhoc.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ are_commands_visible(HostType) ->
180180
gen_mod:get_module_opt(HostType, ?MODULE, report_commands_node).
181181

182182
item(LServer, Node, Name, Lang) ->
183-
#{jid => LServer, node => Node, name => translate:translate(Lang, Name)}.
183+
#{jid => LServer, node => Node, name => service_translations:do(Lang, Name)}.
184184

185185
%%-------------------------------------------------------------------------
186186

@@ -211,12 +211,12 @@ disco_sm_identity(Acc, _, _) ->
211211
ping_identity(Lang) ->
212212
#{category => <<"automation">>,
213213
type => <<"command-node">>,
214-
name => translate:translate(Lang, <<"Ping">>)}.
214+
name => service_translations:do(Lang, <<"Ping">>)}.
215215

216216
command_list_identity(Lang) ->
217217
#{category => <<"automation">>,
218218
type => <<"command-list">>,
219-
name => translate:translate(Lang, <<"Commands">>)}.
219+
name => service_translations:do(Lang, <<"Commands">>)}.
220220

221221
%%-------------------------------------------------------------------------
222222

@@ -266,7 +266,7 @@ ping_command(empty,
266266
node = Node,
267267
session_id = SessionID,
268268
status = completed,
269-
notes = [{<<"info">>, translate:translate(Lang, <<"Pong">>)}]});
269+
notes = [{<<"info">>, service_translations:do(Lang, <<"Pong">>)}]});
270270
false ->
271271
{error, mongoose_xmpp_errors:bad_request()}
272272
end,

src/mod_register.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ process_iq_get(_HostType, From, _To, #iq{lang = Lang, sub_el = Child} = IQ, _Sou
302302
_ ->
303303
{false, [], []}
304304
end,
305-
TranslatedMsg = translate:translate(
305+
TranslatedMsg = service_translations:do(
306306
Lang, <<"Choose a username and password to register with this server">>),
307307
IQ#iq{type = result,
308308
sub_el = [#xmlel{name = <<"query">>,

src/muc/mod_muc.erl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ default_host() ->
923923
identity(Lang) ->
924924
#{category => <<"conference">>,
925925
type => <<"text">>,
926-
name => translate:translate(Lang, <<"Chatrooms">>)}.
926+
name => service_translations:do(Lang, <<"Chatrooms">>)}.
927927

928928
features() ->
929929
[?NS_DISCO_INFO, ?NS_DISCO_ITEMS, ?NS_MUC, ?NS_MUC_UNIQUE, ?NS_REGISTER, ?NS_RSM, ?NS_VCARD, ?NS_CONFERENCE].
@@ -1049,15 +1049,15 @@ iq_get_register_info(HostType, MucHost, From, Lang) ->
10491049
{ok, N} ->
10501050
{N, [#xmlel{name = <<"registered">>}]}
10511051
end,
1052-
ClientReqText = translate:translate(
1052+
ClientReqText = service_translations:do(
10531053
Lang, <<"You need a client that supports x:data to register the nickname">>),
10541054
ClientReqEl = #xmlel{name = <<"instructions">>,
10551055
children = [#xmlcdata{content = ClientReqText}]},
1056-
EnterNicknameText = translate:translate(Lang, <<"Enter nickname you want to register">>),
1057-
TitleText = <<(translate:translate(Lang, <<"Nickname Registration at ">>))/binary,
1056+
EnterNicknameText = service_translations:do(Lang, <<"Enter nickname you want to register">>),
1057+
TitleText = <<(service_translations:do(Lang, <<"Nickname Registration at ">>))/binary,
10581058
MucHost/binary>>,
10591059
NickField = #{type => <<"text-single">>,
1060-
label => translate:translate(Lang, <<"Nickname">>),
1060+
label => service_translations:do(Lang, <<"Nickname">>),
10611061
var => <<"nick">>,
10621062
values => [Nick]},
10631063
Registered ++ [ClientReqEl, mongoose_data_forms:form(#{title => TitleText,
@@ -1136,7 +1136,7 @@ iq_get_vcard(Lang) ->
11361136
#xmlel{name = <<"URL">>, children = [#xmlcdata{content = ?MONGOOSE_URI}]},
11371137
#xmlel{name = <<"DESC">>,
11381138
children = [#xmlcdata{content =
1139-
<<(translate:translate(Lang, <<"ejabberd MUC module">>))/binary,
1139+
<<(service_translations:do(Lang, <<"ejabberd MUC module">>))/binary,
11401140
"\nCopyright (c) 2003-2011 ProcessOne">>}]}].
11411141

11421142
-spec broadcast_service_message(muc_host(), binary() | string()) -> ok.

src/muc/mod_muc_log.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
-include("mod_muc_room.hrl").
5555
-include("mongoose_config_spec.hrl").
5656

57-
-define(T(Text), translate:translate(Lang, Text)).
57+
-define(T(Text), service_translations:do(Lang, Text)).
5858
-define(PROCNAME, ejabberd_mod_muc_log).
5959

6060
-record(room, {jid, title, subject, subject_author, config}).

src/muc/mod_muc_room.erl

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ process_presence_error(From, Packet, Lang, StateData) ->
10781078
true ->
10791079
ErrorText
10801080
= <<"This participant is kicked from the room because he sent an error presence">>,
1081-
expulse_participant(Packet, From, StateData, translate:translate(Lang, ErrorText));
1081+
expulse_participant(Packet, From, StateData, service_translations:do(Lang, ErrorText));
10821082
_ ->
10831083
StateData
10841084
end.
@@ -2862,8 +2862,8 @@ get_affected_jid(Item, Lang, StateData) ->
28622862
{S, _} when undefined =/= S ->
28632863
case jid:from_binary(S) of
28642864
error ->
2865-
ErrText = <<(translate:translate(Lang, <<"Jabber ID ">>))/binary,
2866-
S/binary, (translate:translate(Lang, <<" is invalid">>))/binary>>,
2865+
ErrText = <<(service_translations:do(Lang, <<"Jabber ID ">>))/binary,
2866+
S/binary, (service_translations:do(Lang, <<" is invalid">>))/binary>>,
28672867
{error, mongoose_xmpp_errors:not_acceptable(Lang, ErrText)};
28682868
J ->
28692869
{value, J}
@@ -2872,8 +2872,8 @@ get_affected_jid(Item, Lang, StateData) ->
28722872
case find_jids_by_nick(N, StateData) of
28732873
[] ->
28742874
ErrText
2875-
= <<(translate:translate(Lang, <<"Nickname ">>))/binary, N/binary,
2876-
(translate:translate(Lang, <<" does not exist in the room">>))/binary>>,
2875+
= <<(service_translations:do(Lang, <<"Nickname ">>))/binary, N/binary,
2876+
(service_translations:do(Lang, <<" does not exist in the room">>))/binary>>,
28772877
{error, mongoose_xmpp_errors:not_acceptable(Lang, ErrText)};
28782878
[FirstSessionJid | _RestOfSessions] ->
28792879
{value, FirstSessionJid}
@@ -2945,7 +2945,7 @@ which_property_changed(Item, Lang) ->
29452945
{undefined, BAffiliation} ->
29462946
case catch binary_to_affiliation(BAffiliation) of
29472947
{'EXIT', _} ->
2948-
ErrText1 = <<(translate:translate(Lang, <<"Invalid affiliation ">>))/binary,
2948+
ErrText1 = <<(service_translations:do(Lang, <<"Invalid affiliation ">>))/binary,
29492949
BAffiliation/binary>>,
29502950
{error, mongoose_xmpp_errors:not_acceptable(Lang, ErrText1)};
29512951
Affiliation ->
@@ -2954,7 +2954,7 @@ which_property_changed(Item, Lang) ->
29542954
{BRole, _} ->
29552955
case catch binary_to_role(BRole) of
29562956
{'EXIT', _} ->
2957-
ErrText1 = <<(translate:translate(Lang, <<"Invalid role ">>))/binary,
2957+
ErrText1 = <<(service_translations:do(Lang, <<"Invalid role ">>))/binary,
29582958
BRole/binary>>,
29592959
{error, mongoose_xmpp_errors:bad_request(Lang, ErrText1)};
29602960
Role ->
@@ -3178,7 +3178,7 @@ process_authorized_iq_owner(From, get, Lang, SubEl, StateData, _StateName) ->
31783178
BAffiliation ->
31793179
case catch binary_to_affiliation(BAffiliation) of
31803180
{'EXIT', _} ->
3181-
InvAffT = translate:translate(Lang, <<"Invalid affiliation ">>),
3181+
InvAffT = service_translations:do(Lang, <<"Invalid affiliation ">>),
31823182
ErrText = <<InvAffT/binary, BAffiliation/binary>>,
31833183
{error, mongoose_xmpp_errors:not_acceptable(Lang, ErrText)};
31843184
Affiliation ->
@@ -3294,7 +3294,7 @@ get_default_room_maxusers(RoomState) ->
32943294
get_config(Lang, StateData, From) ->
32953295
AccessPersistent = access_persistent(StateData),
32963296
Config = StateData#state.config,
3297-
TitleTxt = translate:translate(Lang, <<"Configuration of room ">>),
3297+
TitleTxt = service_translations:do(Lang, <<"Configuration of room ">>),
32983298
Title = <<TitleTxt/binary, (jid:to_binary(StateData#state.jid))/binary>>,
32993299
Fields =
33003300
[stringxfield(<<"Room title">>,
@@ -3370,18 +3370,18 @@ get_config(Lang, StateData, From) ->
33703370
Config#config.logging, Lang)];
33713371
_ -> []
33723372
end,
3373-
InstructionsTxt = translate:translate(
3373+
InstructionsTxt = service_translations:do(
33743374
Lang, <<"You need an x:data capable client to configure room">>),
33753375
{result, [#xmlel{name = <<"instructions">>, children = [#xmlcdata{content = InstructionsTxt}]},
33763376
mongoose_data_forms:form(#{title => Title, ns => ?NS_MUC_CONFIG, fields => Fields})],
33773377
StateData}.
33783378

33793379
-spec getmemberlist_field(Lang :: ejabberd:lang()) -> mongoose_data_forms:field().
33803380
getmemberlist_field(Lang) ->
3381-
LabelTxt = translate:translate(
3381+
LabelTxt = service_translations:do(
33823382
Lang, <<"Roles and affiliations that may retrieve member list">>),
33833383
Values = [<<"moderator">>, <<"participant">>, <<"visitor">>],
3384-
Options = [{translate:translate(Lang, Opt), Opt} || Opt <- Values],
3384+
Options = [{service_translations:do(Lang, Opt), Opt} || Opt <- Values],
33853385
#{type => <<"list-multi">>, label => LabelTxt,
33863386
var => <<"muc#roomconfig_getmemberlist">>, values => Values, options => Options}.
33873387

@@ -3394,10 +3394,10 @@ maxusers_field(Lang, StateData) ->
33943394
{N, integer_to_binary(N)};
33953395
_ -> {0, <<"none">>}
33963396
end,
3397-
LabelTxt = translate:translate(Lang, <<"Maximum Number of Occupants">>),
3397+
LabelTxt = service_translations:do(Lang, <<"Maximum Number of Occupants">>),
33983398
Options = if
33993399
is_integer(ServiceMaxUsers) -> [];
3400-
true -> {translate:translate(Lang, <<"No limit">>), <<"none">>}
3400+
true -> {service_translations:do(Lang, <<"No limit">>), <<"none">>}
34013401
end ++
34023402
[integer_to_binary(N) ||
34033403
N <- lists:usort([ServiceMaxUsers, DefaultRoomMaxUsers, MaxUsersRoomInteger |
@@ -3410,9 +3410,9 @@ whois_field(Lang, Config) ->
34103410
Value = if Config#config.anonymous -> <<"moderators">>;
34113411
true -> <<"anyone">>
34123412
end,
3413-
Options = [{translate:translate(Lang, <<"moderators only">>), <<"moderators">>},
3414-
{translate:translate(Lang, <<"anyone">>), <<"anyone">>}],
3415-
#{type => <<"list-single">>, label => translate:translate(Lang, <<"moderators only">>),
3413+
Options = [{service_translations:do(Lang, <<"moderators only">>), <<"moderators">>},
3414+
{service_translations:do(Lang, <<"anyone">>), <<"anyone">>}],
3415+
#{type => <<"list-single">>, label => service_translations:do(Lang, <<"moderators only">>),
34163416
var => <<"muc#roomconfig_whois">>, values => [Value], options => Options}.
34173417

34183418
-spec set_config([{binary(), [binary()]}], state()) -> any().
@@ -3792,7 +3792,7 @@ iq_disco_info_extras(Lang, StateData) ->
37923792

37933793
-spec info_field(binary(), binary(), binary(), ejabberd:lang()) -> mongoose_disco:info_field().
37943794
info_field(Label, Var, Value, Lang) ->
3795-
#{label => translate:translate(Lang, Label), var => Var, values => [Value]}.
3795+
#{label => service_translations:do(Lang, Label), var => Var, values => [Value]}.
37963796

37973797
-spec process_iq_disco_items(jid:jid(), 'get' | 'set', ejabberd:lang(),
37983798
state()) -> {'error', exml:element()}
@@ -3845,7 +3845,7 @@ get_roomdesc_tail(StateData, Lang) ->
38453845
true ->
38463846
<<>>;
38473847
_ ->
3848-
translate:translate(Lang, <<"private, ">>)
3848+
service_translations:do(Lang, <<"private, ">>)
38493849
end,
38503850
Count = count_users(StateData),
38513851
CountBin = integer_to_binary(Count),
@@ -4026,11 +4026,11 @@ invite_body_text(FromJID, Reason, Lang,
40264026
password=Password}}) ->
40274027
BFromJID = jid:to_binary(FromJID),
40284028
BRoomJID = jid:to_binary(RoomJID),
4029-
ITranslate = translate:translate(Lang, <<" invites you to the room ">>),
4029+
ITranslate = service_translations:do(Lang, <<" invites you to the room ">>),
40304030
IMessage = <<BFromJID/binary, ITranslate/binary, BRoomJID/binary>>,
40314031
BPassword = case IsProtected of
40324032
true ->
4033-
PTranslate = translate:translate(Lang, <<"the password is">>),
4033+
PTranslate = service_translations:do(Lang, <<"the password is">>),
40344034
<<", ", PTranslate/binary, " '", Password/binary, "'">>;
40354035
_ ->
40364036
<<>>
@@ -4232,7 +4232,7 @@ route_message(#routed_message{allowed = true, type = <<"error">>, from = From,
42324232
true ->
42334233
ErrorText
42344234
= <<"This participant is kicked from the room because he sent an error message">>,
4235-
expulse_participant(Packet, From, StateData, translate:translate(Lang, ErrorText));
4235+
expulse_participant(Packet, From, StateData, service_translations:do(Lang, ErrorText));
42364236
_ ->
42374237
StateData
42384238
end;
@@ -4433,7 +4433,7 @@ route_nick_message(#routed_nick_message{decide = {expulse_sender, _Reason},
44334433
"sent an error message to another participant">>,
44344434
?LOG_DEBUG(ls(#{what => muc_expulse_sender, text => ErrorText,
44354435
user => From#jid.luser, exml_packet => Packet}, StateData)),
4436-
expulse_participant(Packet, From, StateData, translate:translate(Lang, ErrorText));
4436+
expulse_participant(Packet, From, StateData, service_translations:do(Lang, ErrorText));
44374437
route_nick_message(#routed_nick_message{decide = forget_message}, StateData) ->
44384438
StateData;
44394439
route_nick_message(#routed_nick_message{decide = continue_delivery, allow_pm = true,
@@ -4537,7 +4537,7 @@ make_voice_approval_form(From, Nick, Role) ->
45374537

45384538
-spec xfield(binary(), any(), binary(), binary(), ejabberd:lang()) -> mongoose_data_forms:field().
45394539
xfield(Type, Label, Var, Val, Lang) ->
4540-
#{type => Type, label => translate:translate(Lang, Label), var => Var, values => [Val]}.
4540+
#{type => Type, label => service_translations:do(Lang, Label), var => Var, values => [Val]}.
45414541

45424542
-spec boolxfield(any(), binary(), any(), ejabberd:lang()) -> mongoose_data_forms:field().
45434543
boolxfield(Label, Var, Val, Lang) ->
@@ -4584,7 +4584,7 @@ maybe_add_x_element(#xmlel{children = Children} = Msg) ->
45844584
kick_stanza_for_old_protocol(Packet) ->
45854585
Lang = exml_query:attr(Packet, <<"xml:lang">>, <<>>),
45864586
ErrText = <<"You are not in the room.">>,
4587-
ErrText2 = translate:translate(Lang, ErrText),
4587+
ErrText2 = service_translations:do(Lang, ErrText),
45884588
Response = #xmlel{name = <<"presence">>, attrs = #{<<"type">> => <<"unavailable">>}},
45894589
ItemAttrs = #{<<"affiliation">> => <<"none">>, <<"role">> => <<"none">>},
45904590
ItemEls = [#xmlel{name = <<"reason">>, children = [#xmlcdata{content = ErrText2}]}],

0 commit comments

Comments
 (0)