forked from mtcontrib/exchange_shop
Add i18n whith get_translator
This commit is contained in:
parent
3b79c1c7b6
commit
951981c79a
6
init.lua
6
init.lua
@ -6,6 +6,12 @@ local modpath = minetest.get_modpath("exchange_shop")
|
|||||||
local has_currency = minetest.get_modpath("currency")
|
local has_currency = minetest.get_modpath("currency")
|
||||||
local has_bitchange = minetest.get_modpath("bitchange")
|
local has_bitchange = minetest.get_modpath("bitchange")
|
||||||
|
|
||||||
|
-- Internationalisaton
|
||||||
|
exchange_shop.S = minetest.get_translator("exchange_shop")
|
||||||
|
exchange_shop.FS = function(...)
|
||||||
|
return minetest.formspec_escape(exchange_shop.S(...))
|
||||||
|
end
|
||||||
|
|
||||||
-- Currency migrate options
|
-- Currency migrate options
|
||||||
exchange_shop.migrate = {
|
exchange_shop.migrate = {
|
||||||
use_lbm = false,
|
use_lbm = false,
|
||||||
|
43
shop.lua
43
shop.lua
@ -5,7 +5,8 @@ This code is based on the idea of Dan Duncombe's exchange shop
|
|||||||
https://web.archive.org/web/20160403113102/https://forum.minetest.net/viewtopic.php?id=7002
|
https://web.archive.org/web/20160403113102/https://forum.minetest.net/viewtopic.php?id=7002
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
local S = exchange_shop.S
|
||||||
|
local FS = exchange_shop.FS
|
||||||
local shop_positions = {}
|
local shop_positions = {}
|
||||||
|
|
||||||
local function get_exchange_shop_formspec(mode, pos, meta)
|
local function get_exchange_shop_formspec(mode, pos, meta)
|
||||||
@ -22,10 +23,10 @@ local function get_exchange_shop_formspec(mode, pos, meta)
|
|||||||
-- customer
|
-- customer
|
||||||
local formspec = (
|
local formspec = (
|
||||||
(overflow and "size[8,9]" or "size[8,8]")..
|
(overflow and "size[8,9]" or "size[8,8]")..
|
||||||
"label[1,0.4;You give:]"..
|
"label[1,0.4;" .. FS("You give:") .. "]"..
|
||||||
"list["..name..";cust_ow;1,1;2,2;]"..
|
"list["..name..";cust_ow;1,1;2,2;]"..
|
||||||
"button[3,2.4;2,1;exchange;Exchange]"..
|
"button[3,2.4;2,1;exchange;" .. FS("Exchange") .. "]"..
|
||||||
"label[5,0.4;You get:]"..
|
"label[5,0.4;" .. FS("You get:") .. "]"..
|
||||||
"list["..name..";cust_og;5,1;2,2;]"
|
"list["..name..";cust_og;5,1;2,2;]"
|
||||||
)
|
)
|
||||||
-- Insert fallback slots
|
-- Insert fallback slots
|
||||||
@ -51,17 +52,17 @@ local function get_exchange_shop_formspec(mode, pos, meta)
|
|||||||
-- owner
|
-- owner
|
||||||
local formspec = (
|
local formspec = (
|
||||||
"size[10,10]"..
|
"size[10,10]"..
|
||||||
"label[0,0.1;Title:]"..
|
"label[0,0.1;" .. FS("Title:") .. "]"..
|
||||||
"field[1.2,0.5;3,0.5;title;;"..title.."]"..
|
"field[1.2,0.5;3,0.5;title;;"..title.."]"..
|
||||||
"field_close_on_enter[title;false]"..
|
"field_close_on_enter[title;false]"..
|
||||||
"button[3.9,0.2;1,0.5;set_title;Set]"..
|
"button[3.9,0.2;1,0.5;set_title;" .. FS("Set") .. "]"..
|
||||||
"container[0,2]"..
|
"container[0,2]"..
|
||||||
"label[0,-0.6;You need:]"..
|
"label[0,-0.6;" .. FS("You need") .. FS(":") .. "]"..
|
||||||
"list["..name..";cust_ow;0,0;2,2;]"..
|
"list["..name..";cust_ow;0,0;2,2;]"..
|
||||||
"label[2.5,-0.6;You give:]"..
|
"label[2.5,-0.6;" .. FS("You give") .. FS(":") .. "]"..
|
||||||
"list["..name..";cust_og;2.5,0;2,2;]"..
|
"list["..name..";cust_og;2.5,0;2,2;]"..
|
||||||
"container_end[]"..
|
"container_end[]"..
|
||||||
"label[5,0.1;Current stock:]"
|
"label[5,0.1;" .. FS("Current stock:") .. "]"
|
||||||
)
|
)
|
||||||
|
|
||||||
if overflow then
|
if overflow then
|
||||||
@ -74,17 +75,17 @@ local function get_exchange_shop_formspec(mode, pos, meta)
|
|||||||
|
|
||||||
if mode == "owner_custm" then
|
if mode == "owner_custm" then
|
||||||
formspec = (formspec..
|
formspec = (formspec..
|
||||||
"button[7.5,0.2;2.5,0.5;view_stock;Income]"..
|
"button[7.5,0.2;2.5,0.5;view_stock;" .. FS("Income") .. "]"..
|
||||||
"list["..name..";custm;5,1;5,4;]"..
|
"list["..name..";custm;5,1;5,4;]"..
|
||||||
listring("custm"))
|
listring("custm"))
|
||||||
else
|
else
|
||||||
formspec = (formspec..
|
formspec = (formspec..
|
||||||
"button[7.5,0.2;2.5,0.5;view_custm;Outgoing]"..
|
"button[7.5,0.2;2.5,0.5;view_custm;" .. FS("Outgoing") .. "]"..
|
||||||
"list["..name..";stock;5,1;5,4;]"..
|
"list["..name..";stock;5,1;5,4;]"..
|
||||||
listring("stock"))
|
listring("stock"))
|
||||||
end
|
end
|
||||||
return (formspec..
|
return (formspec..
|
||||||
"label[1,5.4;Use (E) + (Right click) for customer interface]"..
|
"label[1,5.4;" .. FS("Use (E) + (Right click) for customer interface") .. "]"..
|
||||||
"list[current_player;main;1,6;8,4;]")
|
"list[current_player;main;1,6;8,4;]")
|
||||||
end
|
end
|
||||||
return ""
|
return ""
|
||||||
@ -118,10 +119,9 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
|
|||||||
if title ~= fields.title then
|
if title ~= fields.title then
|
||||||
if fields.title ~= "" then
|
if fields.title ~= "" then
|
||||||
meta:set_string("infotext", "'" .. fields.title
|
meta:set_string("infotext", "'" .. fields.title
|
||||||
.. "' (owned by " .. shop_owner .. ")")
|
.. "' (" .. S("owned by @1", shop_owner) .. ")")
|
||||||
else
|
else
|
||||||
meta:set_string("infotext", "Exchange shop (owned by "
|
meta:set_string("infotext", S("Exchange shop (owned by @1", shop_owner) .. ")" )
|
||||||
.. shop_owner ..")")
|
|
||||||
end
|
end
|
||||||
meta:set_string("title", minetest.formspec_escape(fields.title))
|
meta:set_string("title", minetest.formspec_escape(fields.title))
|
||||||
end
|
end
|
||||||
@ -139,7 +139,7 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
|
|||||||
-- Throw error message
|
-- Throw error message
|
||||||
if err_msg then
|
if err_msg then
|
||||||
minetest.chat_send_player(player_name, minetest.colorize("#F33",
|
minetest.chat_send_player(player_name, minetest.colorize("#F33",
|
||||||
"Exchange shop: " .. err_msg))
|
S("Exchange shop:") .. " " .. err_msg))
|
||||||
end
|
end
|
||||||
if resend then
|
if resend then
|
||||||
minetest.show_formspec(player_name, "exchange_shop:shop_formspec",
|
minetest.show_formspec(player_name, "exchange_shop:shop_formspec",
|
||||||
@ -158,7 +158,7 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_node(exchange_shop.shopname, {
|
minetest.register_node(exchange_shop.shopname, {
|
||||||
description = "Exchange Shop",
|
description = S"Exchange Shop",
|
||||||
tiles = {
|
tiles = {
|
||||||
"shop_top.png", "shop_top.png",
|
"shop_top.png", "shop_top.png",
|
||||||
"shop_side.png","shop_side.png",
|
"shop_side.png","shop_side.png",
|
||||||
@ -171,12 +171,11 @@ minetest.register_node(exchange_shop.shopname, {
|
|||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local owner = placer:get_player_name()
|
local owner = placer:get_player_name()
|
||||||
meta:set_string("owner", owner)
|
meta:set_string("owner", owner)
|
||||||
meta:set_string("infotext", "Exchange shop (owned by "
|
meta:set_string("infotext", S("Exchange shop (owned by @1", owner) .. ")")
|
||||||
.. owner .. ")")
|
|
||||||
end,
|
end,
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("infotext", "Exchange shop (constructing)")
|
meta:set_string("infotext", S("Exchange shop (constructing)"))
|
||||||
meta:set_string("owner", "")
|
meta:set_string("owner", "")
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
inv:set_size("stock", exchange_shop.storage_size) -- needed stock for exchanges
|
inv:set_size("stock", exchange_shop.storage_size) -- needed stock for exchanges
|
||||||
@ -195,7 +194,7 @@ minetest.register_node(exchange_shop.shopname, {
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
minetest.chat_send_player(player:get_player_name(),
|
minetest.chat_send_player(player:get_player_name(),
|
||||||
"Cannot dig exchange shop: one or multiple stocks are in use.")
|
S("Cannot dig exchange shop: one or multiple stocks are in use."))
|
||||||
return false
|
return false
|
||||||
end,
|
end,
|
||||||
on_rightclick = function(pos, node, clicker, itemstack)
|
on_rightclick = function(pos, node, clicker, itemstack)
|
||||||
@ -221,7 +220,7 @@ minetest.register_node(exchange_shop.shopname, {
|
|||||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
if listname == "custm" then
|
if listname == "custm" then
|
||||||
minetest.chat_send_player(player:get_player_name(),
|
minetest.chat_send_player(player:get_player_name(),
|
||||||
"Exchange shop: Insert your trade goods into 'Outgoing'.")
|
S("Exchange shop: Insert your trade goods into 'Outgoing'."))
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
local S = exchange_shop.S
|
||||||
|
|
||||||
function exchange_shop.has_access(meta, player_name)
|
function exchange_shop.has_access(meta, player_name)
|
||||||
local owner = meta:get_string("owner")
|
local owner = meta:get_string("owner")
|
||||||
if player_name == owner or owner == "" then
|
if player_name == owner or owner == "" then
|
||||||
@ -67,8 +69,8 @@ end
|
|||||||
function exchange_shop.exchange_action(player_inv, shop_inv)
|
function exchange_shop.exchange_action(player_inv, shop_inv)
|
||||||
if not shop_inv:is_empty("cust_ej")
|
if not shop_inv:is_empty("cust_ej")
|
||||||
or not shop_inv:is_empty("custm_ej") then
|
or not shop_inv:is_empty("custm_ej") then
|
||||||
return "One or multiple ejection fields are filled. "..
|
return S("One or multiple ejection fields are filled.") .. " " ..
|
||||||
"Please empty them or contact the shop owner."
|
S("Please empty them or contact the shop owner.")
|
||||||
end
|
end
|
||||||
local owner_wants = shop_inv:get_list("cust_ow")
|
local owner_wants = shop_inv:get_list("cust_ow")
|
||||||
local owner_gives = shop_inv:get_list("cust_og")
|
local owner_gives = shop_inv:get_list("cust_og")
|
||||||
@ -81,8 +83,8 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
if i1 ~= i2 and name1 == item2:get_name() then
|
if i1 ~= i2 and name1 == item2:get_name() then
|
||||||
return "The field 'Owner needs' can not contain multiple "..
|
return S("The field '@1' can not contain multiple times the same items.", S("You need")) .. " " ..
|
||||||
"times the same items. Please contact the shop owner."
|
S("Please contact the shop owner.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -95,8 +97,8 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
if i1 ~= i2 and name1 == item2:get_name() then
|
if i1 ~= i2 and name1 == item2:get_name() then
|
||||||
return "The field 'Owner gives' can not contain multiple "..
|
return S("The field '@1' can not contain multiple times the same items.", S("You give")) .. " " ..
|
||||||
"times the same items. Please contact the shop owner."
|
S("Please contact the shop owner.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -104,8 +106,8 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
|
|||||||
-- Check for space in the shop
|
-- Check for space in the shop
|
||||||
for i, item in pairs(owner_wants) do
|
for i, item in pairs(owner_wants) do
|
||||||
if not shop_inv:room_for_item("custm", item) then
|
if not shop_inv:room_for_item("custm", item) then
|
||||||
return "The stock in this shop is full. "..
|
return S("The stock in this shop is full.") .. " " ..
|
||||||
"Please contact the shop owner."
|
S("Please contact the shop owner.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -114,21 +116,21 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
|
|||||||
-- Check availability of the shop's items
|
-- Check availability of the shop's items
|
||||||
for i, item in pairs(owner_gives) do
|
for i, item in pairs(owner_gives) do
|
||||||
if not list_contains_item(shop_inv, "stock", item) then
|
if not list_contains_item(shop_inv, "stock", item) then
|
||||||
return "This shop is sold out."
|
return S("This shop is sold out.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check for space in the player's inventory
|
-- Check for space in the player's inventory
|
||||||
for i, item in pairs(owner_gives) do
|
for i, item in pairs(owner_gives) do
|
||||||
if not player_inv:room_for_item("main", item) then
|
if not player_inv:room_for_item("main", item) then
|
||||||
return "You do not have enough space in your inventory."
|
return S("You do not have enough space in your inventory.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check availability of the player's items
|
-- Check availability of the player's items
|
||||||
for i, item in pairs(owner_wants) do
|
for i, item in pairs(owner_wants) do
|
||||||
if not list_contains_item(player_inv, "main", item) then
|
if not list_contains_item(player_inv, "main", item) then
|
||||||
return "You do not have the required items."
|
return S("You do not have the required items.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -157,6 +159,6 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not fully_exchanged then
|
if not fully_exchanged then
|
||||||
return "Warning! Stacks are overflowing somewhere!", true
|
return S("Warning! Stacks are overflowing somewhere!"), true
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user