From 8bd2e86e8787717c222eb8e39949513107b81870 Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Mon, 28 Aug 2017 11:22:18 +0100 Subject: [PATCH] added intllib support and russian translation --- README.md | 2 +- blocks.lua | 9 ++++++-- depends.txt | 1 + init.lua | 17 +++++++++------ intllib.lua | 45 ++++++++++++++++++++++++++++++++++++++++ locale/ru.po | 50 +++++++++++++++++++++++++++++++++++++++++++++ locale/template.pot | 50 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 165 insertions(+), 9 deletions(-) create mode 100644 intllib.lua create mode 100644 locale/ru.po create mode 100644 locale/template.pot diff --git a/README.md b/README.md index 6698583..5a6d016 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,6 @@ Changelog: - 0.4 - Added ability to add custom functions within lucky blocks - 0.5 - Explosions now have radius and fire setting, also added new blocks - 0.6 - Use TNT mod for explosions and if not active do entity damage only -- 0.7 - Added new floor feature to blocks and moreblocks support +- 0.7 - Added new floor feature and moreblocks support Lucky Blocks: 136 (depending on mods enabled) diff --git a/blocks.lua b/blocks.lua index 0177b6d..01ad59f 100644 --- a/blocks.lua +++ b/blocks.lua @@ -1,4 +1,9 @@ +-- Load support for intllib. +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + + -- Default tree schematics local dpath = minetest.get_modpath("default") .. "/schematics/" @@ -104,7 +109,7 @@ if minetest.get_modpath("screwdriver") then if screwdriver and screwdriver.handler then minetest.register_tool(":screwdriver:screwdriver_magenta", { - description = "Super Mega Magenta Ultra Screwdriver 2500\n(left-click to rotate face, right-click to rotates axis)", + description = S("Super Mega Magenta Ultra Screwdriver 2500\n(left-click to rotate face, right-click to rotates axis)"), inventory_image = "screwdriver.png^[colorize:#ff009970", groups = {not_in_creative_inventory = 1}, @@ -347,7 +352,7 @@ end -- Special items minetest.register_node("lucky_block:void_mirror", { - description = "Void Mirror (Place to see through solid walls during daytime)", + description = S("Void Mirror (Place to see through solid walls during daytime)"), drawtype = "normal", tiles = {"default_obsidian_glass.png^[brighten"}, use_texture_alpha = true, diff --git a/depends.txt b/depends.txt index 7a5ba44..a853965 100644 --- a/depends.txt +++ b/depends.txt @@ -1,3 +1,4 @@ default tnt? screwdriver? +intllib? diff --git a/init.lua b/init.lua index 7b79c01..2d513f4 100644 --- a/init.lua +++ b/init.lua @@ -3,6 +3,11 @@ lucky_block = {} lucky_schems = {} +-- Load support for intllib. +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + + -- example custom function (punches player with 5 damage) local function punchy(pos, player) @@ -11,7 +16,7 @@ local function punchy(pos, player) damage_groups = {fleshy = 5} }, nil) - minetest.chat_send_player(player:get_player_name(), "Stop hitting yourself!") + minetest.chat_send_player(player:get_player_name(), S("Stop hitting yourself!")) end @@ -40,7 +45,7 @@ local function bushy(pos, player) player_inv:set_stack("main", i, "default:dry_shrub") end - minetest.chat_send_player(player:get_player_name(), "Dry Shrub Takeover!") + minetest.chat_send_player(player:get_player_name(), S("Dry shrub takeover!")) end @@ -370,7 +375,7 @@ local lucky_block = function(pos, digger) effect(pos, 25, "tnt_smoke.png", 8, 8, 1, -10, 0) - minetest.chat_send_player(digger:get_player_name(), "Random Teleport!") + minetest.chat_send_player(digger:get_player_name(), S("Random Teleport!")) -- drop items elseif action == "dro" then @@ -565,7 +570,7 @@ end -- lucky block itself minetest.register_node('lucky_block:lucky_block', { - description = "Lucky Block", + description = S("Lucky Block"), tiles = {{ name = "lucky_block_animated.png", animation = { @@ -603,7 +608,7 @@ minetest.register_craft({ -- super lucky block minetest.register_node('lucky_block:super_lucky_block', { - description = "Super Lucky Block (use Pick)", + description = S("Super Lucky Block (use pick)"), tiles = {{ name="lucky_block_super_animated.png", animation = { @@ -654,6 +659,6 @@ minetest.register_node('lucky_block:super_lucky_block', { minetest.after(0, function() - print ("[MOD] Lucky Blocks loaded (" .. #lucky_list .. " in total)") + print (S("[MOD] Lucky Blocks loaded (@1 in total)", #lucky_list)) end) diff --git a/intllib.lua b/intllib.lua new file mode 100644 index 0000000..6669d72 --- /dev/null +++ b/intllib.lua @@ -0,0 +1,45 @@ + +-- Fallback functions for when `intllib` is not installed. +-- Code released under Unlicense . + +-- 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 diff --git a/locale/ru.po b/locale/ru.po new file mode 100644 index 0000000..2405290 --- /dev/null +++ b/locale/ru.po @@ -0,0 +1,50 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-05-14 08:34+0200\n" +"PO-Revision-Date: 2017-08-28 11:14+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: ru\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: init.lua +msgid "Stop hitting yourself!" +msgstr "Прекратите удары себя" + +#: init.lua +msgid "Dry shrub takeover!" +msgstr "Поглощение сухих кустов" + +#: init.lua +msgid "Random teleport!" +msgstr "Случайный телепорт!" + +#: init.lua +msgid "Lucky Block" +msgstr "Удачливый блок" + +#: init.lua +msgid "Super Lucky Block (use pick)" +msgstr "Супер удачливый блок (используйте кирку)" + +#: init.lua +msgid "[MOD] Lucky Blocks loaded (@1 in total)" +msgstr "[MOD] Удачливый блок нагруженный (Всего @1)" + +#: blocks.lua +msgid "Super Mega Magenta Ultra Screwdriver 2500\n(left-click to rotate face, right-click to rotates axis)" +msgstr "Пурпурная супер мега ультра отвёртка 2500\n(левая кнопка для вращения лицевой части, правая кнопка для вращения осей)" + +#: blocks.lua +msgid "Void Mirror (Place to see through solid walls during daytime" +msgstr "Пустое зеркало (Установите, чтобы видеть сквозь сплошные стены в дневное время)" diff --git a/locale/template.pot b/locale/template.pot new file mode 100644 index 0000000..546877c --- /dev/null +++ b/locale/template.pot @@ -0,0 +1,50 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-05-14 08:34+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: init.lua +msgid "Stop hitting yourself!" +msgstr "" + +#: init.lua +msgid "Dry shrub takeover!" +msgstr "" + +#: init.lua +msgid "Random teleport!" +msgstr "" + +#: init.lua +msgid "Lucky Block" +msgstr "" + +#: init.lua +msgid "Super Lucky Block (use pick)" +msgstr "" + +#: init.lua +msgid "[MOD] Lucky Blocks loaded (@1 in total)" +msgstr "" + +#: blocks.lua +msgid "Super Mega Magenta Ultra Screwdriver 2500\n(left-click to rotate face, right-click to rotates axis)" +msgstr "" + +#: blocks.lua +msgid "Void Mirror (Place to see through solid walls during daytime" +msgstr ""