25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Adapt to new exmpp API where get_id/1, get_lang/1, get_initiating_entity/1, get_receiving_entity/1 and get_type/1 returns binary().

SVN Revision: 1791
This commit is contained in:
Pablo Polvorin 2009-01-09 19:18:46 +00:00
parent d2524b20d5
commit 98f51dc91f
16 changed files with 136 additions and 103 deletions

View File

@ -1,3 +1,20 @@
2009-01-09 Pablo Polvorin <pablo.polvorin@process-one.net>
* src/mod_muc/mod_muc_room.erl, src/mod_muc/mod_muc.erl
src/mod_offline_odbc.erl, src/mod_irc/mod_irc_connection.erl,
src/mod_irc/mod_irc.erl, src/ejabberd_c2s.erl, src/ejabberd_local.erl,
src/mod_pubsub/mod_pubsub.erl, src/ejabberd_s2s.erl, src/mod_roster.erl,
src/mod_roster_odbc.erl, src/ejabberd_s2s_out.erl, src/mod_offline.erl,
src/translate.erl: Adapt to new exmpp API where get_id/1, get_lang/1,
get_initiating_entity/1, get_receiving_entity/1 and get_type/1
returns binary().
* src/mod_pubsub/node_default.erl: Fix typo in variable name.
* src/ejabberd_c2s.erl: Fix bug in handle_info/3 when dealing with
VCARD requests: convert to IQ struct before invoking gen_iq_handler.
2009-01-08 Christophe Romain <christophe.romain@process-one.net>
* src/mod_pubsub/mod_pubsub.erl: completely support subscription using

View File

