Add translator wrapper functions to support MT 0.4
parent
2ba42fd065
commit
f8601bf6ca
|
@ -1,9 +1,4 @@
|
|||
local S
|
||||
if minetest.get_translator then
|
||||
S = minetest.get_translator("calendar")
|
||||
else
|
||||
S = function(s) return s end
|
||||
end
|
||||
local S = calendar._get_translator("calendar")
|
||||
|
||||
minetest.register_chatcommand("calendar", {
|
||||
param = "",
|
||||
|
|
34
gui.lua
34
gui.lua
|
@ -1,9 +1,4 @@
|
|||
local S
|
||||
if minetest.get_translator then
|
||||
S = minetest.get_translator("calendar")
|
||||
else
|
||||
S = function(s) return s end
|
||||
end
|
||||
local S = calendar._get_translator("calendar")
|
||||
local F = minetest.formspec_escape
|
||||
|
||||
local COLOR_HOLIDAY = "#00FF00"
|
||||
|
@ -22,6 +17,8 @@ local DEFAULT_SETTINGS = {
|
|||
show_controls = true,
|
||||
}
|
||||
|
||||
local SHOW_AREA_TOOLTIPS = minetest.features.formspec_version_element
|
||||
|
||||
function calendar.show_calendar(player_name, settings, wanted_months, wanted_years, caption_format)
|
||||
if not settings then
|
||||
settings = DEFAULT_SETTINGS
|
||||
|
@ -55,11 +52,7 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
|
|||
table.insert(args, calendar.get_date_string(caption_format[a], tdays))
|
||||
end
|
||||
end
|
||||
if minetest.translate then
|
||||
caption = minetest.translate(caption_format[2], caption_format[1], unpack(args))
|
||||
else
|
||||
caption = S(caption_format[2], unpack(args))
|
||||
end
|
||||
caption = calendar._translate(caption_format[2], caption_format[1], unpack(args))
|
||||
else
|
||||
if settings.ordinal then
|
||||
caption = S("Month @1, year @2", wanted_dmonths, wanted_dyears)
|
||||
|
@ -101,8 +94,10 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
|
|||
local holidays = calendar.get_holidays(tdays)
|
||||
local tooltip_lines = {}
|
||||
if settings.show_holidays and #holidays > 0 then
|
||||
for h=1, #holidays do
|
||||
table.insert(tooltip_lines, minetest.colorize(COLOR_HOLIDAY, holidays[h].name))
|
||||
if SHOW_AREA_TOOLTIPS then
|
||||
for h=1, #holidays do
|
||||
table.insert(tooltip_lines, minetest.colorize(COLOR_HOLIDAY, holidays[h].name))
|
||||
end
|
||||
end
|
||||
day_str = minetest.colorize(COLOR_HOLIDAY, day_str)
|
||||
box_color = COLOR_DAYBOX_HOLIDAY
|
||||
|
@ -110,7 +105,9 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
|
|||
day_str = F(day_str)
|
||||
if settings.show_today and tdays == total_days then
|
||||
formspec = formspec .. "box["..(x-0.05)..","..(y-0.05)..";1.1,1.1;"..COLOR_DAYBOX_TODAY.."]"
|
||||
table.insert(tooltip_lines, minetest.colorize(COLOR_TOOLTIP_TODAY, S("Today")))
|
||||
if SHOW_AREA_TOOLTIPS then
|
||||
table.insert(tooltip_lines, minetest.colorize(COLOR_TOOLTIP_TODAY, S("Today")))
|
||||
end
|
||||
end
|
||||
formspec = formspec .. "box["..x..","..y..";1,1;"..box_color.."]" ..
|
||||
"label["..(x+0.15)..","..(y+0.3)..";"..day_str.."]"
|
||||
|
@ -128,18 +125,21 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
|
|||
if wanted_months > 0 or wanted_years > 0 then
|
||||
formspec = formspec .. "button[0.5,"..y..";1,1;prev_year;<<]"
|
||||
.. "button[1.5,"..y..";1,1;prev_month;<]"
|
||||
.. "tooltip[prev_month;"..F(S("Previous month")).."]"
|
||||
formspec = formspec .. "tooltip[prev_month;"..F(S("Previous month")).."]"
|
||||
.. "tooltip[prev_year;"..F(S("Previous year")).."]"
|
||||
end
|
||||
formspec = formspec .. "button[2.5,"..y..";2,1;today;"..F(S("Today")).."]"
|
||||
formspec = formspec .. "button[4.5,"..y..";1,1;next_month;>]"
|
||||
.. "button[5.5,"..y..";1,1;next_year;>>]"
|
||||
.. "tooltip[next_month;"..F(S("Next month")).."]"
|
||||
formspec = formspec .. "tooltip[next_month;"..F(S("Next month")).."]"
|
||||
.. "tooltip[next_year;"..F(S("Next year")).."]"
|
||||
end
|
||||
local size_x = math.max(calendar.WEEK_DAYS+2, 7)
|
||||
local size_y = y+1.5
|
||||
formspec = "formspec_version[3]size["..size_x..","..size_y.."]" .. formspec
|
||||
if minetest.features.formspec_version_element then
|
||||
formspec = "formspec_version[3]" .. formspec
|
||||
end
|
||||
formspec = "size["..size_x..","..size_y.."]" .. formspec
|
||||
minetest.show_formspec(player_name, "calendar:calendar", formspec)
|
||||
|
||||
player_current_calendars[player_name] = { years = wanted_years, months = wanted_months }
|
||||
|
|
33
init.lua
33
init.lua
|
@ -1,10 +1,35 @@
|
|||
calendar = {}
|
||||
local S
|
||||
if minetest.get_translator then
|
||||
S = minetest.get_translator("calendar")
|
||||
|
||||
-- Compability translator code to support MT 0.4, which doesn't support
|
||||
-- translations for mods.
|
||||
-- This adds two dummy or wrapper functions:
|
||||
-- * minetest.translate ← calendar._translate
|
||||
-- * minetest.get_translator ← calendar._get_translator
|
||||
|
||||
if not minetest.translate then
|
||||
-- No translation system available, use dummy functions
|
||||
function calendar._translate(textdomain, str, ...)
|
||||
local arg = {n=select('#', ...), ...}
|
||||
return str:gsub("@(.)", function(matched)
|
||||
local c = string.byte(matched)
|
||||
if string.byte("1") <= c and c <= string.byte("9") then
|
||||
return arg[c - string.byte("0")]
|
||||
else
|
||||
return matched
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function calendar._get_translator(textdomain)
|
||||
return function(str, ...) return calendar._translate(textdomain or "", str, ...) end
|
||||
end
|
||||
else
|
||||
S = function(s) return s end
|
||||
-- Translation system available, just user wrapper functions
|
||||
calendar._translate = minetest.translate
|
||||
calendar._get_translator = minetest.get_translator
|
||||
end
|
||||
|
||||
local S = calendar._get_translator("calendar")
|
||||
local F = minetest.formspec_escape
|
||||
|
||||
dofile(minetest.get_modpath("calendar").."/gameconfig.lua")
|
||||
|
|
Loading…
Reference in New Issue