From 85e9ffc80aa96d36f326b6871f3baae3ec7886ae Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Mon, 19 Feb 2018 10:28:21 +0000 Subject: [PATCH] added intllib support and malay translation (thanks MuhdNurHidayat) --- depends.txt | 1 + init.lua | 26 +++++++++++--------- intllib.lua | 45 ++++++++++++++++++++++++++++++++++ locale/ms.po | 59 +++++++++++++++++++++++++++++++++++++++++++++ locale/template.pot | 58 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 178 insertions(+), 11 deletions(-) create mode 100644 intllib.lua create mode 100644 locale/ms.po create mode 100644 locale/template.pot diff --git a/depends.txt b/depends.txt index 0dc5ef3..5ccba0d 100644 --- a/depends.txt +++ b/depends.txt @@ -1,2 +1,3 @@ mobs lucky_block? +intllib? diff --git a/init.lua b/init.lua index c588b15..6790cac 100644 --- a/init.lua +++ b/init.lua @@ -1,4 +1,8 @@ +-- intllib +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP .. "/intllib.lua") + -- rideable horse mobs:register_mob("mob_horse:horse", { @@ -141,7 +145,7 @@ mobs:spawn({ day_toggle = true, }) -mobs:register_egg("mob_horse:horse", "Horse", "wool_brown.png", 1) +mobs:register_egg("mob_horse:horse", S("Horse"), "wool_brown.png", 1) -- horseshoe helper function @@ -164,21 +168,21 @@ local apply_shoes = function(name, itemstack, obj, shoes, speed, jump, reverse) ent.accel = speed ent.shoed = shoes - minetest.chat_send_player(name, "Horse shoes fitted -" - .. " speed: " .. speed - .. " , jump height: " .. jump - .. " , stop speed: " .. reverse) + minetest.chat_send_player(name, S("Horse shoes fitted -") + .. S(" speed: ") .. speed + .. S(" , jump height: ") .. jump + .. S(" , stop speed: ") .. reverse) itemstack:take_item() ; return itemstack else - minetest.chat_send_player(name, "Horse shoes only work on horses!") + minetest.chat_send_player(name, S("Horse shoes only work on horses!")) end end -- steel horseshoes minetest.register_craftitem(":mobs:horseshoe_steel", { - description = "Steel HorseShoes (use on horse to apply)", + description = S("Steel HorseShoes (use on horse to apply)"), inventory_image = "mobs_horseshoe_steel.png", on_use = function(itemstack, user, pointed_thing) return apply_shoes(user:get_player_name(), itemstack, pointed_thing, @@ -197,7 +201,7 @@ minetest.register_craft({ -- bronze horseshoes minetest.register_craftitem(":mobs:horseshoe_bronze", { - description = "Bronze HorseShoes (use on horse to apply)", + description = S("Bronze HorseShoes (use on horse to apply)"), inventory_image = "mobs_horseshoe_bronze.png", on_use = function(itemstack, user, pointed_thing) return apply_shoes(user:get_player_name(), itemstack, pointed_thing, @@ -216,7 +220,7 @@ minetest.register_craft({ -- mese horseshoes minetest.register_craftitem(":mobs:horseshoe_mese", { - description = "Mese HorseShoes (use on horse to apply)", + description = S("Mese HorseShoes (use on horse to apply)"), inventory_image = "mobs_horseshoe_mese.png", on_use = function(itemstack, user, pointed_thing) return apply_shoes(user:get_player_name(), itemstack, pointed_thing, @@ -235,7 +239,7 @@ minetest.register_craft({ -- diamond horseshoes minetest.register_craftitem(":mobs:horseshoe_diamond", { - description = "Diamond HorseShoes (use on horse to apply)", + description = S("Diamond HorseShoes (use on horse to apply)"), inventory_image = "mobs_horseshoe_diamond.png", on_use = function(itemstack, user, pointed_thing) return apply_shoes(user:get_player_name(), itemstack, pointed_thing, @@ -262,4 +266,4 @@ lucky_block:add_blocks({ {"dro", {"mobs:horseshoe_diamond"}}, }) -end \ No newline at end of file +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/ms.po b/locale/ms.po new file mode 100644 index 0000000..fa76d1a --- /dev/null +++ b/locale/ms.po @@ -0,0 +1,59 @@ +# 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. +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-02-06 00:07+0800\n" +"PO-Revision-Date: 2018-02-06 00:14+0800\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.0.6\n" +"Last-Translator: MuhdNurHidayat (MNH48) \n" +"Plural-Forms: nplurals=1; plural=0;\n" +"Language: ms\n" + +#: init.lua +msgid "Horse" +msgstr "Kuda" + +#: init.lua +msgid "Horse shoes fitted -" +msgstr "Ladam telah dipasang pada kuda -" + +#: init.lua +msgid " speed: " +msgstr " kelajuan: " + +#: init.lua +msgid " , jump height: " +msgstr " , ketinggian lompat: " + +#: init.lua +msgid " , stop speed: " +msgstr " , kelajuan berhenti: " + +#: init.lua +msgid "Horse shoes only work on horses!" +msgstr "Ladam hanya boleh dipakaikan pada kuda!" + +#: init.lua +msgid "Steel HorseShoes (use on horse to apply)" +msgstr "Ladam Kuda Keluli (guna pada kuda untuk pakaikan ia)" + +#: init.lua +msgid "Bronze HorseShoes (use on horse to apply)" +msgstr "Ladam Kuda Gangsa (guna pada kuda untuk pakaikan ia)" + +#: init.lua +msgid "Mese HorseShoes (use on horse to apply)" +msgstr "Ladam Kuda Mese (guna pada kuda untuk pakaikan ia)" + +#: init.lua +msgid "Diamond HorseShoes (use on horse to apply)" +msgstr "Ladam Kuda Intan (guna pada kuda untuk pakaikan ia)" diff --git a/locale/template.pot b/locale/template.pot new file mode 100644 index 0000000..7811c0e --- /dev/null +++ b/locale/template.pot @@ -0,0 +1,58 @@ +# 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: 2018-02-06 00:07+0800\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 "Horse" +msgstr "" + +#: init.lua +msgid "Horse shoes fitted -" +msgstr "" + +#: init.lua +msgid " speed: " +msgstr "" + +#: init.lua +msgid " , jump height: " +msgstr "" + +#: init.lua +msgid " , stop speed: " +msgstr "" + +#: init.lua +msgid "Horse shoes only work on horses!" +msgstr "" + +#: init.lua +msgid "Steel HorseShoes (use on horse to apply)" +msgstr "" + +#: init.lua +msgid "Bronze HorseShoes (use on horse to apply)" +msgstr "" + +#: init.lua +msgid "Mese HorseShoes (use on horse to apply)" +msgstr "" + +#: init.lua +msgid "Diamond HorseShoes (use on horse to apply)" +msgstr ""