mirror of
https://gitlab.com/rubenwardy/awards.git
synced 2025-07-16 14:50:24 +02:00
Use client-side translation instead of intllib
This commit is contained in:
committed by
rubenwardy
parent
23c7ca57b7
commit
7bac284f80
@ -1,6 +1,6 @@
|
||||
-- Copyright (c) 2013-18 rubenwardy. MIT.
|
||||
|
||||
local S = awards.gettext
|
||||
local S = awards.translator
|
||||
|
||||
function awards.register_award(name, def)
|
||||
def.name = name
|
||||
|
@ -1,6 +1,10 @@
|
||||
-- Copyright (c) 2013-18 rubenwardy. MIT.
|
||||
|
||||
local S, NS = awards.gettext, awards.ngettext
|
||||
local function ngettext(msgid, msgid_plural, n, ...)
|
||||
return awards.translator(n==1 and msgid or msgid_plural, ...)
|
||||
end
|
||||
|
||||
local S, NS = awards.translator, ngettext
|
||||
|
||||
awards.on = {}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
-- Copyright (c) 2013-18 rubenwardy and Wuzzy. MIT.
|
||||
|
||||
local S = awards.gettext
|
||||
local S = awards.translator
|
||||
|
||||
|
||||
-- Saint-Maclou
|
||||
@ -1100,7 +1100,7 @@ end
|
||||
|
||||
if minetest.get_modpath("basic_materials") then
|
||||
awards.register_award("awards_oil", {
|
||||
title = S("Oil Typhoon"),
|
||||
title = S("Oil Tycoon"),
|
||||
description = S("Craft 500 times oil extract."),
|
||||
|
||||
trigger = {
|
||||
|
@ -1,6 +1,6 @@
|
||||
-- Copyright (c) 2013-18 rubenwardy. MIT.
|
||||
|
||||
local S = awards.gettext
|
||||
local S = awards.translator
|
||||
|
||||
minetest.register_chatcommand("awards", {
|
||||
params = S("[c|clear|disable|enable]"),
|
||||
@ -37,7 +37,7 @@ minetest.register_chatcommand("awd", {
|
||||
func = function(name, param)
|
||||
local def = awards.registered_awards[param]
|
||||
if def then
|
||||
minetest.chat_send_player(name, string.format(S("%s: %s"), def.title, def.description))
|
||||
minetest.chat_send_player(name, string.format("%s: %s", def.title, def.description))
|
||||
else
|
||||
minetest.chat_send_player(name, S("Award not found."))
|
||||
end
|
||||
|
15
src/gui.lua
15
src/gui.lua
@ -1,6 +1,6 @@
|
||||
-- Copyright (c) 2013-18 rubenwardy. MIT.
|
||||
|
||||
local S = awards.gettext
|
||||
local S = awards.translator
|
||||
|
||||
function awards.get_formspec(name, to, sid)
|
||||
local formspec = ""
|
||||
@ -30,13 +30,18 @@ function awards.get_formspec(name, to, sid)
|
||||
if sdef and sdef.title then
|
||||
title = sdef.title
|
||||
end
|
||||
local status = "%s"
|
||||
local status = "@1"
|
||||
if sitem.unlocked then
|
||||
status = S("%s (unlocked)")
|
||||
-- Don't actually use translator here. We define empty S() to fool the update_translations script
|
||||
-- into extracting that string for the templates.
|
||||
local function S(str)
|
||||
return str
|
||||
end
|
||||
status = S("@1 (unlocked)")
|
||||
end
|
||||
|
||||
formspec = formspec .. "textarea[0.5,3.1;4.8,1.45;;" ..
|
||||
string.format(status, minetest.formspec_escape(title)) ..
|
||||
S(status, minetest.formspec_escape(title)) ..
|
||||
";]"
|
||||
|
||||
if sdef and sdef.icon then
|
||||
@ -122,7 +127,7 @@ function awards.show_to(name, to, sid, text)
|
||||
if def then
|
||||
if def.title then
|
||||
if def.description then
|
||||
minetest.chat_send_player(to, string.format(S("%s: %s"), def.title, def.description))
|
||||
minetest.chat_send_player(to, string.format("%s: %s", def.title, def.description))
|
||||
else
|
||||
minetest.chat_send_player(to, def.title)
|
||||
end
|
||||
|
@ -1,44 +0,0 @@
|
||||
-- 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
|
@ -14,6 +14,12 @@
|
||||
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
--
|
||||
|
||||
-- Don't actually use translator here. We define empty S() to fool the update_translations script
|
||||
-- into extracting those strings for the templates. Actual translation is done in api_triggers.lua.
|
||||
local S = function (str)
|
||||
return str
|
||||
end
|
||||
|
||||
-- Check if a player object is valid for awards.
|
||||
local function player_ok(player)
|
||||
return player and player.is_player and player:is_player() and not player.is_fake_player
|
||||
@ -21,8 +27,8 @@ end
|
||||
|
||||
awards.register_trigger("chat", {
|
||||
type = "counted",
|
||||
progress = "@1/@2 chat messages",
|
||||
auto_description = { "Send a chat message", "Chat @1 times" },
|
||||
progress = S("@1/@2 chat messages"),
|
||||
auto_description = { S("Send a chat message"), S("Chat @1 times") },
|
||||
})
|
||||
minetest.register_on_chat_message(function(name, message)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
@ -36,17 +42,17 @@ end)
|
||||
|
||||
awards.register_trigger("join", {
|
||||
type = "counted",
|
||||
progress = "@1/@2 joins",
|
||||
auto_description = { "Join once", "Join @1 times" },
|
||||
progress = S("@1/@2 joins"),
|
||||
auto_description = { S("Join once"), S("Join @1 times") },
|
||||
})
|
||||
minetest.register_on_joinplayer(awards.notify_join)
|
||||
|
||||
|
||||
awards.register_trigger("death", {
|
||||
type = "counted_key",
|
||||
progress = "@1/@2 deaths",
|
||||
auto_description = { "Die once of @2", "Die @1 times of @2" },
|
||||
auto_description_total = { "Die @1 times.", "Mine @1 times" },
|
||||
progress = S("@1/@2 deaths"),
|
||||
auto_description = { S("Die once of @2"), S("Die @1 times of @2") },
|
||||
auto_description_total = { S("Die @1 times."), S("Mine @1 times") },
|
||||
get_key = function(self, def)
|
||||
return def.trigger.reason
|
||||
end,
|
||||
@ -63,9 +69,9 @@ end)
|
||||
|
||||
awards.register_trigger("dig", {
|
||||
type = "counted_key",
|
||||
progress = "@1/@2 dug",
|
||||
auto_description = { "Mine: @2", "Mine: @1×@2" },
|
||||
auto_description_total = { "Mine @1 block.", "Mine @1 blocks." },
|
||||
progress = S("@1/@2 dug"),
|
||||
auto_description = { S("Mine: @2"), S("Mine: @1×@2") },
|
||||
auto_description_total = { S("Mine @1 block."), S("Mine @1 blocks.") },
|
||||
get_key = function(self, def)
|
||||
return minetest.registered_aliases[def.trigger.node] or def.trigger.node
|
||||
end,
|
||||
@ -84,9 +90,9 @@ end)
|
||||
|
||||
awards.register_trigger("place", {
|
||||
type = "counted_key",
|
||||
progress = "@1/@2 placed",
|
||||
auto_description = { "Place: @2", "Place: @1×@2" },
|
||||
auto_description_total = { "Place @1 block.", "Place @1 blocks." },
|
||||
progress = S("@1/@2 placed"),
|
||||
auto_description = { S("Place: @2"), S("Place: @1×@2") },
|
||||
auto_description_total = { S("Place @1 block."), S("Place @1 blocks.") },
|
||||
get_key = function(self, def)
|
||||
return minetest.registered_aliases[def.trigger.node] or def.trigger.node
|
||||
end,
|
||||
@ -105,9 +111,9 @@ end)
|
||||
|
||||
awards.register_trigger("craft", {
|
||||
type = "counted_key",
|
||||
progress = "@1/@2 crafted",
|
||||
auto_description = { "Craft: @2", "Craft: @1×@2" },
|
||||
auto_description_total = { "Craft @1 item", "Craft @1 items." },
|
||||
progress = S("@1/@2 crafted"),
|
||||
auto_description = { S("Craft: @2"), S("Craft: @1×@2") },
|
||||
auto_description_total = { S("Craft @1 item"), S("Craft @1 items.") },
|
||||
get_key = function(self, def)
|
||||
return minetest.registered_aliases[def.trigger.item] or def.trigger.item
|
||||
end,
|
||||
@ -126,9 +132,9 @@ end)
|
||||
|
||||
awards.register_trigger("eat", {
|
||||
type = "counted_key",
|
||||
progress = "@1/@2 eaten",
|
||||
auto_description = { "Eat @2", "Eat @1×@2" },
|
||||
auto_description_total = { "Eat @1 item", "Eat @1 items." },
|
||||
progress = S("@1/@2 eaten"),
|
||||
auto_description = { S("Eat @2"), S("Eat @1×@2") },
|
||||
auto_description_total = { S("Eat @1 item"), S("Eat @1 items.") },
|
||||
get_key = function(self, def)
|
||||
return minetest.registered_aliases[def.trigger.item] or def.trigger.item
|
||||
end,
|
||||
|
Reference in New Issue
Block a user