From 7dea2eba5816e1d7af7b1002c3b4f177ec9b15b5 Mon Sep 17 00:00:00 2001 From: "Y. Wang" Date: Wed, 2 Nov 2022 15:08:21 +0100 Subject: Add helper for "insufficient privileges" messages BREAKING: attrans is now implemented as a table with the __call metamethod instead of as a function --- advtrains/copytool.lua | 2 +- advtrains/couple.lua | 4 ++-- advtrains/init.lua | 6 ++---- advtrains/l10n.lua | 20 ++++++++++++++++++++ advtrains/locale/advtrains.de.tr | 15 ++++++++------- advtrains/locale/advtrains.fr.tr | 13 +++++++------ advtrains/locale/advtrains.zh_CN.tr | 13 +++++++------ advtrains/locale/advtrains.zh_TW.tr | 13 +++++++------ advtrains/locale/template.txt | 13 +++++++------ advtrains/protection.lua | 6 +++--- 10 files changed, 64 insertions(+), 41 deletions(-) create mode 100644 advtrains/l10n.lua diff --git a/advtrains/copytool.lua b/advtrains/copytool.lua index 0b2aa52..c0af8e1 100644 --- a/advtrains/copytool.lua +++ b/advtrains/copytool.lua @@ -26,7 +26,7 @@ minetest.register_tool("advtrains:copytool", { return itemstack end if not minetest.check_player_privs(placer, {train_operator = true }) then - minetest.chat_send_player(pname, attrans("You don't have the train_operator privilege.")) + minetest.chat_send_player(pname, attrans.nopriv("train_operator")) return itemstack end if not minetest.check_player_privs(placer, {train_admin = true }) and minetest.is_protected(pointed_thing.under, placer:get_player_name()) then diff --git a/advtrains/couple.lua b/advtrains/couple.lua index 3e6c432..87fa9ed 100644 --- a/advtrains/couple.lua +++ b/advtrains/couple.lua @@ -182,8 +182,8 @@ end function advtrains.safe_couple_trains(train1, t1_is_front, train2, t2_is_front, pname) if pname and not minetest.check_player_privs(pname, "train_operator") then - minetest.chat_send_player(pname, "Missing train_operator privilege") - return false + minetest.chat_send_player(pname, attrans.nopriv("train_operator", "couple trains")) + return false end local wck_t1, wck_t2 diff --git a/advtrains/init.lua b/advtrains/init.lua index a7e5764..be0cb5d 100644 --- a/advtrains/init.lua +++ b/advtrains/init.lua @@ -22,9 +22,6 @@ Copyright (C) 2016-2020 Moritz Blei (orwell96) and contributors local lot = os.clock() minetest.log("action", "[advtrains] Loading...") --- There is no need to support 0.4.x anymore given that the compatitability with it is already broken by 1bb1d825f46af3562554c12fba35a31b9f7973ff -attrans = minetest.get_translator ("advtrains") - --advtrains advtrains = {trains={}, player_to_train_mapping={}} @@ -178,7 +175,8 @@ function assertt(var, typ) end end -dofile(advtrains.modpath.."/helpers.lua"); +dofile(advtrains.modpath.."/l10n.lua") +dofile(advtrains.modpath.."/helpers.lua") --dofile(advtrains.modpath.."/debugitems.lua"); advtrains.meseconrules = diff --git a/advtrains/l10n.lua b/advtrains/l10n.lua new file mode 100644 index 0000000..3eb75c9 --- /dev/null +++ b/advtrains/l10n.lua @@ -0,0 +1,20 @@ +local S = minetest.get_translator("advtrains") + +local function S_nopriv(priv, verb, ...) + if verb then + return S(string.format("You are not allowed to %s without the %s privilege.", verb, priv), ...) + else + return S("You do not have the @1 privilege.", priv) + end +end + +local mt = { + __call = function(_, ...) + return S(...) + end, +} + +attrans = { + nopriv = S_nopriv, +} +setmetatable(attrans, mt) diff --git a/advtrains/locale/advtrains.de.tr b/advtrains/locale/advtrains.de.tr index 10d4a92..027ed0b 100644 --- a/advtrains/locale/advtrains.de.tr +++ b/advtrains/locale/advtrains.de.tr @@ -15,7 +15,7 @@ Can't get on: wagon full or doors closed!=Sie können nicht einsteigen: der Wagg Use Sneak+rightclick to bypass closed doors!=Nutzen Sie Schleichen+Rechtsklick, um trotz geschlossener Türen einzusteigen. Doors are closed! Use Sneak+rightclick to ignore the closed doors and get off!=Die Türen sind geschlossen. Nutzen Sie Schleichen+Rechtsklick, um trotz geschlossener Türen auszusteigen. Access to @1=Zugang zu @1 -You don't have the train_operator privilege.=Ihnen fehlt das „train_operator“-Privileg. +You don't have the @1 privilege.=Ihnen fehlt das „@1“-Privileg. The wagon's inventory is not empty!=Das Inventar dieses Waggons ist nicht leer! Position is occupied by a train.=Ein Zug steht an dieser Position. There's a Track Circuit Break here.=Hier ist eine Gleisabschnittsgrenze (TCB). @@ -46,7 +46,8 @@ You need to own at least one neighboring wagon to destroy this couple.=Sie müss Buffer and Chain Coupler=Schraubenkupplung Scharfenberg Coupler=Scharfenbergkupplung Japanese Train Inter-Wagon Connection=Waggonzwischenverbindung Japanischer Personenzüge -Can not couple: The couplers of the trains do not match (@1 and @2).=Kann nicht ankuppeln: Die Kupplungen der Züge passen nicht zueinander (@1 und @2) +Can not couple: The couplers of the trains do not match (@1 and @2).=Die Kupplungen der Züge passen nicht zueinander (@1 und @2). +You are not allowed to couple trains without the train_operator privilege.=Sie dürfen ohne das „train_builder“-Privileg keine Züge ankuppeln. # Clipboard The track you are trying to place the wagon on is not long enough!=Das Gleis, auf dem der Waggon platziert werden woll, ist zu kurz. @@ -60,11 +61,11 @@ No such train: @1=Es gibt keinen mit „@1“ identifizierbaren Zug. Train copied!=Der Zug wurde Kopiert. # Protection -You are not allowed to build tracks without the track_builder privilege=Sie dürfen ohne das „track_builder“-Privileg kein Gleis bauen. -You are not allowed to build near tracks without the track_builder privilege=Sie dürfen ohne das „track_builder“-Privileg nicht in der Nähe von Gleisen bauen. -You are not allowed to build tracks at this protected position=Sie dürfen an geschützten Stellen kein Gleis bauen. -You are not allowed to build near tracks at this protected position=Sie dürfen an geschützten Stellen nicht in der Nähe von Gleisen bauen. -You are not allowed to operate turnouts and signals (missing railway_operator privilege)=Sie dürfen ohne das „railway_operator“-Privileg keine Bahnanlage operieren. +You are not allowed to build tracks without the track_builder privilege.=Sie dürfen ohne das „track_builder“-Privileg kein Gleis bauen. +You are not allowed to build near tracks without the track_builder privilege.=Sie dürfen ohne das „track_builder“-Privileg nicht in der Nähe von Gleisen bauen. +You are not allowed to build tracks at this protected position.=Sie dürfen an geschützten Stellen kein Gleis bauen. +You are not allowed to build near tracks at this protected position.=Sie dürfen an geschützten Stellen nicht in der Nähe von Gleisen bauen. +You are not allowed to operate turnouts and signals without the railway_operator privilege.=Sie dürfen ohne das „railway_operator“-Privileg keine Bahnanlage operieren. # Train HUD/Formspecs Speed:=Geschw.: diff --git a/advtrains/locale/advtrains.fr.tr b/advtrains/locale/advtrains.fr.tr index 8b0c5ca..baf61e9 100644 --- a/advtrains/locale/advtrains.fr.tr +++ b/advtrains/locale/advtrains.fr.tr @@ -15,7 +15,7 @@ Can't get on: wagon full or doors closed!=Embarquement impossible : le wagon est Use Sneak+rightclick to bypass closed doors!=Utilisez "Marcher lentement (Sneak)" et Clic-Droit pour franchir les portes closes ! Doors are closed! Use Sneak+rightclick to ignore the closed doors and get off!=Portes closes ! Utilisez "Marcher lentement (Sneak)" et Clic-Droit pour franchir les portes et débarquer ! Access to @1=Accès à @1 -You don't have the train_operator privilege.=Vous ne possédez pas le privilège "train_operator". +You don't have the @1 privilege.=Vous ne possédez pas le privilège "@1". The wagon's inventory is not empty!=Le stock de ce wagon n'est pas vide ! Position is occupied by a train.=Cet emplacement est occupé par un train. There's a Track Circuit Break here.=Il y a un "Track Circuit Break" ici. @@ -47,6 +47,7 @@ Buffer and Chain Coupler=Attelage à tampon et vis Scharfenberg Coupler=Attelage Scharfenberg Japanese Train Inter-Wagon Connection=Passage inter-voiture de train Japonais Can not couple: The couplers of the trains do not match (@1 and @2).=Accouplement impossible: les attelages des trains ne concordent pas (@1 et @2). +You are not allowed to couple trains without the train_operator privilege.=You are not allowed to couple trains without the train_operator privilege. # Clipboard The track you are trying to place the wagon on is not long enough!=La voie sur laquelle vous tentez de placer le wagon est trop courte ! @@ -60,11 +61,11 @@ No such train: @1=Pas de tel train : @1 Train copied!=Train copié ! # Protection -You are not allowed to build tracks without the track_builder privilege=Vous ne pouvez pas construire une voie sans le privilège "track_builder" -You are not allowed to build near tracks without the track_builder privilege=Vous ne pouvez pas construire à proximité d'une voie sans le privilège "track_builder" (?) -You are not allowed to build tracks at this protected position=Vous ne pouvez pas construire une voie à cet emplacement protégé -You are not allowed to build near tracks at this protected position=Vous ne pouvez pas construire à proximité d'une voie à cet emplacement protégé -You are not allowed to operate turnouts and signals (missing railway_operator privilege)=Vous ne pouvez pas actionner les aiguillages ou les signaux (privilège "railway_operator" manquant) +You are not allowed to build tracks without the track_builder privilege.=Vous ne pouvez pas construire une voie sans le privilège "track_builder" +You are not allowed to build near tracks without the track_builder privilege.=Vous ne pouvez pas construire à proximité d'une voie sans le privilège "track_builder" (?) +You are not allowed to build tracks at this protected position.=Vous ne pouvez pas construire une voie à cet emplacement protégé +You are not allowed to build near tracks at this protected position.=Vous ne pouvez pas construire à proximité d'une voie à cet emplacement protégé +You are not allowed to operate turnouts and signals without the railway_operator privilege.=Vous ne pouvez pas actionner les aiguillages ou les signaux (privilège "railway_operator" manquant) # Train HUD/Formspecs Speed:=Vitesse : diff --git a/advtrains/locale/advtrains.zh_CN.tr b/advtrains/locale/advtrains.zh_CN.tr index 6203230..ee1d463 100644 --- a/advtrains/locale/advtrains.zh_CN.tr +++ b/advtrains/locale/advtrains.zh_CN.tr @@ -15,7 +15,7 @@ Can't get on: wagon full or doors closed!=无法上车:车门已关闭或车 Use Sneak+rightclick to bypass closed doors!=请使用潜行+右键上车。 Doors are closed! Use Sneak+rightclick to ignore the closed doors and get off!=车门已关闭,请使用潜行+右键单击下车。 Access to @1=可前往@1 -You don't have the train_operator privilege.=您没有“train_operator”权限。 +You don't have the @1 privilege.=您没有“@1”权限。 The wagon's inventory is not empty!=The wagon's inventory is not empty! Position is occupied by a train.=Position is occupied by a train. There's a Track Circuit Break here.=There's a Track Circuit Break here. @@ -47,6 +47,7 @@ Buffer and Chain Coupler=链式车钩 Scharfenberg Coupler=Scharfenberg 式车钩 Japanese Train Inter-Wagon Connection=日本火车车钩 Can not couple: The couplers of the trains do not match (@1 and @2).=您无法连接这两节车厢:这两节车厢使用不同的车钩 (@1和@2)。 +You are not allowed to couple trains without the train_operator privilege.=您没有“train_operator”权限,不能连接这两节车厢。 # Clipboard The track you are trying to place the wagon on is not long enough!=轨道太短。 @@ -60,11 +61,11 @@ No such train: @1=ID 为“@1”的列车不存在。 Train copied!=已复制 # Protection -You are not allowed to build tracks without the track_builder privilege=您没有“train_operator”权限,不能在这里建造铁路。 -You are not allowed to build near tracks without the track_builder privilege=您没有“train_operator”权限,不能在铁路附近建任何东西。 -You are not allowed to build tracks at this protected position=这里已被保护,您不能在这里建造铁路。 -You are not allowed to build near tracks at this protected position=这里已被保护,您不能在这里的铁路附近建任何东西。 -You are not allowed to operate turnouts and signals (missing railway_operator privilege)=您没有“railway_operator”权限,不能控制铁路设施。 +You are not allowed to build tracks without the track_builder privilege.=您没有“train_operator”权限,不能在这里建造铁路。 +You are not allowed to build near tracks without the track_builder privilege.=您没有“train_operator”权限,不能在铁路附近建任何东西。 +You are not allowed to build tracks at this protected position.=这里已被保护,您不能在这里建造铁路。 +You are not allowed to build near tracks at this protected position.=这里已被保护,您不能在这里的铁路附近建任何东西。 +You are not allowed to operate turnouts and signals without the railway_operator privilege.=您没有“railway_operator”权限,不能控制铁路设施。 # Train HUD/Formspecs Speed:=速度 diff --git a/advtrains/locale/advtrains.zh_TW.tr b/advtrains/locale/advtrains.zh_TW.tr index a483277..014239c 100644 --- a/advtrains/locale/advtrains.zh_TW.tr +++ b/advtrains/locale/advtrains.zh_TW.tr @@ -15,7 +15,7 @@ Can't get on: wagon full or doors closed!=無法上車:車門已關閉或車 Use Sneak+rightclick to bypass closed doors!=請使用潛行+右鍵上車。 Doors are closed! Use Sneak+rightclick to ignore the closed doors and get off!=車門已關閉,請使用潛行+右鍵單擊下車。 Access to @1=可前往@1 -You don't have the train_operator privilege.=您沒有「train_operator」許可權。 +You don't have the @1 privilege.=您沒有「@1」許可權。 The wagon's inventory is not empty!=The wagon's inventory is not empty! Position is occupied by a train.=Position is occupied by a train. There's a Track Circuit Break here.=There's a Track Circuit Break here. @@ -47,6 +47,7 @@ Buffer and Chain Coupler=鏈式連結器 Scharfenberg Coupler=Scharfenberg 式連結器 Japanese Train Inter-Wagon Connection=日本火車連結器 Can not couple: The couplers of the trains do not match (@1 and @2).=您無法連結這兩節車廂:這兩節車廂使用不同的連結器 (@1和@2)。 +You are not allowed to couple trains without the train_operator privilege.=您沒有「train_operator」許可權,不能連結這兩節車廂。 # Clipboard The track you are trying to place the wagon on is not long enough!=軌道太短。 @@ -60,11 +61,11 @@ No such train: @1=ID 為「@1」的列車不存在。 Train copied!=已複製 # Protection -You are not allowed to build tracks without the track_builder privilege=您沒有「train_operator」許可權,不能在這裡建造鐵路。 -You are not allowed to build near tracks without the track_builder privilege=您沒有「train_operator」許可權,不能在鐵路附近建任何東西。 -You are not allowed to build tracks at this protected position=這裡已被保護,您不能在這裡建造鐵路。 -You are not allowed to build near tracks at this protected position=這裡已被保護,您不能在這裡的鐵路附近建任何東西。 -You are not allowed to operate turnouts and signals (missing railway_operator privilege)=您沒有「railway_operator」許可權,不能控制鐵路設施。 +You are not allowed to build tracks without the track_builder privilege.=您沒有「train_operator」許可權,不能在這裡建造鐵路。 +You are not allowed to build near tracks without the track_builder privilege.=您沒有「train_operator」許可權,不能在鐵路附近建任何東西。 +You are not allowed to build tracks at this protected position.=這裡已被保護,您不能在這裡建造鐵路。 +You are not allowed to build near tracks at this protected position.=這裡已被保護,您不能在這裡的鐵路附近建任何東西。 +You are not allowed to operate turnouts and signals without the railway_operator privilege.=您沒有「railway_operator」許可權,不能控制鐵路設施。 # Train HUD/Formspecs Speed:=速度 diff --git a/advtrains/locale/template.txt b/advtrains/locale/template.txt index d7c814c..c361cc4 100644 --- a/advtrains/locale/template.txt +++ b/advtrains/locale/template.txt @@ -15,7 +15,7 @@ Can't get on: wagon full or doors closed!=Can't get on: wagon full or doors clos Use Sneak+rightclick to bypass closed doors!=Use Sneak+rightclick to bypass closed doors! Doors are closed! Use Sneak+rightclick to ignore the closed doors and get off!=Doors are closed! Use Sneak+rightclick to ignore the closed doors and get off! Access to @1=Access to @1 -You don't have the train_operator privilege.=You don't have the train_operator privilege. +You don't have the @1 privilege.=You don't have the @1 privilege. The wagon's inventory is not empty!=The wagon's inventory is not empty! Position is occupied by a train.=Position is occupied by a train. There's a Track Circuit Break here.=There's a Track Circuit Break here. @@ -47,6 +47,7 @@ Buffer and Chain Coupler=Buffer and Chain Coupler Scharfenberg Coupler=Scharfenberg Coupler Japanese Train Inter-Wagon Connection=Japanese Train Inter-Wagon Connection Can not couple: The couplers of the trains do not match (@1 and @2).=Can not couple: The couplers of the trains do not match (@1 and @2). +You are not allowed to couple trains without the train_operator privilege.=You are not allowed to couple trains without the train_operator privilege. # Clipboard The track you are trying to place the wagon on is not long enough!=The track you are trying to place the wagon on is not long enough! @@ -60,11 +61,11 @@ No such train: @1=No such train: @1 Train copied!=Train copied! # Protection -You are not allowed to build tracks without the track_builder privilege=You are not allowed to build tracks without the track_builder privilege -You are not allowed to build near tracks without the track_builder privilege=You are not allowed to build near tracks without the track_builder privilege -You are not allowed to build tracks at this protected position=You are not allowed to build tracks at this protected position -You are not allowed to build near tracks at this protected position=You are not allowed to build near tracks at this protected position -You are not allowed to operate turnouts and signals (missing railway_operator privilege)=You are not allowed to operate turnouts and signals (missing railway_operator privilege) +You are not allowed to build tracks without the track_builder privilege.=You are not allowed to build tracks without the track_builder privilege. +You are not allowed to build near tracks without the track_builder privilege.=You are not allowed to build near tracks without the track_builder privilege. +You are not allowed to build tracks at this protected position.=You are not allowed to build tracks at this protected position. +You are not allowed to build near tracks at this protected position.=You are not allowed to build near tracks at this protected position. +You are not allowed to operate turnouts and signals without the railway_operator privilege.=You are not allowed to operate turnouts and signals without the railway_operator privilege. # Train HUD/Formspecs Speed:=Speed: diff --git a/advtrains/protection.lua b/advtrains/protection.lua index cca54a9..83ead86 100644 --- a/advtrains/protection.lua +++ b/advtrains/protection.lua @@ -145,12 +145,12 @@ function advtrains.check_track_protection(pos, pname, near, prot_p) --atdebug("CTP: ",pos,pname,near,prot_p,"priv=",priv,"prot=",prot,"dprot=",dprot) if not priv and (not boo or prot or not dprot) then - minetest.chat_send_player(pname, attrans("You are not allowed to build "..nears.."tracks without the track_builder privilege")) + minetest.chat_send_player(pname, attrans.nopriv("track_builder", "build "..nears.."tracks")) minetest.log("action", pname.." tried to modify terrain "..nears.."track at "..minetest.pos_to_string(apos).." but is not permitted to (no privilege)") return false end if prot then - minetest.chat_send_player(pname, attrans("You are not allowed to build "..nears.."tracks at this protected position")) + minetest.chat_send_player(pname, attrans("You are not allowed to build "..nears.."tracks at this protected position.")) minetest.record_protection_violation(pos, pname) minetest.log("action", pname.." tried to modify "..nears.."track at "..minetest.pos_to_string(apos).." but position is protected!") return false @@ -181,7 +181,7 @@ function advtrains.check_turnout_signal_protection(pos, pname) nocheck=false return true else - minetest.chat_send_player(pname, attrans("You are not allowed to operate turnouts and signals (missing railway_operator privilege)")) + minetest.chat_send_player(pname, attrans.nopriv("railway_operator", "operate turnouts and signals")) minetest.log("action", pname.." tried to operate turnout/signal at "..minetest.pos_to_string(pos).." but does not have railway_operator") nocheck=false return false -- cgit v1.2.3