Make mod translatable

master
rubenwardy 2019-11-24 14:42:44 +00:00
parent eae45236b4
commit a02367a81a
7 changed files with 117 additions and 50 deletions

View File

@ -1,6 +1,8 @@
local S = classroom.S
classroom.register_action("bring", {
title = "Bring",
description = "Teleport players to your location",
title = S"Bring",
description = S"Teleport players to your location",
online_required = true,
func = function(runner, players)
local pos = runner:get_pos()
@ -13,8 +15,8 @@ classroom.register_action("bring", {
})
classroom.register_action("look", {
title = "Look",
description = "Make players look at you",
title = S"Look",
description = S"Make players look at you",
online_required = true,
func = function(runner, players)
local pos = runner:get_pos()
@ -28,8 +30,8 @@ classroom.register_action("look", {
})
classroom.register_action("mute", {
title = "Mute",
description = "Revoke shout from players",
title = S"Mute",
description = S"Revoke shout from players",
online_required = false,
func = function(runner, players)
for _, name in pairs(players) do
@ -42,8 +44,8 @@ classroom.register_action("mute", {
})
classroom.register_action("unmute", {
title = "Unmute",
description = "Grant shout to players",
title = S"Unmute",
description = S"Grant shout to players",
online_required = false,
func = function(runner, players)
for _, name in pairs(players) do
@ -55,8 +57,8 @@ classroom.register_action("unmute", {
})
classroom.register_action("fly", {
title = "Fly",
description = "Grant fly to players",
title = S"Fly",
description = S"Grant fly to players",
online_required = false,
func = function(runner, players)
for _, name in pairs(players) do
@ -68,8 +70,8 @@ classroom.register_action("fly", {
})
classroom.register_action("nofly", {
title = "NoFly",
description = "Revoke fly from players",
title = S"NoFly",
description = S"Revoke fly from players",
online_required = false,
func = function(runner, players)
for _, name in pairs(players) do

113
gui.lua
View File

@ -1,16 +1,18 @@
local S = classroom.S
local FS = classroom.FS
local infos = {
{
title = "Shout?",
title = S"Shout?",
type = "priv",
privs = { shout = true },
},
{
title = "Fly?",
title = S"Fly?",
type = "priv",
privs = { fly = true },
},
{
title = "Fast?",
title = S"Fast?",
type = "priv",
privs = { fast = true },
},
@ -25,7 +27,7 @@ local function get_group(context)
end
sfinv.register_page("classroom:edu", {
title = "Classroom",
title = S"Classroom",
check_perm = function(self, player)
return minetest.check_player_privs(player:get_player_name(), { teacher = true })
end,
@ -34,7 +36,7 @@ sfinv.register_page("classroom:edu", {
end,
get = function(self, player, context)
if not self:check_perm(player) then
return "label[0,0;Access denied]"
return "label[0,0;" .. FS"Access denied" .. "]"
end
local fs = {
@ -52,7 +54,8 @@ sfinv.register_page("classroom:edu", {
fs[#fs + 1] = "]"
do
fs[#fs + 1] = "tabheader[0.3,1.1;group;All"
fs[#fs + 1] = "tabheader[0.3,1.1;group;"
fs[#fs + 1] = FS"All"
local selected_group_idx = 1
local i = 2
for name, group in pairs(classroom.get_all_groups()) do
@ -88,7 +91,7 @@ sfinv.register_page("classroom:edu", {
if col.type == "priv" then
local has_priv = minetest.check_player_privs(student, col.privs)
color = has_priv and "green" or "red"
value = has_priv and "Yes" or "No"
value = has_priv and FS"Yes" or FS"No"
end
fs[#fs + 1] = ","
@ -102,46 +105,78 @@ sfinv.register_page("classroom:edu", {
fs[#fs + 1] = selection_id
fs[#fs + 1] = "]"
fs[#fs + 1] = "button[5.25,-0.2;1.4,1;new_group;New Group]"
fs[#fs + 1] = "button[5.25,-0.2;1.4,1;new_group;"
fs[#fs + 1] = FS"New Group"
fs[#fs + 1] = "]"
if context.groupname then
fs[#fs + 1] = "button[6.65,-0.2;1.4,1;edit_group;Edit Group]"
fs[#fs + 1] = "button[6.65,-0.2;1.4,1;edit_group;"
fs[#fs + 1] = FS"Edit Group"
fs[#fs + 1] = "]"
else
fs[#fs + 1] = "box[6.65,-0.1;1.2,0.7;#222]"
fs[#fs + 1] = "label[6.8,0.05;Edit Group]"
fs[#fs + 1] = "tooltip[6.65,-0.2;1.4,1;Please select a group first]"
fs[#fs + 1] = "label[6.8,0.05;"
fs[#fs + 1] = FS"Edit Group"
fs[#fs + 1] = "]"
fs[#fs + 1] = "tooltip[6.65,-0.2;1.4,1;"
fs[#fs + 1] = FS"Please select a group first"
fs[#fs + 1] = "]"
end
fs[#fs + 1] = "container[5.25,1.1]"
fs[#fs + 1] = "box[-0.25,-0.3;3.1,1.15;#666]"
fs[#fs + 1] = "label[0,-0.3;Run actions on:]"
fs[#fs + 1] = "label[0,-0.3;"
fs[#fs + 1] = FS"Run actions on:"
fs[#fs + 1] = "]"
if context.select_toggle == "all" then
fs[#fs + 1] = "box[0,0.1;0.8,0.7;#53ac56]"
fs[#fs + 1] = "label[0.3,0.25;All]"
fs[#fs + 1] = "label[0.3,0.25;"
fs[#fs + 1] = FS"All"
fs[#fs + 1] = "]"
else
fs[#fs + 1] = "button[0,0;1,1;select_all;All]"
fs[#fs + 1] = "button[0,0;1,1;select_all;"
fs[#fs + 1] = FS"All"
fs[#fs + 1] = "]"
end
if not context.groupname then
fs[#fs + 1] = "box[0.9,0.1;0.8,0.7;#333]"
fs[#fs + 1] = "label[1.05,0.25;Group]"
fs[#fs + 1] = "tooltip[0.9,0;1,1;Please select a group first]"
fs[#fs + 1] = "label[1.05,0.25;"
fs[#fs + 1] = FS"Group"
fs[#fs + 1] = "]"
fs[#fs + 1] = "tooltip[0.9,0;1,1;"
fs[#fs + 1] = FS"Please select a group first"
fs[#fs + 1] = "]"
elseif context.select_toggle == "group" then
fs[#fs + 1] = "box[0.9,0.1;0.8,0.7;#53ac56]"
fs[#fs + 1] = "label[1.05,0.25;Group]"
fs[#fs + 1] = "label[1.05,0.25;"
fs[#fs + 1] = FS"Group"
fs[#fs + 1] = "]"
else
fs[#fs + 1] = "button[0.9,0;1,1;select_group;Group]"
fs[#fs + 1] = "button[0.9,0;1,1;select_group;"
fs[#fs + 1] = FS"Group"
fs[#fs + 1] = "]"
end
if not context.selected_student then
fs[#fs + 1] = "box[1.8,0.1;0.8,0.7;#333]"
fs[#fs + 1] = "label[1.85,0.25;Selected]"
fs[#fs + 1] = "tooltip[1.8,0;1,1;Please select a student first]"
fs[#fs + 1] = "label[1.85,0.25;"
fs[#fs + 1] = FS"Selected"
fs[#fs + 1] = "]"
fs[#fs + 1] = "tooltip[1.8,0;1,1;"
fs[#fs + 1] = FS"Please select a student first"
fs[#fs + 1] = "]"
elseif context.select_toggle == "selected" then
fs[#fs + 1] = "box[1.8,0.1;0.8,0.7;#53ac56]"
fs[#fs + 1] = "label[1.85,0.25;Selected]"
fs[#fs + 1] = "label[1.85,0.25;"
fs[#fs + 1] = FS"Selected"
fs[#fs + 1] = "]"
else
fs[#fs + 1] = "button[1.8,0;1,1;select_selected;Selected]"
fs[#fs + 1] = "button[1.8,0;1,1;select_selected;"
fs[#fs + 1] = FS"Selected"
fs[#fs + 1] = "]"
end
fs[#fs + 1] = "label[0,0.9;Actions]"
fs[#fs + 1] = "label[0,0.9;"
fs[#fs + 1] = FS"Actions:"
fs[#fs + 1] = "]"
local x = 0
local y = 1.2
@ -177,10 +212,12 @@ sfinv.register_page("classroom:edu", {
fs[#fs + 1] = tostring(y)
fs[#fs + 1] = "]"
fs[#fs + 1] = "label[0,-0.1;Selected user: "
fs[#fs + 1] = minetest.formspec_escape(context.selected_student)
fs[#fs + 1] = "label[0,-0.1;"
fs[#fs + 1] = FS("Selected user: @1", context.selected_student)
fs[#fs + 1] = "]"
fs[#fs + 1] = "button[0,0.3;1.5,1;teleport;"
fs[#fs + 1] = FS"Teleport to"
fs[#fs + 1] = "]"
fs[#fs + 1] = "button[0,0.3;1.5,1;teleport;Teleport To]"
fs[#fs + 1] = "container_end[]"
end
@ -303,11 +340,11 @@ function classroom.show_new_group(player)
return
end
minetest.show_formspec(player:get_player_name(), "classroom:new_group", [[
size[5,1.8]
field[0.2,0.4;5,1;name;Name;]
button[1.5,1;2,1;create;Create]
]])
minetest.show_formspec(player:get_player_name(), "classroom:new_group", table.concat({
"size[5,1.8]",
"field[0.2,0.4;5,1;name;", FS"Name", ";]",
"button[1.5,1;2,1;create;", FS"Create", "]",
}, ""))
end
@ -344,8 +381,10 @@ function classroom.show_edit_group(player, groupname)
local fs = {
"size[5.55,6]",
"label[0,-0.1;Other students]",
"label[3.3,-0.1;Students in group ", minetest.formspec_escape(context.groupname), "]",
"label[0,-0.1;", FS"Other students", "]",
"label[3.3,-0.1;",
FS("Students in group @1", context.groupname),
"]",
"button[2.25,0.5;1,1;go_right;", minetest.formspec_escape(">"), "]",
"button[2.25,1.5;1,1;go_left;", minetest.formspec_escape("<"), "]",
}
@ -367,7 +406,9 @@ function classroom.show_edit_group(player, groupname)
fs[#fs + 1] = tostring(context.index_r)
fs[#fs + 1] = "]"
else
fs[#fs + 1] = "label[3.5,0.7;No students]"
fs[#fs + 1] = "label[3.5,0.7;"
fs[#fs + 1] = FS("No students")
fs[#fs + 1] = "]"
end
local not_members = classroom.get_students_except(members)
@ -389,7 +430,9 @@ function classroom.show_edit_group(player, groupname)
fs[#fs + 1] = tostring(context.index_l)
fs[#fs + 1] = "]"
else
fs[#fs + 1] = "label[0.4,0.7;No students]"
fs[#fs + 1] = "label[0.4,0.7;"
fs[#fs + 1] = FS("No students")
fs[#fs + 1] = "]"
end
minetest.show_formspec(player:get_player_name(), "classroom:edit_group", table.concat(fs, ""))

View File

@ -1,5 +1,10 @@
classroom = {}
classroom.S = minetest.get_translator("classroom")
classroom.FS = function(...)
return minetest.formspec_escape(classroom.S(...))
end
dofile(minetest.get_modpath("classroom") .. "/api.lua")
dofile(minetest.get_modpath("classroom") .. "/gui.lua")
dofile(minetest.get_modpath("classroom") .. "/actions.lua")
@ -8,6 +13,7 @@ minetest.register_privilege("teacher", {
give_to_singleplayer = false
})
-- Hooks needed to make api.lua testable
classroom.get_connected_players = minetest.get_connected_players
classroom.get_player_by_name = minetest.get_player_by_name
classroom.check_player_privs = minetest.check_player_privs

View File

@ -8,6 +8,7 @@ end
local function recreate_classroom()
_G.classroom = {
S = string.format,
get_connected_players = function()
return {
fake_player("user1"),

4
utils/client.conf Normal file
View File

@ -0,0 +1,4 @@
max_fps = 5
screen_h = 30
screen_w = 30
enable_shaders = false

2
utils/server.conf Normal file
View File

@ -0,0 +1,2 @@
name = teacher1
port = 30000

View File

@ -10,9 +10,17 @@ find_minetest() {
echo "Found minetest at: $MT_DIR"
}
set_conf() {
# Make readonly config
conf=/tmp/$1.conf
chmod 0644 $conf # incase it already exists
cp utils/$1.conf /tmp/$1.conf
chmod 0444 $conf
}
start_server() {
echo "Starting server"
$MT --server --port 30000 --world "${MT_DIR}/worlds/edu" --name "teacher1" &
$MT --server --port 30000 --world "${MT_DIR}/worlds/edu" --name "teacher1" --config "$conf" &
}
start_client() {
@ -22,15 +30,16 @@ start_client() {
start_headless_client() {
echo "Starting headless client $1"
xvfb-run $MT --address "127.0.0.1" --name $1 --password "pass" --go &
xvfb-run $MT --address "127.0.0.1" --name $1 --password "pass" --config "$conf" --go &
}
find_minetest
build_conf
set_conf server
start_server
set_conf client
start_headless_client student1
start_headless_client student2
start_headless_client student3