@ -239,9 +239,9 @@ wait_for_stream({xmlstreamstart, #xmlel{ns = NS} = Opening}, StateData) ->
StateData#state.streamid, DefaultLang),
case NS of
?NS_XMPP ->
Server = exmpp_stringprep:nameprep(
ServerB = exmpp_stringprep:nameprep(
exmpp_stream:get_receiving_entity(Opening)),
ServerB = list_to_binary(Server),
Server = binary_to_list(ServerB),
case lists:member(Server, ?MYHOSTS) of
true ->
Lang = exmpp_stream:get_lang(Opening),
@ -900,9 +900,9 @@ session_established2(El, StateData) ->
catch
throw:{stringprep, _, _, _} ->
case exmpp_stanza:get_type(El) of
"error" ->
<<"error">> ->
ok;
"result" ->
<<"result">> ->
ok;
_ ->
Err = exmpp_stanza:reply_with_error(El, 'jid-malformed'),
@ -1166,7 +1166,7 @@ handle_info({route, From, To, Packet}, StateName, StateData) ->
case ets:lookup(sm_iqtable, {?NS_VCARD, Host}) of
[{_, Module, Function, Opts}] ->
gen_iq_handler:handle(Host, Module, Function, Opts,
From, To, Packet);
From, To, exmpp_iq:xmlel_to_iq(Packet));
[] ->
Res = exmpp_iq:error(Packet, 'feature-not-implemented'),
ejabberd_router:route(To, From, Res)
@ -1857,7 +1857,6 @@ resend_subscription_requests(#state{user = UserB,
PendingSubscriptions).
process_unauthenticated_stanza(StateData, El) when ?IS_IQ(El) ->
ServerString = binary_to_list(StateData#state.server),
case exmpp_iq:get_kind(El) of
request ->
IQ_Rec = exmpp_iq:xmlel_to_iq(El),
@ -1873,7 +1872,7 @@ process_unauthenticated_stanza(StateData, El) when ?IS_IQ(El) ->
ResIQ = exmpp_iq:error_without_original(El,
'service-unavailable'),
Res1 = exmpp_stanza:set_sender(ResIQ,
exmpp_jid:make_bare_jid(ServerString)),
exmpp_jid:make_bare_jid(StateData#state.server)),
Res2 = exmpp_stanza:remove_recipient(Res1),
send_element(StateData, Res2);
_ ->

View File

@ -321,8 +321,8 @@ do_route(From, To, Packet) ->
end;
true ->
case exmpp_stanza:get_type(Packet) of
"error" -> ok;
"result" -> ok;
<<"error">> -> ok;
<<"result">> -> ok;
_ ->
ejabberd_hooks:run(local_send_to_resource_hook,
exmpp_jid:ldomain(To),

View File

@ -290,8 +290,8 @@ do_route(From, To, Packet) ->
ok;
{aborted, _Reason} ->
case exmpp_stanza:get_type(Packet) of
"error" -> ok;
"result" -> ok;
<<"error">> -> ok;
<<"result">> -> ok;
_ ->
Err = exmpp_stanza:reply_with_error(Packet,
'service-unavailable'),

View File

@ -803,8 +803,8 @@ send_queue(StateData, Q) ->
%% Bounce a single message (xmlel)
bounce_element(El, Condition) ->
case exmpp_stanza:get_type(El) of
"error" -> ok;
"result" -> ok;
<<"error">> -> ok;
<<"result">> -> ok;
_ ->
Err = exmpp_stanza:reply_with_error(El, Condition),
From = exmpp_jid:binary_to_jid(exmpp_stanza:get_sender(El)),
@ -882,14 +882,14 @@ is_verify_res(#xmlel{ns = ?NS_DIALBACK, name = 'result',
exmpp_stanza:get_recipient_from_attrs(Attrs),
exmpp_stanza:get_sender_from_attrs(Attrs),
exmpp_stanza:get_id_from_attrs(Attrs),
exmpp_stanza:get_type_from_attrs(Attrs)};
binary_to_list(exmpp_stanza:get_type_from_attrs(Attrs))};
is_verify_res(#xmlel{ns = ?NS_DIALBACK, name = 'verify',
attrs = Attrs}) ->
{verify,
exmpp_stanza:get_recipient_from_attrs(Attrs),
exmpp_stanza:get_sender_from_attrs(Attrs),
exmpp_stanza:get_id_from_attrs(Attrs),
exmpp_stanza:get_type_from_attrs(Attrs)};
binary_to_list(exmpp_stanza:get_type_from_attrs(Attrs))};
is_verify_res(_) ->
false.

View File

@ -371,10 +371,10 @@ process_irc_register(Host, From, _To, _DefEnc,
exmpp_iq:error(IQ_Rec, 'not-acceptable');
_ ->
case exmpp_stanza:get_type(XDataEl) of
"cancel" ->
<<"cancel">> ->
Result = #xmlel{ns = XMLNS, name = 'query'},
exmpp_iq:result(IQ_Rec, Result);
"submit" ->
<<"submit">> ->
XData = jlib:parse_xdata_submit(XDataEl),
case XData of
invalid ->

View File

@ -625,7 +625,7 @@ bounce_messages(Reason) ->
receive
{send_element, El} ->
case exmpp_stanza:get_type(El) of
"error" ->
<<"error">> ->
ok;
_ ->
Error = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'error',

View File

@ -401,9 +401,9 @@ do_route1(Host, ServerHost, Access, HistorySize, RoomShaper,
end;
_ ->
case exmpp_stanza:get_type(Packet) of
"error" ->
<<"error">> ->
ok;
"result" ->
<<"result">> ->
ok;
_ ->
Err = exmpp_iq:error(Packet,'item-not-found'),
@ -638,9 +638,9 @@ process_iq_register_set(Host, From, SubEl, Lang) ->
case exmpp_xml:get_child_elements(SubEl) of
[#xmlel{ns= NS, name = 'x'} = XEl] ->
case {NS, exmpp_stanza:get_type(XEl)} of
{?NS_DATA_FORMS, "cancel"} ->
{?NS_DATA_FORMS, <<"cancel">>} ->
ok;
{?NS_DATA_FORMS, "submit"} ->
{?NS_DATA_FORMS, <<"submit">>} ->
XData = jlib:parse_xdata_submit(XEl),
case XData of
invalid ->

View File

@ -966,38 +966,38 @@ is_user_online(JID, StateData) ->
LJID = jlib:short_prepd_jid(JID),
?DICT:is_key(LJID, StateData#state.users).
role_to_list(Role) ->
role_to_binary(Role) ->
case Role of
moderator -> "moderator";
participant -> "participant";
visitor -> "visitor";
none -> "none"
moderator -> <<"moderator">>;
participant -> <<"participant">>;
visitor -> <<"visitor">>;
none -> <<"none">>
end.
affiliation_to_list(Affiliation) ->
affiliation_to_binary(Affiliation) ->
case Affiliation of
owner -> "owner";
admin -> "admin";
member -> "member";
outcast -> "outcast";
none -> "none"
owner -> <<"owner">>;
admin -> <<"admin">>;
member -> <<"member">>;
outcast -> <<"outcast">>;
none -> <<"none">>
end.
list_to_role(Role) ->
binary_to_role(Role) ->
case Role of
"moderator" -> moderator;
"participant" -> participant;
"visitor" -> visitor;
"none" -> none
<<"moderator">> -> moderator;
<<"participant">> -> participant;
<<"visitor">> -> visitor;
<<"none">> -> none
end.
list_to_affiliation(Affiliation) ->
binary_to_affiliation(Affiliation) ->
case Affiliation of
"owner" -> owner;
"admin" -> admin;
"member" -> member;
"outcast" -> outcast;
"none" -> none
<<"owner">> -> owner;
<<"admin">> -> admin;
<<"member">> -> member;
<<"outcast">> -> outcast;
<<"none">> -> none
end.
%% Decide the fate of the message and its sender
@ -1758,8 +1758,8 @@ send_new_presence(NJID, Reason, StateData) ->
last_presence = Presence}} =
?DICT:find(jlib:short_prepd_jid(NJID), StateData#state.users),
Affiliation = get_affiliation(NJID, StateData),
SAffiliation = affiliation_to_list(Affiliation),
SRole = role_to_list(Role),
SAffiliation = affiliation_to_binary(Affiliation),
SRole = role_to_binary(Role),
lists:foreach(
fun({_LJID, Info}) ->
ItemAttrs =
@ -1824,12 +1824,12 @@ send_existing_presences(ToJID, StateData) ->
true ->
[#xmlattr{name = 'jid', value = exmpp_jid:jid_to_list(FromJID)},
#xmlattr{name = 'affiliation',
value = affiliation_to_list(FromAffiliation)},
#xmlattr{name = 'role', value = role_to_list(FromRole)}];
value = affiliation_to_binary(FromAffiliation)},
#xmlattr{name = 'role', value = role_to_binary(FromRole)}];
_ ->
[#xmlattr{name = 'affiliation',
value = affiliation_to_list(FromAffiliation)},
#xmlattr{name = 'role', value = role_to_list(FromRole)}]
value = affiliation_to_binary(FromAffiliation)},
#xmlattr{name = 'role', value = role_to_binary(FromRole)}]
end,
Packet = exmpp_xml:append_child(Presence,
#xmlel{ns = ?NS_MUC_USER, name = 'x',
@ -1871,8 +1871,8 @@ send_nick_changing(JID, OldNick, StateData) ->
last_presence = Presence}} =
?DICT:find(jlib:short_prepd_jid(JID), StateData#state.users),
Affiliation = get_affiliation(JID, StateData),
SAffiliation = affiliation_to_list(Affiliation),
SRole = role_to_list(Role),
SAffiliation = affiliation_to_binary(Affiliation),
SRole = role_to_binary(Role),
lists:foreach(
fun({_LJID, Info}) ->
ItemAttrs1 =
@ -2030,13 +2030,13 @@ process_iq_admin(From, get, Lang, SubEl, StateData) ->
Item ->
FAffiliation = get_affiliation(From, StateData),
FRole = get_role(From, StateData),
case exmpp_xml:get_attribute(Item, 'role', false) of
case exmpp_xml:get_attribute_as_binary(Item, 'role', false) of
false ->
case exmpp_xml:get_attribute(Item, 'affiliation', false) of
case exmpp_xml:get_attribute_as_binary(Item, 'affiliation', false) of
false ->
{error, 'bad-request'};
StrAffiliation ->
case catch list_to_affiliation(StrAffiliation) of
case catch binary_to_affiliation(StrAffiliation) of
{'EXIT', _} ->
{error, 'bad-request'};
SAffiliation ->
@ -2053,7 +2053,7 @@ process_iq_admin(From, get, Lang, SubEl, StateData) ->
end
end;
StrRole ->
case catch list_to_role(StrRole) of
case catch binary_to_role(StrRole) of
{'EXIT', _} ->
{error, 'bad-request'};
SRole ->
@ -2082,9 +2082,9 @@ items_with_affiliation(SAffiliation, StateData) ->
{N, D, R} = JID,
#xmlel{name = 'item',
attrs = [#xmlattr{name = 'affiliation',
value = affiliation_to_list(Affiliation)},
value = affiliation_to_binary(Affiliation)},
#xmlattr{name = 'jid',
value = exmpp_jid:jid_to_list(N, D, R)}],
value = exmpp_jid:jid_to_binary(N, D, R)}],
children = [ #xmlel{name = 'reason',
children = [#xmlcdata{cdata = Reason}]}]};
@ -2092,9 +2092,9 @@ items_with_affiliation(SAffiliation, StateData) ->
{N, D, R} = JID,
#xmlel{name = 'item',
attrs = [#xmlattr{name = 'affiliation',
value = affiliation_to_list(Affiliation)},
value = affiliation_to_binary(Affiliation)},
#xmlattr{name = 'jid',
value = exmpp_jid:jid_to_list(N, D, R)}]}
value = exmpp_jid:jid_to_binary(N, D, R)}]}
end, search_affiliation(SAffiliation, StateData)).
user_to_item(#user{role = Role,
@ -2104,10 +2104,10 @@ user_to_item(#user{role = Role,
Affiliation = get_affiliation(JID, StateData),
#xmlel{name = 'item',
attrs = [
#xmlattr{name = 'role', value = role_to_list(Role)},
#xmlattr{name = 'affiliation', value = affiliation_to_list(Affiliation)},
#xmlattr{name = 'role', value = role_to_binary(Role)},
#xmlattr{name = 'affiliation', value = affiliation_to_binary(Affiliation)},
#xmlattr{name = 'nick', value = Nick},
#xmlattr{name = 'jid', value = exmpp_jid:jid_to_list(JID)}]
#xmlattr{name = 'jid', value = exmpp_jid:jid_to_binary(JID)}]
}.
search_role(Role, StateData) ->
@ -2225,9 +2225,9 @@ find_changed_items(UJID, UAffiliation, URole, [#xmlcdata{} | Items],
find_changed_items(UJID, UAffiliation, URole,
[#xmlel{name = 'item'} = Item | Items],
Lang, StateData, Res) ->
TJID = case exmpp_xml:get_attribute(Item, 'jid',false) of
TJID = case exmpp_xml:get_attribute_as_binary(Item, 'jid',false) of
S when S =/= false ->
try exmpp_jid:list_to_jid(S) of
try exmpp_jid:binary_to_jid(S) of
J ->
{value, J}
catch
@ -2261,13 +2261,13 @@ find_changed_items(UJID, UAffiliation, URole,
{value, JID} ->
TAffiliation = get_affiliation(JID, StateData),
TRole = get_role(JID, StateData),
case exmpp_xml:get_attribute(Item, 'role',false) of
case exmpp_xml:get_attribute_as_binary(Item, 'role',false) of
false ->
case exmpp_xml:get_attribute(Item, 'affiliation', false) of
case exmpp_xml:get_attribute_as_binary(Item, 'affiliation', false) of
false ->
{error, 'bad-request'};
StrAffiliation ->
case catch list_to_affiliation(StrAffiliation) of
case catch binary_to_affiliation(StrAffiliation) of
{'EXIT', _} ->
ErrText1 =
io_lib:format(
@ -2324,7 +2324,7 @@ find_changed_items(UJID, UAffiliation, URole,
end
end;
StrRole ->
case catch list_to_role(StrRole) of
case catch binary_to_role(StrRole) of
{'EXIT', _} ->
ErrText1 =
io_lib:format(
@ -2566,7 +2566,7 @@ send_kickban_presence1(UJID, Reason, Code, StateData) ->
nick = Nick}} = ?DICT:find(UJID, StateData#state.users),
{N,D,R} = UJID,
Affiliation = get_affiliation(exmpp_jid:make_jid(N,D,R), StateData),
SAffiliation = affiliation_to_list(Affiliation),
SAffiliation = affiliation_to_binary(Affiliation),
lists:foreach(
fun({_LJID, Info}) ->
ItemAttrs = [#xmlattr{name = 'affiliation', value = SAffiliation},
@ -2607,10 +2607,10 @@ process_iq_owner(From, set, Lang, SubEl, StateData) ->
owner ->
case exmpp_xml:get_child_elements(SubEl) of
[#xmlel{ns = XMLNS, name = 'x'} = XEl] ->
case {XMLNS, exmpp_xml:get_attribute(XEl, 'type',false)} of
{?NS_DATA_FORMS, "cancel"} ->
case {XMLNS, exmpp_xml:get_attribute_as_binary(XEl, 'type',false)} of
{?NS_DATA_FORMS, <<"cancel">>} ->
{result, [], StateData};
{?NS_DATA_FORMS, "submit"} ->
{?NS_DATA_FORMS, <<"submit">>} ->
case {check_allowed_log_change(XEl, StateData, From),
check_allowed_persistent_change(XEl, StateData, From)} of
{allow, allow} -> set_config(XEl, StateData);
@ -2639,11 +2639,11 @@ process_iq_owner(From, get, Lang, SubEl, StateData) ->
[] ->
get_config(Lang, StateData, From);
[Item] ->
case exmpp_xml:get_attribute(Item, 'affiliation',false) of
case exmpp_xml:get_attribute_as_binary(Item, 'affiliation',false) of
false ->
{error, 'bad-request'};
StrAffiliation ->
case catch list_to_affiliation(StrAffiliation) of
case catch binary_to_affiliation(StrAffiliation) of
{'EXIT', _} ->
ErrText =
io_lib:format(
@ -3227,7 +3227,7 @@ check_invitation(From, Els, Lang, StateData) ->
_ ->
throw({error, 'bad-request'})
end,
JID = try exmpp_jid:list_to_jid(exmpp_xml:get_attribute(InviteEl,
JID = try exmpp_jid:binary_to_jid(exmpp_xml:get_attribute_as_binary(InviteEl,
'to',
false)) of
JID1 -> JID1
@ -3330,8 +3330,8 @@ check_decline_invitation(Packet) ->
#xmlel{name = 'message'} = Packet,
#xmlel{ns = ?NS_MUC_USER} = XEl = exmpp_xml:get_element(Packet, 'x'),
DEl = exmpp_xml:get_element(XEl, 'decline'),
ToString = exmpp_xml:get_attribute(DEl, 'to', false),
ToJID = exmpp_jid:list_to_jid(ToString),
ToString = exmpp_xml:get_attribute_as_binary(DEl, 'to', false),
ToJID = exmpp_jid:binary_to_jid(ToString),
{true, {Packet, XEl, DEl, ToJID}}.
%% Send the decline to the inviter user.

View File

@ -157,8 +157,8 @@ stop(Host) ->
store_packet(From, To, Packet) ->
Type = exmpp_stanza:get_type(Packet),
if
(Type /= "error") and (Type /= "groupchat") and
(Type /= "headline") ->
(Type /= <<"error">>) and (Type /= <<"groupchat">>) and
(Type /= <<"headline">>) ->
case check_event(From, To, Packet) of
true ->
LUser = exmpp_jid:lnode_as_list(To),
@ -197,7 +197,7 @@ check_event(From, To, Packet) ->
S ->
#xmlel{ns = ?NS_MESSAGE_EVENT, name = 'id',
children = [#xmlcdata{cdata =
list_to_binary(S)}]}
S}]}
end,
X = #xmlel{ns = ?NS_MESSAGE_EVENT, name = 'x', children =
[ID, #xmlel{ns = ?NS_MESSAGE_EVENT, name = 'offline'}]},

View File

@ -165,8 +165,8 @@ stop(Host) ->
store_packet(From, To, Packet) ->
Type = exmpp_stanza:get_type(Packet),
if
(Type /= "error") and (Type /= "groupchat") and
(Type /= "headline") ->
(Type /= <<"error">>) and (Type /= <<"groupchat">>) and
(Type /= <<"headline">>) ->
case check_event(From, To, Packet) of
true ->
LUser = exmpp_jid:lnode_as_list(To),

View File

@ -694,9 +694,9 @@ do_route(ServerHost, Access, Plugins, Host, From, To, Packet) ->
end;
_ ->
case exmpp_stanza:get_type(Packet) of
"error" ->
<<"error">> ->
ok;
"result" ->
<<"result">> ->
ok;
_ ->
Err = exmpp_stanza:reply_with_error(Packet,

View File

@ -279,7 +279,7 @@ delete_node(Host, Removed) ->
%% <p>In the default plugin module, the record is unchanged.</p>
subscribe_node(Host, Node, Sender, Subscriber, AccessModel,
SendLast, PresenceSubscription, RosterGroup) ->
SubKey = jlib:short_prepd_jid(Owner),
SubKey = jlib:short_prepd_jid(Subscriber),
GenKey = jlib:short_prepd_bare_jid(SubKey),
Authorized = (jlib:short_prepd_bare_jid(Sender) == GenKey),
GenState = get_state(Host, Node, GenKey),

View File

@ -190,7 +190,7 @@ process_iq_set(From, To, #iq{payload = Request} = IQ_Rec) ->
process_item_set(From, To, #xmlel{} = El) ->
try
JID1 = exmpp_jid:list_to_jid(exmpp_xml:get_attribute(El, 'jid', "")),
JID1 = exmpp_jid:binary_to_jid(exmpp_xml:get_attribute_as_binary(El, 'jid', <<>>)),
User = exmpp_jid:node(From),
LUser = exmpp_jid:lnode(From),
LServer = exmpp_jid:ldomain(From),
@ -596,7 +596,7 @@ set_items(User, Server, #xmlel{children = Els}) ->
process_item_set_t(LUser, LServer, #xmlel{} = El) ->
try
JID1 = exmpp_jid:list_to_jid(exmpp_xml:get_attribute(El, 'jid', "")),
JID1 = exmpp_jid:binary_to_jid(exmpp_xml:get_attribute(El, 'jid', <<>>)),
JID = jlib:short_jid(JID1),
LJID = jlib:short_prepd_jid(JID1),
Item = #roster{usj = {LUser, LServer, LJID},

View File

@ -216,7 +216,7 @@ process_iq_set(From, To, #iq{payload = Request} = IQ_Rec) ->
process_item_set(From, To, #xmlel{} = El) ->
try
JID1 = exmpp_jid:list_to_jid(exmpp_xml:get_attribute(El, 'jid', "")),
JID1 = exmpp_jid:binary_to_jid(exmpp_xml:get_attribute_as_binary(El, 'jid', <<>>)),
LUser = exmpp_jid:lnode_as_list(From),
LServer = exmpp_jid:ldomain_as_list(From),
{U0, S0, R0} = LJID = jlib:short_prepd_jid(JID1),
@ -655,7 +655,7 @@ set_items(User, Server, #xmlel{children = Els}) ->
process_item_set_t(LUser, LServer, #xmlel{} = El) ->
try
JID1 = exmpp_jid:list_to_jid(exmpp_xml:get_attribute(El, 'jid', "")),
JID1 = exmpp_jid:binary_to_jid(exmpp_xml:get_attribute_as_binary(El, 'jid', <<>>)),
{U0, S0, R0} = LJID = jlib:short_prepd_jid(JID1),
Username = ejabberd_odbc:escape(LUser),
SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(U0, S0, R0)),

View File

@ -32,6 +32,8 @@
load_file/2,
translate/2]).
-export([tokens/2, ascii_tolower/1]).
-include("ejabberd.hrl").
start() ->
@ -68,7 +70,8 @@ load_dir(Dir) ->
lists:foreach(
fun(FN) ->
L = ascii_tolower(
string:substr(FN, 1, string:len(FN) - 4)),
list_to_binary(
string:substr(FN, 1, string:len(FN) - 4))),
load_file(L, Dir ++ "/" ++ FN)
end, MsgFiles),
ok;
@ -107,14 +110,14 @@ translate(Lang, Msg) ->
[{_, Trans}] ->
Trans;
_ ->
ShortLang = case string:tokens(LLang, "-") of
ShortLang = case tokens(LLang, $-) of
[] ->
LLang;
[SL | _] ->
SL
end,
case ShortLang of
"en" ->
<<"en">> ->
Msg;
LLang ->
translate(Msg);
@ -132,7 +135,7 @@ translate(Msg) ->
case ?MYLANG of
undefined ->
Msg;
"en" ->
<<"en">> ->
Msg;
Lang ->
LLang = ascii_tolower(Lang),
@ -140,14 +143,14 @@ translate(Msg) ->
[{_, Trans}] ->
Trans;
_ ->
ShortLang = case string:tokens(LLang, "-") of
ShortLang = case tokens(LLang, $-) of
[] ->
LLang;
[SL | _] ->
SL
end,
case ShortLang of
"en" ->
<<"en">> ->
Msg;
Lang ->
Msg;
@ -162,11 +165,25 @@ translate(Msg) ->
end
end.
ascii_tolower([C | Cs]) when C >= $A, C =< $Z ->
[C + ($a - $A) | ascii_tolower(Cs)];
ascii_tolower([C | Cs]) ->
[C | ascii_tolower(Cs)];
ascii_tolower([]) ->
[];
ascii_tolower(undefined) ->
[].
<<>>;
ascii_tolower(Bin) ->
<< <<(char_tolower(X))>> || <<X>> <= Bin >>.
char_tolower(C) when C >= $A, C =< $Z ->
C + ($a -$A);
char_tolower(C) ->
C.
tokens(<<>>,_Sep) ->
[];
tokens(Bin, Sep) ->
tokens(Bin, Sep, <<>>, []).
tokens(<<>>, _Sep, T, Tokens) ->
lists:reverse([T|Tokens]);
tokens(<<Sep, R/binary>>, Sep, T, Tokens) ->
tokens(R, Sep, <<>>, [T | Tokens]);
tokens(<<C, R/binary>>, Sep, T, Tokens) ->
tokens(R, Sep, <<T/binary, C>>, Tokens).