Add intllib support
This commit is contained in:
parent
ec9127adb1
commit
132a01cd0f
@ -1,2 +1,3 @@
|
|||||||
|
intllib?
|
||||||
unified_inventory?
|
unified_inventory?
|
||||||
central_message?
|
central_message?
|
||||||
|
96
init.lua
96
init.lua
@ -1,3 +1,15 @@
|
|||||||
|
-- Boilerplate to support localized strings if intllib mod is installed.
|
||||||
|
local S, F
|
||||||
|
if minetest.get_modpath("intllib") then
|
||||||
|
dofile(minetest.get_modpath("intllib").."/intllib.lua")
|
||||||
|
S = intllib.Getter(minetest.get_current_modname())
|
||||||
|
else
|
||||||
|
S = function(s) return s end
|
||||||
|
end
|
||||||
|
F = function(f) return minetest.formspec_escape(S(f)) end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
doc = {}
|
doc = {}
|
||||||
|
|
||||||
doc.VERSION = {}
|
doc.VERSION = {}
|
||||||
@ -81,7 +93,7 @@ function doc.mark_entry_as_revealed(playername, category_id, entry_id)
|
|||||||
doc.data.players[playername].entry_textlist_needs_updating = true
|
doc.data.players[playername].entry_textlist_needs_updating = true
|
||||||
if minetest.get_modpath("central_message") ~= nil then
|
if minetest.get_modpath("central_message") ~= nil then
|
||||||
local cat = doc.data.categories[category_id]
|
local cat = doc.data.categories[category_id]
|
||||||
cmsg.push_message_player(minetest.get_player_by_name(playername), string.format("New help entry unlocked: %s > %s", cat.def.name, entry.name))
|
cmsg.push_message_player(minetest.get_player_by_name(playername), string.format(S("New help entry unlocked: %s > %s"), cat.def.name, entry.name))
|
||||||
end
|
end
|
||||||
-- To avoid sound spamming, don't play sound more than once per second
|
-- To avoid sound spamming, don't play sound more than once per second
|
||||||
local last_sound = doc.data.players[playername].last_reveal_sound
|
local last_sound = doc.data.players[playername].last_reveal_sound
|
||||||
@ -116,7 +128,7 @@ function doc.mark_all_entries_as_revealed(playername)
|
|||||||
doc.data.players[playername].entry_textlist_needs_updating = true
|
doc.data.players[playername].entry_textlist_needs_updating = true
|
||||||
|
|
||||||
-- Notify
|
-- Notify
|
||||||
local msg = "All help entries unlocked!"
|
local msg = S("All help entries unlocked!")
|
||||||
if minetest.get_modpath("central_message") ~= nil then
|
if minetest.get_modpath("central_message") ~= nil then
|
||||||
cmsg.push_message_player(minetest.get_player_by_name(playername), msg)
|
cmsg.push_message_player(minetest.get_player_by_name(playername), msg)
|
||||||
else
|
else
|
||||||
@ -448,13 +460,17 @@ end)
|
|||||||
|
|
||||||
function doc.formspec_core(tab)
|
function doc.formspec_core(tab)
|
||||||
if tab == nil then tab = 1 else tab = tostring(tab) end
|
if tab == nil then tab = 1 else tab = tostring(tab) end
|
||||||
return "size[12,9]tabheader[0,0;doc_header;Category list,Entry list,Entry;"..tab..";true;false]"
|
return "size[12,9]tabheader[0,0;doc_header;"..
|
||||||
|
minetest.formspec_escape(S("Category list")) .. "," ..
|
||||||
|
minetest.formspec_escape(S("Entry list")) .. "," ..
|
||||||
|
minetest.formspec_escape(S("Entry")) .. ";"
|
||||||
|
..tab..";true;false]"
|
||||||
end
|
end
|
||||||
|
|
||||||
function doc.formspec_main()
|
function doc.formspec_main()
|
||||||
local formstring = "label[0,0;This is the Documentation System, Version "..doc.VERSION.STRING..".\n"
|
local formstring = "label[0,0;"..minetest.formspec_escape(string.format(S("This is the Documentation System, Version %s."), doc.VERSION.STRING)) .. "\n"
|
||||||
if doc.get_category_count() >= 1 then
|
if doc.get_category_count() >= 1 then
|
||||||
formstring = formstring .. "Please select a category you wish to learn more about:]"
|
formstring = formstring .. F("Please select a category you wish to learn more about:").."]"
|
||||||
local y = 1
|
local y = 1
|
||||||
for c=1,#doc.data.category_order do
|
for c=1,#doc.data.category_order do
|
||||||
local id = doc.data.category_order[c]
|
local id = doc.data.category_order[c]
|
||||||
@ -475,28 +491,28 @@ end
|
|||||||
|
|
||||||
function doc.formspec_error_no_categories()
|
function doc.formspec_error_no_categories()
|
||||||
local formstring = "size[8,6]textarea[0.25,0;8,6;;"
|
local formstring = "size[8,6]textarea[0.25,0;8,6;;"
|
||||||
formstring = formstring .. minetest.formspec_escape(
|
formstring = formstring ..
|
||||||
[=[This is the Documentation System, Version ]=]..doc.VERSION.STRING..[=[.
|
F([=[This is the Documentation System, Version %s.
|
||||||
|
|
||||||
ERROR: No help available.
|
ERROR: No help available.
|
||||||
|
|
||||||
No categories have been registered, but the Documentation System is useless without them.
|
No categories have been registered, but the Documentation System is useless without them.
|
||||||
The Documentation System does not come with help contents on its own, it needs additional mods to add help content.
|
The Documentation System does not come with help contents on its own, it needs additional mods to add help content.
|
||||||
Please make sure such mods are enabled on for this world, and try again.]=])
|
Please make sure such mods are enabled on for this world, and try again.]=])
|
||||||
formstring = formstring .. ";]button_exit[3,5;2,1;okay;OK]"
|
formstring = formstring .. ";]button_exit[3,5;2,1;okay;"..F("OK").."]"
|
||||||
return formstring
|
return formstring
|
||||||
end
|
end
|
||||||
|
|
||||||
function doc.formspec_error_hidden(category_id, entry_id)
|
function doc.formspec_error_hidden(category_id, entry_id)
|
||||||
local formstring = "size[8,6]textarea[0.25,0;8,6;;"
|
local formstring = "size[8,6]textarea[0.25,0;8,6;;"
|
||||||
formstring = formstring .. minetest.formspec_escape(
|
formstring = formstring .. minetest.formspec_escape(
|
||||||
string.format([=[This is the Documentation System, Version %s.
|
string.format(S([=[This is the Documentation System, Version %s.
|
||||||
|
|
||||||
ERROR: Access denied.
|
ERROR: Access denied.
|
||||||
|
|
||||||
Sorry, access to the requested entry has been denied; this entry is secret. You may unlock access by more playing. Figure out on your own how to unlock this entry.]=],
|
Sorry, access to the requested entry has been denied; this entry is secret. You may unlock access by more playing. Figure out on your own how to unlock this entry.]=]),
|
||||||
doc.VERSION.STRING, doc.data.categories[category_id].def.name, doc.data.categories[category_id].entries[entry_id].name))
|
doc.VERSION.STRING, doc.data.categories[category_id].def.name, doc.data.categories[category_id].entries[entry_id].name))
|
||||||
formstring = formstring .. ";]button_exit[3,5;2,1;okay;OK]"
|
formstring = formstring .. ";]button_exit[3,5;2,1;okay;"..F("OK").."]"
|
||||||
return formstring
|
return formstring
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -619,40 +635,40 @@ end
|
|||||||
function doc.formspec_category(id, playername)
|
function doc.formspec_category(id, playername)
|
||||||
local formstring
|
local formstring
|
||||||
if id == nil then
|
if id == nil then
|
||||||
formstring = "label[0,0.5;You haven't chosen a category yet. Please choose one in the category list first.]"
|
formstring = "label[0,0.5;"..F("You haven't chosen a category yet. Please choose one in the category list first.").."]"
|
||||||
formstring = formstring .. "button[0,1.5;3,1;doc_button_goto_main;Go to category list]"
|
formstring = formstring .. "button[0,1.5;3,1;doc_button_goto_main;"..F("Go to category list").."]"
|
||||||
else
|
else
|
||||||
formstring = "label[0,0;Help > "..doc.data.categories[id].def.name.."]"
|
formstring = "label[0,0;"..minetest.formspec_escape(string.format(S("Help > %s"), doc.data.categories[id].def.name)).."]"
|
||||||
local total = doc.get_entry_count(id)
|
local total = doc.get_entry_count(id)
|
||||||
if total >= 1 then
|
if total >= 1 then
|
||||||
local revealed = doc.get_revealed_count(playername, id)
|
local revealed = doc.get_revealed_count(playername, id)
|
||||||
if revealed == 0 then
|
if revealed == 0 then
|
||||||
formstring = formstring .. "label[0,0.5;Currently all entries in this category are hidden from you.\nUnlock new entries by proceeding in the game.]"
|
formstring = formstring .. "label[0,0.5;"..F("Currently all entries in this category are hidden from you.\nUnlock new entries by proceeding in the game.").."]"
|
||||||
formstring = formstring .. "button[0,1.5;3,1;doc_button_goto_main;Go to category list]"
|
formstring = formstring .. "button[0,1.5;3,1;doc_button_goto_main;"..F("Go to category list").."]"
|
||||||
else
|
else
|
||||||
formstring = formstring .. "label[0,0.5;This category has the following entries:]"
|
formstring = formstring .. "label[0,0.5;"..F("This category has the following entries:").."]"
|
||||||
formstring = formstring .. doc.generate_entry_list(id, playername)
|
formstring = formstring .. doc.generate_entry_list(id, playername)
|
||||||
formstring = formstring .. "button[0,8;3,1;doc_button_goto_entry;Show entry]"
|
formstring = formstring .. "button[0,8;3,1;doc_button_goto_entry;"..F("Show entry").."]"
|
||||||
formstring = formstring .. "label[8,8;Number of entries: "..total.."\n"
|
formstring = formstring .. "label[8,8;"..minetest.formspec_escape(string.format(S("Number of entries: %d"), total)).."\n"
|
||||||
local viewed = doc.get_viewed_count(playername, id)
|
local viewed = doc.get_viewed_count(playername, id)
|
||||||
local hidden = total - revealed
|
local hidden = total - revealed
|
||||||
local new = total - viewed - hidden
|
local new = total - viewed - hidden
|
||||||
-- TODO/FIXME: Check if number of hidden/viewed entries is always correct
|
-- TODO/FIXME: Check if number of hidden/viewed entries is always correct
|
||||||
if viewed < total then
|
if viewed < total then
|
||||||
formstring = formstring .. "New entries: "..new
|
formstring = formstring .. minetest.formspec_escape(string.format(S("New entries: %d"), new))
|
||||||
if hidden > 0 then
|
if hidden > 0 then
|
||||||
formstring = formstring .. "\n"
|
formstring = formstring .. "\n"
|
||||||
formstring = formstring .. "Hidden entries: "..hidden.."]"
|
formstring = formstring .. minetest.formspec_escape(string.format(S("Hidden entries: %d"), hidden)).."]"
|
||||||
else
|
else
|
||||||
formstring = formstring .. "]"
|
formstring = formstring .. "]"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
formstring = formstring .. "All entries read.]"
|
formstring = formstring .. F("All entries read.").."]"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
formstring = formstring .. "label[0,0.5;This category is empty.]"
|
formstring = formstring .. "label[0,0.5;"..F("This category is empty.").."]"
|
||||||
formstring = formstring .. "button[0,1.5;3,1;doc_button_goto_main;Go to category list]"
|
formstring = formstring .. "button[0,1.5;3,1;doc_button_goto_main;"..F("Go to category list").."]"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return formstring
|
return formstring
|
||||||
@ -663,33 +679,33 @@ function doc.formspec_entry_navigation(category_id, entry_id)
|
|||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
local formstring = ""
|
local formstring = ""
|
||||||
formstring = formstring .. "button[10,8.5;1,1;doc_button_goto_prev;<]"
|
formstring = formstring .. "button[10,8.5;1,1;doc_button_goto_prev;"..F("<").."]"
|
||||||
formstring = formstring .. "button[11,8.5;1,1;doc_button_goto_next;>]"
|
formstring = formstring .. "button[11,8.5;1,1;doc_button_goto_next;"..F(">").."]"
|
||||||
formstring = formstring .. "tooltip[doc_button_goto_prev;Show previous entry]"
|
formstring = formstring .. "tooltip[doc_button_goto_prev;"..F("Show previous entry").."]"
|
||||||
formstring = formstring .. "tooltip[doc_button_goto_next;Show next entry]"
|
formstring = formstring .. "tooltip[doc_button_goto_next;"..F("Show next entry").."]"
|
||||||
return formstring
|
return formstring
|
||||||
end
|
end
|
||||||
|
|
||||||
function doc.formspec_entry(category_id, entry_id)
|
function doc.formspec_entry(category_id, entry_id)
|
||||||
local formstring
|
local formstring
|
||||||
if category_id == nil then
|
if category_id == nil then
|
||||||
formstring = "label[0,0;You haven't chosen a category yet. Please choose one in the category list first.]"
|
formstring = "label[0,0;"..F("You haven't chosen a category yet. Please choose one in the category list first.").."]"
|
||||||
formstring = formstring .. "button[0,1;3,1;doc_button_goto_main;Go to category list]"
|
formstring = formstring .. "button[0,1;3,1;doc_button_goto_main;"..F("Go to category list").."]"
|
||||||
elseif entry_id == nil then
|
elseif entry_id == nil then
|
||||||
formstring = "label[0,0;Help > "..doc.data.categories[category_id].def.name.." > (No Entry)]"
|
formstring = "label[0,0;"..minetest.formspec_escape(string.format(S("Help > %s > (No Entry)"), doc.data.categories[category_id].def.name)) .. "]"
|
||||||
if doc.get_entry_count(category_id) >= 1 then
|
if doc.get_entry_count(category_id) >= 1 then
|
||||||
formstring = formstring .. "label[0,0.5;You haven't chosen an entry yet. Please choose one in the entry list first.]"
|
formstring = formstring .. "label[0,0.5;"..F("You haven't chosen an entry yet. Please choose one in the entry list first.").."]"
|
||||||
formstring = formstring .. "button[0,1.5;3,1;doc_button_goto_category;Go to entry list]"
|
formstring = formstring .. "button[0,1.5;3,1;doc_button_goto_category;"..F("Go to entry list").."]"
|
||||||
else
|
else
|
||||||
formstring = formstring .. "label[0,0.5;This category does not have any entries.]"
|
formstring = formstring .. "label[0,0.5;"..F("This category does not have any entries.").."]"
|
||||||
formstring = formstring .. "button[0,1.5;3,1;doc_button_goto_main;Go to category list]"
|
formstring = formstring .. "button[0,1.5;3,1;doc_button_goto_main;"..F("Go to category list").."]"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
||||||
local category = doc.data.categories[category_id]
|
local category = doc.data.categories[category_id]
|
||||||
local entry = doc.get_entry(category_id, entry_id)
|
local entry = doc.get_entry(category_id, entry_id)
|
||||||
|
|
||||||
formstring = "label[0,0;Help > "..category.def.name.." > "..entry.name.."]"
|
formstring = "label[0,0;"..minetest.formspec_escape(string.format(S("Help > %s > %s"), category.def.name, entry.name)).."]"
|
||||||
formstring = formstring .. category.def.build_formspec(entry.data)
|
formstring = formstring .. category.def.build_formspec(entry.data)
|
||||||
formstring = formstring .. doc.formspec_entry_navigation(category_id, entry_id)
|
formstring = formstring .. doc.formspec_entry_navigation(category_id, entry_id)
|
||||||
end
|
end
|
||||||
@ -811,7 +827,7 @@ minetest.register_on_player_receive_fields(doc.process_form)
|
|||||||
|
|
||||||
minetest.register_chatcommand("doc", {
|
minetest.register_chatcommand("doc", {
|
||||||
params = "",
|
params = "",
|
||||||
description = "Open documentation system.",
|
description = S("Open documentation system"),
|
||||||
privs = {},
|
privs = {},
|
||||||
func = function(playername, param)
|
func = function(playername, param)
|
||||||
doc.show_doc(playername)
|
doc.show_doc(playername)
|
||||||
@ -872,7 +888,7 @@ if minetest.get_modpath("unified_inventory") ~= nil then
|
|||||||
unified_inventory.register_button("doc", {
|
unified_inventory.register_button("doc", {
|
||||||
type = "image",
|
type = "image",
|
||||||
image = "doc_button_icon_hires.png",
|
image = "doc_button_icon_hires.png",
|
||||||
tooltip = "Documentation System",
|
tooltip = S("Documentation System"),
|
||||||
action = function(player)
|
action = function(player)
|
||||||
doc.show_doc(player:get_player_name())
|
doc.show_doc(player:get_player_name())
|
||||||
end,
|
end,
|
||||||
@ -880,13 +896,13 @@ if minetest.get_modpath("unified_inventory") ~= nil then
|
|||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_privilege("doc_reveal", {
|
minetest.register_privilege("doc_reveal", {
|
||||||
description = "Allows you to reveal all hidden help entries with /doc_reveal",
|
description = S("Allows you to reveal all hidden help entries with /doc_reveal"),
|
||||||
give_to_singleplayer = false
|
give_to_singleplayer = false
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_chatcommand("doc_reveal", {
|
minetest.register_chatcommand("doc_reveal", {
|
||||||
params = "",
|
params = "",
|
||||||
description = "Reveals all hidden help entries to you",
|
description = S("Reveals all hidden help entries to you"),
|
||||||
privs = { doc_reveal = true },
|
privs = { doc_reveal = true },
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
doc.mark_all_entries_as_revealed(name)
|
doc.mark_all_entries_as_revealed(name)
|
||||||
|
32
locale/template.txt
Normal file
32
locale/template.txt
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
< =
|
||||||
|
> =
|
||||||
|
All entries read. =
|
||||||
|
All help entries unlocked! =
|
||||||
|
Allows you to reveal all hidden help entries with /doc_reveal =
|
||||||
|
Category list =
|
||||||
|
Currently all entries in this category are hidden from you.\\nUnlock new entries by proceeding in the game. =
|
||||||
|
Documentation System =
|
||||||
|
Entry =
|
||||||
|
Entry list =
|
||||||
|
Go to category list =
|
||||||
|
Go to entry list =
|
||||||
|
Help > %s =
|
||||||
|
Help > %s > %s =
|
||||||
|
Help > %s > (No Entry) =
|
||||||
|
Hidden entries: %d =
|
||||||
|
New entries: %d =
|
||||||
|
New help entry unlocked: %s > %s =
|
||||||
|
Number of entries: %d =
|
||||||
|
OK =
|
||||||
|
Open documentation system =
|
||||||
|
Please select a category you wish to learn more about: =
|
||||||
|
Reveals all hidden help entries to you =
|
||||||
|
Show entry =
|
||||||
|
Show next entry =
|
||||||
|
Show previous entry =
|
||||||
|
This category does not have any entries. =
|
||||||
|
This category has the following entries: =
|
||||||
|
This category is empty. =
|
||||||
|
This is the Documentation System, Version %s. =
|
||||||
|
You haven't chosen a category yet. Please choose one in the category list first. =
|
||||||
|
You haven't chosen an entry yet. Please choose one in the entry list first. =
|
Loading…
x
Reference in New Issue
Block a user