diff options
author | Evgeny Khramtsov <ekhramtsov@process-one.net> | 2019-06-22 17:08:45 +0300 |
---|---|---|
committer | Evgeny Khramtsov <ekhramtsov@process-one.net> | 2019-06-22 17:08:45 +0300 |
commit | 00f2a736eb555206fd76b65ca32f00cb9df9f026 (patch) | |
tree | 5f3f704c329f7a5037e4dca067eb655b54810386 /src/mod_muc_log.erl | |
parent | Change Travis OTP platform from 19.1 to 19.3 (diff) |
Improve extraction of translated strings
Now every such string MUST be encapsulated into ?T() macro.
The macro itself is defined in include/translate.hrl.
Example:
-module(foo).
-export([bar/1]).
-include("translate.hrl").
bar(Lang) ->
translate:translate(Lang, ?T("baz")).
Diffstat (limited to '')
-rw-r--r-- | src/mod_muc_log.erl | 138 |
1 files changed, 70 insertions, 68 deletions
diff --git a/src/mod_muc_log.erl b/src/mod_muc_log.erl index 0e2ff6984..4b9a6154d 100644 --- a/src/mod_muc_log.erl +++ b/src/mod_muc_log.erl @@ -42,11 +42,10 @@ mod_opt_type/1, mod_options/1, depends/2]). -include("logger.hrl"). - -include("xmpp.hrl"). -include("mod_muc_room.hrl"). +-include("translate.hrl"). --define(T(Text), translate:translate(Lang, Text)). -record(room, {jid, title, subject, subject_author, config}). -define(PLAINTEXT_CO, <<"ZZCZZ">>). @@ -346,7 +345,7 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, Lang, FileFormat), put_room_config(F, RoomConfig, Lang, FileFormat), io_lib:format("<font class=\"mrcm\">~s</font><br/>", - [?T(<<"Chatroom configuration modified">>)]); + [tr(Lang, ?T("Chatroom configuration modified"))]); {roomconfig_change, Occupants} -> RoomConfig = roomconfig_to_string(Room#room.config, Lang, FileFormat), @@ -355,53 +354,53 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, FileFormat), put_room_occupants(F, RoomOccupants, Lang, FileFormat), io_lib:format("<font class=\"mrcm\">~s</font><br/>", - [?T(<<"Chatroom configuration modified">>)]); + [tr(Lang, ?T("Chatroom configuration modified"))]); join -> io_lib:format("<font class=\"mj\">~s ~s</font><br/>", - [Nick, ?T(<<"joins the room">>)]); + [Nick, tr(Lang, ?T("joins the room"))]); leave -> io_lib:format("<font class=\"ml\">~s ~s</font><br/>", - [Nick, ?T(<<"leaves the room">>)]); + [Nick, tr(Lang, ?T("leaves the room"))]); {leave, Reason} -> io_lib:format("<font class=\"ml\">~s ~s: ~s</font><br/>", - [Nick, ?T(<<"leaves the room">>), + [Nick, tr(Lang, ?T("leaves the room")), htmlize(Reason, NoFollow, FileFormat)]); {kickban, 301, <<"">>} -> io_lib:format("<font class=\"mb\">~s ~s</font><br/>", - [Nick, ?T(<<"has been banned">>)]); + [Nick, tr(Lang, ?T("has been banned"))]); {kickban, 301, Reason} -> io_lib:format("<font class=\"mb\">~s ~s: ~s</font><br/>", - [Nick, ?T(<<"has been banned">>), + [Nick, tr(Lang, ?T("has been banned")), htmlize(Reason, FileFormat)]); {kickban, 307, <<"">>} -> io_lib:format("<font class=\"mk\">~s ~s</font><br/>", - [Nick, ?T(<<"has been kicked">>)]); + [Nick, tr(Lang, ?T("has been kicked"))]); {kickban, 307, Reason} -> io_lib:format("<font class=\"mk\">~s ~s: ~s</font><br/>", - [Nick, ?T(<<"has been kicked">>), + [Nick, tr(Lang, ?T("has been kicked")), htmlize(Reason, FileFormat)]); {kickban, 321, <<"">>} -> io_lib:format("<font class=\"mk\">~s ~s</font><br/>", [Nick, - ?T(<<"has been kicked because of an affiliation " - "change">>)]); + tr(Lang, ?T("has been kicked because of an affiliation " + "change"))]); {kickban, 322, <<"">>} -> io_lib:format("<font class=\"mk\">~s ~s</font><br/>", [Nick, - ?T(<<"has been kicked because the room has " - "been changed to members-only">>)]); + tr(Lang, ?T("has been kicked because the room has " + "been changed to members-only"))]); {kickban, 332, <<"">>} -> io_lib:format("<font class=\"mk\">~s ~s</font><br/>", [Nick, - ?T(<<"has been kicked because of a system " - "shutdown">>)]); + tr(Lang, ?T("has been kicked because of a system " + "shutdown"))]); {nickchange, OldNick} -> io_lib:format("<font class=\"mnc\">~s ~s ~s</font><br/>", [htmlize(OldNick, FileFormat), - ?T(<<"is now known as">>), Nick]); + tr(Lang, ?T("is now known as")), Nick]); {subject, T} -> io_lib:format("<font class=\"msc\">~s~s~s</font><br/>", - [Nick, ?T(<<" has set the subject to: ">>), + [Nick, tr(Lang, ?T(" has set the subject to: ")), htmlize(T, NoFollow, FileFormat)]); {body, T} -> case {ejabberd_regexp:run(T, <<"^/me ">>), Nick} of @@ -441,38 +440,38 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, %% Utilities get_room_existence_string(created, Lang) -> - ?T(<<"Chatroom is created">>); + tr(Lang, ?T("Chatroom is created")); get_room_existence_string(destroyed, Lang) -> - ?T(<<"Chatroom is destroyed">>); + tr(Lang, ?T("Chatroom is destroyed")); get_room_existence_string(started, Lang) -> - ?T(<<"Chatroom is started">>); + tr(Lang, ?T("Chatroom is started")); get_room_existence_string(stopped, Lang) -> - ?T(<<"Chatroom is stopped">>). + tr(Lang, ?T("Chatroom is stopped")). get_dateweek(Date, Lang) -> Weekday = case calendar:day_of_the_week(Date) of - 1 -> ?T(<<"Monday">>); - 2 -> ?T(<<"Tuesday">>); - 3 -> ?T(<<"Wednesday">>); - 4 -> ?T(<<"Thursday">>); - 5 -> ?T(<<"Friday">>); - 6 -> ?T(<<"Saturday">>); - 7 -> ?T(<<"Sunday">>) + 1 -> tr(Lang, ?T("Monday")); + 2 -> tr(Lang, ?T("Tuesday")); + 3 -> tr(Lang, ?T("Wednesday")); + 4 -> tr(Lang, ?T("Thursday")); + 5 -> tr(Lang, ?T("Friday")); + 6 -> tr(Lang, ?T("Saturday")); + 7 -> tr(Lang, ?T("Sunday")) end, {Y, M, D} = Date, Month = case M of - 1 -> ?T(<<"January">>); - 2 -> ?T(<<"February">>); - 3 -> ?T(<<"March">>); - 4 -> ?T(<<"April">>); - 5 -> ?T(<<"May">>); - 6 -> ?T(<<"June">>); - 7 -> ?T(<<"July">>); - 8 -> ?T(<<"August">>); - 9 -> ?T(<<"September">>); - 10 -> ?T(<<"October">>); - 11 -> ?T(<<"November">>); - 12 -> ?T(<<"December">>) + 1 -> tr(Lang, ?T("January")); + 2 -> tr(Lang, ?T("February")); + 3 -> tr(Lang, ?T("March")); + 4 -> tr(Lang, ?T("April")); + 5 -> tr(Lang, ?T("May")); + 6 -> tr(Lang, ?T("June")); + 7 -> tr(Lang, ?T("July")); + 8 -> tr(Lang, ?T("August")); + 9 -> tr(Lang, ?T("September")); + 10 -> tr(Lang, ?T("October")); + 11 -> tr(Lang, ?T("November")); + 12 -> tr(Lang, ?T("December")) end, list_to_binary( case Lang of @@ -575,7 +574,7 @@ put_header(F, Room, Date, CSSFile, Lang, Hour_offset, {<<"">>, <<"">>} -> ok; {SuA, Su} -> fw(F, <<"<div class=\"roomsubject\">~s~s~s</div>">>, - [SuA, ?T(<<" has set the subject to: ">>), Su]) + [SuA, tr(Lang, ?T(" has set the subject to: ")), Su]) end, RoomConfig = roomconfig_to_string(Room#room.config, Lang, FileFormat), @@ -622,7 +621,7 @@ put_room_config(F, RoomConfig, Lang, _FileFormat) -> fw(F, <<"<div class=\"rct\" onclick=\"sh('a~p');return " "false;\">~s</div>">>, - [Now2, ?T(<<"Room Configuration">>)]), + [Now2, tr(Lang, ?T("Room Configuration"))]), fw(F, <<"<div class=\"rcos\" id=\"a~p\" style=\"displa" "y: none;\" ><br/>~s</div>">>, @@ -642,7 +641,7 @@ put_room_occupants(F, RoomOccupants, Lang, fw(F, <<"<div class=\"rct\" onclick=\"sh('o~p');return " "false;\">~s</div>">>, - [Now2, ?T(<<"Room Occupants">>)]), + [Now2, tr(Lang, ?T("Room Occupants"))]), fw(F, <<"<div class=\"rcos\" id=\"o~p\" style=\"displa" "y: none;\" ><br/>~s</div>">>, @@ -766,7 +765,7 @@ roomconfig_to_string(Options, Lang, FileFormat) -> allow_private_messages_from_visitors -> <<"<div class=\"rcot\">", OptText/binary, ": \"", - (htmlize(?T(misc:atom_to_binary(T)), + (htmlize(tr(Lang, misc:atom_to_binary(T)), FileFormat))/binary, "\"</div>">>; _ -> <<"\"", T/binary, "\"">> @@ -777,48 +776,47 @@ roomconfig_to_string(Options, Lang, FileFormat) -> end, <<"">>, Options2). -get_roomconfig_text(title, Lang) -> ?T(<<"Room title">>); +get_roomconfig_text(title, Lang) -> tr(Lang, ?T("Room title")); get_roomconfig_text(persistent, Lang) -> - ?T(<<"Make room persistent">>); + tr(Lang, ?T("Make room persistent")); get_roomconfig_text(public, Lang) -> - ?T(<<"Make room public searchable">>); + tr(Lang, ?T("Make room public searchable")); get_roomconfig_text(public_list, Lang) -> - ?T(<<"Make participants list public">>); + tr(Lang, ?T("Make participants list public")); get_roomconfig_text(password_protected, Lang) -> - ?T(<<"Make room password protected">>); -get_roomconfig_text(password, Lang) -> ?T(<<"Password">>); + tr(Lang, ?T("Make room password protected")); +get_roomconfig_text(password, Lang) -> tr(Lang, ?T("Password")); get_roomconfig_text(anonymous, Lang) -> - ?T(<<"This room is not anonymous">>); + tr(Lang, ?T("This room is not anonymous")); get_roomconfig_text(members_only, Lang) -> - ?T(<<"Make room members-only">>); + tr(Lang, ?T("Make room members-only")); get_roomconfig_text(moderated, Lang) -> - ?T(<<"Make room moderated">>); + tr(Lang, ?T("Make room moderated")); get_roomconfig_text(members_by_default, Lang) -> - ?T(<<"Default users as participants">>); + tr(Lang, ?T("Default users as participants")); get_roomconfig_text(allow_change_subj, Lang) -> - ?T(<<"Allow users to change the subject">>); + tr(Lang, ?T("Allow users to change the subject")); get_roomconfig_text(allow_private_messages, Lang) -> - ?T(<<"Allow users to send private messages">>); + tr(Lang, ?T("Allow users to send private messages")); get_roomconfig_text(allow_private_messages_from_visitors, Lang) -> - ?T(<<"Allow visitors to send private messages to">>); + tr(Lang, ?T("Allow visitors to send private messages to")); get_roomconfig_text(allow_query_users, Lang) -> - ?T(<<"Allow users to query other users">>); + tr(Lang, ?T("Allow users to query other users")); get_roomconfig_text(allow_user_invites, Lang) -> - ?T(<<"Allow users to send invites">>); -get_roomconfig_text(logging, Lang) -> ?T(<<"Enable logging">>); + tr(Lang, ?T("Allow users to send invites")); +get_roomconfig_text(logging, Lang) -> tr(Lang, ?T("Enable logging")); get_roomconfig_text(allow_visitor_nickchange, Lang) -> - ?T(<<"Allow visitors to change nickname">>); + tr(Lang, ?T("Allow visitors to change nickname")); get_roomconfig_text(allow_visitor_status, Lang) -> - ?T(<<"Allow visitors to send status text in " - "presence updates">>); + tr(Lang, ?T("Allow visitors to send status text in presence updates")); get_roomconfig_text(captcha_protected, Lang) -> - ?T(<<"Make room CAPTCHA protected">>); + tr(Lang, ?T("Make room CAPTCHA protected")); get_roomconfig_text(description, Lang) -> - ?T(<<"Room description">>); + tr(Lang, ?T("Room description")); %% get_roomconfig_text(subject, Lang) -> "Subject"; %% get_roomconfig_text(subject_author, Lang) -> "Subject author"; get_roomconfig_text(max_users, Lang) -> - ?T(<<"Maximum Number of Occupants">>); + tr(Lang, ?T("Maximum Number of Occupants")); get_roomconfig_text(_, _) -> undefined. %% Users = [{JID, Nick, Role}] @@ -918,6 +916,10 @@ calc_hour_offset(TimeHere) -> fjoin(FileList) -> list_to_binary(filename:join([binary_to_list(File) || File <- FileList])). +-spec tr(binary(), binary()) -> binary(). +tr(Lang, Text) -> + translate:translate(Lang, Text). + has_no_permanent_store_hint(Packet) -> xmpp:has_subtag(Packet, #hint{type = 'no-store'}) orelse xmpp:has_subtag(Packet, #hint{type = 'no-storage'}) orelse |