diff --git a/depends.txt b/depends.txt index 4451908..c2a3e1b 100644 --- a/depends.txt +++ b/depends.txt @@ -1,3 +1,4 @@ default stairs moreblocks? +intllib? \ No newline at end of file diff --git a/init.lua b/init.lua index 63be0c5..c2870a7 100644 --- a/init.lua +++ b/init.lua @@ -1,16 +1,20 @@ local settings = Settings(minetest.get_modpath("quartz").."/settings.txt") +-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + -- -- Item Registration -- -- Quartz Crystal minetest.register_craftitem("quartz:quartz_crystal", { - description = "Quartz Crystal", + description = S("Quartz Crystal"), inventory_image = "quartz_crystal_full.png", }) minetest.register_craftitem("quartz:quartz_crystal_piece", { - description = "Quartz Crystal Piece", + description = S("Quartz Crystal Piece"), inventory_image = "quartz_crystal_piece.png", }) @@ -20,7 +24,7 @@ minetest.register_craftitem("quartz:quartz_crystal_piece", { -- Ore minetest.register_node("quartz:quartz_ore", { - description = "Quartz Ore", + description = S("Quartz Ore"), tiles = {"default_stone.png^quartz_ore.png"}, groups = {cracky=3, stone=1}, drop = 'quartz:quartz_crystal', @@ -40,7 +44,7 @@ minetest.register_ore({ -- Quartz Block minetest.register_node("quartz:block", { - description = "Quartz Block", + description = S("Quartz Block"), tiles = {"quartz_block.png"}, groups = {cracky=3, oddly_breakable_by_hand=1}, sounds = default.node_sound_glass_defaults(), @@ -48,7 +52,7 @@ minetest.register_node("quartz:block", { -- Chiseled Quartz minetest.register_node("quartz:chiseled", { - description = "Chiseled Quartz", + description = S("Chiseled Quartz"), tiles = {"quartz_chiseled.png"}, groups = {cracky=3, oddly_breakable_by_hand=1}, sounds = default.node_sound_glass_defaults(), @@ -56,7 +60,7 @@ minetest.register_node("quartz:chiseled", { -- Quartz Pillar minetest.register_node("quartz:pillar", { - description = "Quartz Pillar", + description = S("Quartz Pillar"), paramtype2 = "facedir", tiles = {"quartz_pillar_top.png", "quartz_pillar_top.png", "quartz_pillar_side.png"}, groups = {cracky=3, oddly_breakable_by_hand=1}, @@ -68,15 +72,15 @@ minetest.register_node("quartz:pillar", { stairs.register_stair_and_slab("quartzblock", "quartz:block", {cracky=3, oddly_breakable_by_hand=1}, {"quartz_block.png"}, - "Quartz stair", - "Quartz slab", + S("Quartz stair"), + S("Quartz slab"), default.node_sound_glass_defaults()) -stairs.register_slab("quartzstair", "quartz:pillar", +stairs.register_stair_and_slab("quartzstair", "quartz:pillar", {cracky=3, oddly_breakable_by_hand=1}, {"quartz_pillar_top.png", "quartz_pillar_top.png", "quartz_pillar_side.png"}, - "Quartz Pillar stair", - "Quartz Pillar slab", + S("Quartz Pillar stair"), + S("Quartz Pillar slab"), default.node_sound_glass_defaults()) -- 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/template.pot b/locale/template.pot new file mode 100644 index 0000000..9c78dda --- /dev/null +++ b/locale/template.pot @@ -0,0 +1,57 @@ +# 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-02-19 21:50-0700\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: init.lua:13 +msgid "Quartz Crystal" +msgstr "" + +#: init.lua:17 +msgid "Quartz Crystal Piece" +msgstr "" + +#: init.lua:27 +msgid "Quartz Ore" +msgstr "" + +#: init.lua:47 +msgid "Quartz Block" +msgstr "" + +#: init.lua:55 +msgid "Chiseled Quartz" +msgstr "" + +#: init.lua:63 +msgid "Quartz Pillar" +msgstr "" + +#: init.lua:75 +msgid "Quartz stair" +msgstr "" + +#: init.lua:76 +msgid "Quartz slab" +msgstr "" + +#: init.lua:82 +msgid "Quartz Pillar stair" +msgstr "" + +#: init.lua:83 +msgid "Quartz Pillar slab" +msgstr ""