Add intllib support

Tested with MT/MTG 5.0.1 and works fine.
If there is any typo/bug/error, please tell me, so, I can fix it.
This commit is contained in:
Panquesito7 2019-07-15 13:52:31 -05:00 committed by GitHub
parent 4986742a24
commit 736512ee3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 362 additions and 43 deletions

@ -60,6 +60,7 @@ These are the following commands available in-game:
There are no dependencies.
However, optional dependencies are:
- [areas](https://github.com/minetest-mods/areas)
- [intllib](https://github.com/minetest-mods/intllib)
## License
See license [here](https://github.com/ChaosWormz/teleport-request/blob/master/LICENSE.md).

@ -1 +1,2 @@
areas?
intllib?

@ -5,6 +5,10 @@ Updates by Zeno and ChaosWormz
New release by RobbieF under new mod: tps_teleport - http://blog.minetest.tv/teleport-request/
--]]
-- Load support for intllib.
local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua")
local timeout_delay = 60
local version = "1.5"
@ -18,18 +22,18 @@ local function can_teleport(to)
end
minetest.register_privilege("tp", {
description = "Let players teleport to other players (request will be sent)",
description = S("Let players teleport to other players (request will be sent)"),
give_to_singleplayer = false,
give_to_admin = true,
})
minetest.register_privilege("tp_admin", {
description = "Admin overrides for tps_teleport.",
description = S("Gives full admin-access to a player."),
give_to_singleplayer = false,
give_to_admin = true,
})
minetest.register_privilege("tp_tpc", {
description = "Allow player to teleport to coordinates (if allowed by area protection).",
description = S("Allow player to teleport to coordinates (if allowed by area protection)"),
give_to_singleplayer = true,
give_to_admin = true,
})
@ -84,30 +88,30 @@ function tpr_send(sender, receiver)
end
end, sender)
if receiver == "" then
minetest.chat_send_player(sender, "Usage: /tpr <Player name>")
minetest.chat_send_player(sender, S("Usage: /tpr <Player name>"))
return
end
if not minetest.get_player_by_name(receiver) then
minetest.chat_send_player(sender, "There is no player by that name. Keep in mind this is case-sensitive, and the player must be online")
minetest.chat_send_player(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online"))
return
end
tpr_accept(receiver)
minetest.chat_send_player(sender, "You are teleporting to " .. receiver .. ".")
minetest.chat_send_player(sender, S("You are teleporting to @1.", receiver))
return
end
if receiver == "" then
minetest.chat_send_player(sender, "Usage: /tpr <Player name>")
minetest.chat_send_player(sender, S("Usage: /tpr <Player name>"))
return
end
if not minetest.get_player_by_name(receiver) then
minetest.chat_send_player(sender, "There is no player by that name. Keep in mind this is case-sensitive, and the player must be online.")
minetest.chat_send_player(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online."))
return
end
minetest.chat_send_player(receiver, sender ..' is requesting to teleport to you. /tpy to accept.')
minetest.chat_send_player(sender, 'Teleport request sent! It will timeout in '.. timeout_delay ..' seconds.')
minetest.chat_send_player(receiver, S("@1 is requesting to teleport to you. /tpy to accept", sender))
minetest.chat_send_player(sender, S("Teleport request sent! It will timeout in @1 seconds", timeout_delay))
-- Write name values to list and clear old values.
if not minetest.check_player_privs(sender, {tp_admin = true}) then
@ -132,29 +136,29 @@ function tphr_send(sender, receiver)
end
end, sender)
if receiver == "" then
minetest.chat_send_player(sender, "Usage: /tphr <Player name>")
minetest.chat_send_player(sender, S("Usage: /tphr <Player name>"))
return
end
if not minetest.get_player_by_name(receiver) then
minetest.chat_send_player(sender, "There is no player by that name. Keep in mind this is case-sensitive, and the player must be online")
minetest.chat_send_player(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online"))
return
end
tpr_accept(receiver)
minetest.chat_send_player(sender, receiver .. " is teleporting to you.")
minetest.chat_send_player(sender, S("@1 is teleporting to you.", receiver))
return
end
if receiver == "" then
minetest.chat_send_player(sender, "Usage: /tphr <Player name>")
minetest.chat_send_player(sender, S("Usage: /tphr <Player name>"))
return
end
if not minetest.get_player_by_name(receiver) then
minetest.chat_send_player(sender, "There is no player by that name. Keep in mind this is case-sensitive, and the player must be online.")
minetest.chat_send_player(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online."))
return
end
minetest.chat_send_player(receiver, sender ..' is requesting that you teleport to them. /tpy to accept; /tpn to deny')
minetest.chat_send_player(sender, 'Teleport request sent! It will timeout in '.. timeout_delay ..' seconds.')
minetest.chat_send_player(receiver, S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny", sender))
minetest.chat_send_player(sender, S("Teleport request sent! It will timeout in @1 seconds ", timeout_delay))
-- Write name values to list and clear old values.
if not minetest.check_player_privs(sender, {tp_admin = true}) then
@ -180,14 +184,14 @@ function tpc_send(player, coordinates)
end
if posx==nil or posy==nil or posz==nil or string.len(posx) > 6 or string.len(posy) > 6 or string.len(posz) > 6 then
minetest.chat_send_player(player, "Usage: /tpc <x, y, z>")
minetest.chat_send_player(player, S("Usage: /tpc <x, y, z>"))
return nil
end
local target_coords = {x=posx, y=posy, z=posz}
if can_teleport(target_coords) == false then
minetest.chat_send_player("You cannot teleport to a location outside the map!")
minetest.chat_send_player(player, S("You cannot teleport to a location outside the map!"))
return nil
end
@ -195,7 +199,7 @@ function tpc_send(player, coordinates)
-- In future release we'll actually query the player who owns the area, if they're online, and ask for their permission.
-- Admin user (priv "tp_admin") overrides all protection
if minetest.check_player_privs(pname, {tp_admin=true}) then
minetest.chat_send_player(player, 'Teleporting to '..posx..','..posy..','..posz)
minetest.chat_send_player(player, S("Teleporting to: @1, @2, @3", posx, posy, posz))
pname:set_pos(find_free_position_near(target_coords))
minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
--parti2(target_coords)
@ -205,16 +209,16 @@ function tpc_send(player, coordinates)
if protected and minetest.get_modpath("areas") then
if not areas:canInteract(target_coords, player) then
local owners = areas:getNodeOwners(target_coords)
minetest.chat_send_player(player,("Error: %s is protected by %s."):format(minetest.pos_to_string(target_coords),table.concat(owners, ", ")))
minetest.chat_send_player(player, S("Error: @1 is protected by @2.", minetest.pos_to_string(target_coords), table.concat(owners, ", ")))
return
end
end
minetest.chat_send_player(player, 'Teleporting to '..posx..','..posy..','..posz)
minetest.chat_send_player(player, S("Teleporting to: @1, @2, @3", posx, posy, posz))
pname:set_pos(find_free_position_near(target_coords))
minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
--parti2(target_coords)
else
minetest.chat_send_player(player, "Error: You do not have permission to teleport to coordinates.")
minetest.chat_send_player(player, S("Error: You do not have permission to teleport to coordinates."))
return
end
end
@ -222,11 +226,11 @@ end
function tpr_deny(name)
if tpr_list[name] then
minetest.chat_send_player(tpr_list[name], 'Teleport request denied.')
minetest.chat_send_player(tpr_list[name], S("Teleport request denied."))
tpr_list[name] = nil
end
if tphr_list[name] then
minetest.chat_send_player(tphr_list[name], 'Teleport request denied.')
minetest.chat_send_player(tphr_list[name], S("Teleport request denied."))
tphr_list[name] = nil
end
end
@ -236,7 +240,7 @@ function tpr_accept(name, param)
-- Check to prevent constant teleporting.
if not tpr_list[name]
and not tphr_list[name] then
minetest.chat_send_player(name, "Usage: /tpy allows you to accept teleport requests sent to you by other players.")
minetest.chat_send_player(name, S("Usage: /tpy allows you to accept teleport requests sent to you by other players"))
return
end
@ -246,13 +250,13 @@ function tpr_accept(name, param)
name2 = tpr_list[name]
source = minetest.get_player_by_name(name)
target = minetest.get_player_by_name(name2)
chatmsg = name2 .. " is teleporting to you."
chatmsg = S("@1 is teleporting to you.", name2)
tpr_list[name] = nil
elseif tphr_list[name] then
name2 = tphr_list[name]
source = minetest.get_player_by_name(name2)
target = minetest.get_player_by_name(name)
chatmsg = "You are teleporting to " .. name2 .. "."
chatmsg = S("You are teleporting to @1.", name2)
tphr_list[name] = nil
else
return
@ -264,7 +268,7 @@ function tpr_accept(name, param)
return
end
minetest.chat_send_player(name2, "Request Accepted!")
minetest.chat_send_player(name2, S("Request Accepted!"))
minetest.chat_send_player(name, chatmsg)
local target_coords = source:get_pos()
@ -278,13 +282,13 @@ function tpj(player, param)
local pname = minetest.get_player_by_name(player)
if param == "" then
minetest.chat_send_player(player, "Usage. <x|y|z> <Number>")
minetest.chat_send_player(player, S("Usage: <x|y|z> <Number>"))
return false
end
local args = param:split(" ") -- look into this. Can it crash if the player does not have two parameters?
if #args < 2 then
minetest.chat_send_player(player, "Usage. <x|y|z> <Number>")
minetest.chat_send_player(player, S("Usage: <x|y|z> <Number>"))
return false
end
@ -301,11 +305,11 @@ function tpj(player, param)
elseif args[1] == "z" then
target_coords["z"] = target_coords["z"] + tonumber(args[2])
else
minetest.chat_send_player(player, "Not a valid axis. Valid options are X, Y or Z.")
minetest.chat_send_player(player, S("Not a valid axis. Valid options are X, Y or Z."))
return
end
if can_teleport(target_coords) == false then
minetest.chat_send_player(player, "You cannot teleport to a location outside the map!")
minetest.chat_send_player(player, S("You cannot teleport to a location outside the map!"))
return
end
pname:set_pos(find_free_position_near(target_coords))
@ -315,7 +319,7 @@ end
-- Evade
function tpe(player)
minetest.chat_send_player(player, "EVADE!")
minetest.chat_send_player(player, S("EVADE!"))
local mindistance = 15
local maxdistance = 50
local times = math.random(6,20) -- how many times to jump - minimum,maximum
@ -342,50 +346,52 @@ end
-- Register chatcommands
minetest.register_chatcommand("tpr", {
description = "Request teleport to another player",
description = S("Request teleport to another player"),
params = "<playername> | leave playername empty to see help message",
privs = {interact = true, tp = true},
func = tpr_send
})
minetest.register_chatcommand("tphr", {
description = "Request player to teleport to you",
description = S("Request player to teleport to you"),
params = "<playername> | leave playername empty to see help message",
privs = {interact = true, tp = true},
func = tphr_send
})
minetest.register_chatcommand("tpc", {
description = "Teleport to coordinates",
description = S("Teleport to coordinates"),
params = "<coordinates> | leave coordinates empty to see help message",
privs = {interact = true, tp_tpc = true, tp = true},
func = tpc_send
})
minetest.register_chatcommand("tpj", {
description = "Teleport to relative position",
description = S("Teleport to relative position"),
params = "<axis> <distance> | leave empty to see help message",
privs = {interact = true, tp_tpc = true, tp = true},
func = tpj
})
minetest.register_chatcommand("tpe", {
description = "Evade Enemy",
description = S("Evade Enemy"),
privs = {interact = true, tp_tpc = true, tp = true},
func = tpe
})
minetest.register_chatcommand("tpy", {
description = "Accept teleport requests from another player",
description = S("Accept teleport requests from another player"),
privs = {interact = true, tp = true},
func = tpr_accept
})
minetest.register_chatcommand("tpn", {
description = "Deny teleport requests from another player",
description = S("Deny teleport requests from another player"),
privs = {interact = true, tp = true},
func = tpr_deny
})
-- Log
minetest.log("info", "[Teleport Request] TPS Teleport v" .. version .. " Loaded.")
if minetest.settings:get_bool("log_mods") then
minetest.log("info", "[Teleport Request] TPS Teleport v" .. version .. " Loaded.")
end

45
intllib.lua Normal file

@ -0,0 +1,45 @@
-- Fallback functions for when `intllib` is not installed.
-- Code released under Unlicense <http://unlicense.org>.
-- Get the latest version of this file at:
-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua
local function format(str, ...)
local args = { ... }
local function repl(escape, open, num, close)
if escape == "" then
local replacement = tostring(args[tonumber(num)])
if open == "" then
replacement = replacement..close
end
return replacement
else
return "@"..open..num..close
end
end
return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl))
end
local gettext, ngettext
if minetest.get_modpath("intllib") then
if intllib.make_gettext_pair then
-- New method using gettext.
gettext, ngettext = intllib.make_gettext_pair()
else
-- Old method using text files.
gettext = intllib.Getter()
end
end
-- Fill in missing functions.
gettext = gettext or function(msgid, ...)
return format(msgid, ...)
end
ngettext = ngettext or function(msgid, msgid_plural, n, ...)
return format(n==1 and msgid or msgid_plural, ...)
end
return gettext, ngettext

133
locale/es.po Normal file

@ -0,0 +1,133 @@
# Spanish translation for Teleport Request.
# Copyright (C) 2015-2019 Michael Tomaino and contributors.
# This file is distributed under under the same license as the Teleport Request package.
# Panquesito7, 2019.
msgid ""
msgstr ""
"Project-Id-Version: Teleport Request\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-07-12 5:07+0200\n"
"PO-Revision-Date: \n"
"Last-Translator: FULL NAME EMAIL@ADDRESS\n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: init.lua:19
msgid "Let players teleport to other players (request will be sent)"
msgstr "Permite que los jugadores se teletransporten a otros jugadores (se enviará una solicitud)"
#: init.lua:43
msgid "Gives full admin-access to a player."
msgstr "Da acceso total de administrador a un jugador."
#: init.lua:50
msgid "Allow player to teleport to coordinates (if allowed by area protection)"
msgstr "Permite a los jugadores teletransportarse a las coordenadas especificadas (si esta permitido por la protección de la área)"
#: init.lua:105
msgid "You are teleporting to @1."
msgstr "Te estas teletransportando a @1."
#: init.lua:111
msgid "Usage: /tpr <Player name>"
msgstr "Uso: /tpr <jugador>"
#: init.lua:116
msgid "There is no player by that name. Keep in mind this is case-sensitive, and the player must be online"
msgstr "No hay jugador con ese nombre. Tenga en cuenta que esto es caso-sensitivo, y el jugador debe de estar én linea."
#: init.lua:120
msgid "@1 is requesting to teleport to you. /tpy to accept"
msgstr "@1 esta pidiendo teletransportarse a ti. /tpy para aceptar"
#: init.lua:121
msgid "Teleport request sent! It will timeout in @1 seconds"
msgstr "¡Solicitud enviada! Se agotara en @1 segundos"
#: init.lua:147
msgid "@1 is teleporting to you."
msgstr "@1 se esta teletransportando a ti."
#: init.lua:152
msgid "Usage: /tphr <Player name>"
msgstr "Uso: /tphr <jugador>"
#: init.lua:160
msgid "@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny"
msgstr "@1 esta pidiendo que tu te teletransportes a el/ella. /tpy para aceptar, /tpn para denegar"
#: init.lua:187
msgid "Usage: /tpc <x, y, z>"
msgstr "Uso: /tpc <x, y, z>"
#: init.lua:194
msgid "You cannot teleport to a location outside the map!"
msgstr "No puedes teletransportarte afuera del mundo!"
#: init.lua:204
msgid "Teleporting to: @1, @2, @3"
msgstr "Teletransportandose a: @1, @2, @3"
#: init.lua:215
msgid "Error: @1 is protected by @2."
msgstr "Error: @1 esta protegido por @2."
#: init.lua:240
msgid "Error: You do not have permission to teleport to those coordinates."
msgstr "Error: No tienes permiso para teletransportarte a esas coordenadas."
#: init.lua:258
msgid "Teleport request denied."
msgstr "Solicitud denegada."
#: init.lua:278
msgid "Usage: /tpy allows you to accept teleport requests sent to you by other players"
msgstr "Uso: /tpy te permite aceptar solicitudes enviadas para ti de otros jugadores"
#: init.lua:317
msgid "Request Accepted!"
msgstr "Solicitud aceptada!"
#: init.lua:330
msgid "Usage: <x|y|z> <number>"
msgstr "Uso: <x|y|z> <numero>"
#: init.lua:353
msgid "Not a valid axis. Valid options are X, Y or Z"
msgstr "Eje invalido. Opciones validas son x, y, o z"
#: init.lua:367
msgid "EVADE!"
msgstr "¡EVADIR!"
#: init.lua:394
msgid "Request teleport to another player."
msgstr "Enviar solicitud para teletransportarte a otro jugador."
#: init.lua:401
msgid "Request player to teleport to you"
msgstr "Solicita al jugador que se teletransporte a ti."
#: init.lua:408
msgid "Teleport to coordinates"
msgstr "Teletransportarse a las coordenadas especificadas."
#: init.lua:415
msgid "Teleport to relative position"
msgstr "Teletransportarse a la posición relativa."
#: init.lua:422
msgid "Evade Enemy"
msgstr "Evadir enemigo."
#: init.lua:428
msgid "Accept teleport requests from another player"
msgstr "Aceptar solicitudes de otro jugador."
#: init.lua:434
msgid "Deny teleport requests from another player"
msgstr "Denegar solicitudos de otro jugador."

133
locale/template.pot Normal file

@ -0,0 +1,133 @@
# Template translation for Teleport Request.
# Copyright (C) 2015-2019 Michael Tomaino and contributors.
# This file is distributed under under the same license as the Teleport Request package.
# Panquesito7, 2019.
msgid ""
msgstr ""
"Project-Id-Version: Teleport Request\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-07-12 5:07+0200\n"
"PO-Revision-Date: \n"
"Last-Translator: FULL NAME EMAIL@ADDRESS\n"
"Language-Team: \n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: init.lua:19
msgid "Let players teleport to other players (request will be sent)"
msgstr ""
#: init.lua:43
msgid "Gives full admin-access to a player."
msgstr ""
#: init.lua:50
msgid "Allow player to teleport to coordinates (if allowed by area protection)"
msgstr ""
#: init.lua:105
msgid "You are teleporting to @1."
msgstr ""
#: init.lua:111
msgid "Usage: /tpr <Player name>"
msgstr ""
#: init.lua:116
msgid "There is no player by that name. Keep in mind this is case sensitive, and the player must be online"
msgstr ""
#: init.lua:120
msgid "@1 is requesting to teleport to you. /tpy to accept"
msgstr ""
#: init.lua:121
msgid "Teleport request sent! It will timeout in @1 seconds"
msgstr ""
#: init.lua:147
msgid "@1 is teleporting to you."
msgstr ""
#: init.lua:152
msgid "Usage: /tphr <Player name>"
msgstr ""
#: init.lua:160
msgid "@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny"
msgstr ""
#: init.lua:187
msgid "Usage: /tpc <x, y, z>"
msgstr ""
#: init.lua:194
msgid "You cannot teleport to a location outside the map!"
msgstr ""
#: init.lua:204
msgid "Teleporting to: @1, @2, @3"
msgstr ""
#: init.lua:215
msgid "Error: @1 is protected by @2."
msgstr ""
#: init.lua:240
msgid "Error: You do not have permission to teleport to those coordinates."
msgstr ""
#: init.lua:258
msgid "Teleport request denied."
msgstr ""
#: init.lua:278
msgid "Usage: /tpy allows you to accept teleport requests sent to you by other players"
msgstr ""
#: init.lua:317
msgid "Request Accepted!"
msgstr ""
#: init.lua:330
msgid "Usage: <x|y|z> <number>"
msgstr ""
#: init.lua:353
msgid "Not a valid axis. Valid options are X, Y or Z"
msgstr ""
#: init.lua:367
msgid "EVADE!"
msgstr ""
#: init.lua:394
msgid "Request teleport to another player."
msgstr ""
#: init.lua:401
msgid "Request player to teleport to you"
msgstr ""
#: init.lua:408
msgid "Teleport to coordinates"
msgstr ""
#: init.lua:415
msgid "Teleport to relative position"
msgstr ""
#: init.lua:422
msgid "Evade Enemy"
msgstr ""
#: init.lua:428
msgid "Accept teleport requests from another player"
msgstr ""
#: init.lua:434
msgid "Deny teleport requests from another player"
msgstr ""

@ -1,3 +1,3 @@
name = tpr
optional_depends = areas
optional_depends = areas, intllib
description = Allows players to send a request to other players to teleport to them.