Change calendar caption format string
parent
c30827eeb8
commit
074c0d10ca
18
API.md
18
API.md
|
@ -126,7 +126,17 @@ get a tooltip.
|
|||
* `show_controls`: If `true`, show buttons to change the month and year (default: `true`)
|
||||
* `wanted_months`: Which cardinal calendar month to show (default: current one)
|
||||
* `wanted_years`: Which cardinal calendar year to show (default: current one)
|
||||
* `caption_format`: Optional format string to change the calendar caption
|
||||
The same placeholders as for `calender.get_date_string` can be used.
|
||||
Note the placeholders for days and weekdays will are
|
||||
arbitrary here
|
||||
* `caption_format`: Optional format information to change the calendar caption.
|
||||
Is a table with the following fields:
|
||||
[1]: Format string with `minetest.translate`-style placeholders (from Minetest 5.0.0)
|
||||
[2]: Translator domain for `minetest.translate`
|
||||
[3]: and further: Parameters for the format string. For each parameter, use
|
||||
a placeholder from `calender.get_date_string`.
|
||||
|
||||
Example for `caption_format`:
|
||||
|
||||
{ N("@1, year @2"), "mymod", "%b", "%Y" }
|
||||
|
||||
Will resolve to e.g. "January, Year 1".
|
||||
`N` is a dummy function `function(s) return s end` that is used for the translation collector
|
||||
script.
|
||||
|
|
8
gui.lua
8
gui.lua
|
@ -49,7 +49,13 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
|
|||
local formspec = ""
|
||||
local caption = ""
|
||||
if caption_format then
|
||||
caption = calendar.get_date_string(caption_format, tdays)
|
||||
local args = {}
|
||||
if caption_format[3] then
|
||||
for a=3, #caption_format do
|
||||
table.insert(args, calendar.get_date_string(caption_format[a], tdays))
|
||||
end
|
||||
end
|
||||
caption = minetest.translate(caption_format[2], caption_format[1], unpack(args))
|
||||
else
|
||||
if settings.ordinal then
|
||||
caption = S("Month @1, year @2", wanted_dmonths, wanted_dyears)
|
||||
|
|
3
init.lua
3
init.lua
|
@ -119,6 +119,9 @@ calendar.get_date_string = function(format, total_days)
|
|||
format = string.gsub( format, "%%b", S(calendar.month_names[ m + 1 ]) ) -- current month long name
|
||||
format = string.gsub( format, "%%h", S(calendar.month_names_short[ m + 1 ]) ) -- current month short name
|
||||
|
||||
format = string.gsub( format, "%%b", S(calendar.month_names[ m + 1 ]) ) -- current month long name
|
||||
format = string.gsub( format, "%%h", S(calendar.month_names_short[ m + 1 ]) ) -- current month short name
|
||||
|
||||
format = string.gsub( format, "%%z", "%%" )
|
||||
|
||||
return format
|
||||
|
|
Loading…
Reference in New Issue