Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F627820
setlang.lua
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
setlang.lua
View Options
--[[
mattata v2.0 - Set Language Plugin
Allows users to select their preferred language via inline keyboard.
]]
local
plugin
=
{}
plugin
.
name
=
'setlang'
plugin
.
category
=
'utility'
plugin
.
description
=
'Set your preferred language'
plugin
.
commands
=
{
'setlang'
,
'language'
,
'lang'
}
plugin
.
help
=
'/setlang - Select your preferred language from the available options.'
local
LANG_NAMES
=
{
en_gb
=
'English (GB)'
,
en_us
=
'English (US)'
,
de_de
=
'Deutsch'
,
de_at
=
'Deutsch (AT)'
,
ar_ar
=
'العربية'
,
pl_pl
=
'Polski'
,
pt_br
=
'Português (BR)'
,
pt_pt
=
'Português (PT)'
,
tr_tr
=
'Türkçe'
,
scottish
=
'Scottish'
}
function
plugin
.
on_message
(
api
,
message
,
ctx
)
local
i18n
=
require
(
'src.core.i18n'
)
local
available
=
i18n
.
available
()
-- Build keyboard with 2 languages per row
local
keyboard
=
api
.
inline_keyboard
()
local
current_row
=
nil
for
i
,
code
in
ipairs
(
available
)
do
if
(
i
-
1
)
%
2
==
0
then
current_row
=
api
.
row
()
end
local
label
=
LANG_NAMES
[
code
]
or
code
current_row
:
callback_data_button
(
label
,
'setlang:set:'
..
code
)
if
i
%
2
==
0
or
i
==
#
available
then
keyboard
:
row
(
current_row
)
end
end
return
api
.
send_message
(
message
.
chat
.
id
,
'Select your preferred language:'
,
{
reply_markup
=
keyboard
}
)
end
function
plugin
.
on_callback_query
(
api
,
callback_query
,
message
,
ctx
)
local
data
=
callback_query
.
data
local
code
=
data
:
match
(
'^set:(.+)$'
)
if
not
code
then
return
end
local
i18n
=
require
(
'src.core.i18n'
)
if
not
i18n
.
exists
(
code
)
then
return
api
.
answer_callback_query
(
callback_query
.
id
,
{
text
=
'Language not available.'
})
end
ctx
.
session
.
set_setting
(
callback_query
.
from
.
id
,
'language'
,
code
,
0
)
local
name
=
LANG_NAMES
[
code
]
or
code
api
.
answer_callback_query
(
callback_query
.
id
,
{
text
=
'Language set to '
..
name
..
'!'
})
return
api
.
edit_message_text
(
message
.
chat
.
id
,
message
.
message_id
,
string.format
(
'Language set to <b>%s</b>.'
,
name
),
{
parse_mode
=
'html'
}
)
end
return
plugin
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 15, 2:48 AM (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
132943
Default Alt Text
setlang.lua (2 KB)
Attached To
Mode
R69 mattata
Attached
Detach File
Event Timeline