From 1c507021bf49ddecd46b3c37862fc46903a95f5f Mon Sep 17 00:00:00 2001 From: fat115 Date: Fri, 4 Aug 2017 15:07:28 +0200 Subject: [PATCH] add intllib support (i18n) add french translation --- depends.txt | 1 + init.lua | 16 +++++++++------ intllib.lua | 45 ++++++++++++++++++++++++++++++++++++++++ locale/fr.po | 50 +++++++++++++++++++++++++++++++++++++++++++++ locale/template.pot | 44 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 150 insertions(+), 6 deletions(-) create mode 100644 depends.txt create mode 100644 intllib.lua create mode 100644 locale/fr.po create mode 100644 locale/template.pot diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..77e8d97 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +intllib? diff --git a/init.lua b/init.lua index aaa89c1..78773ac 100644 --- a/init.lua +++ b/init.lua @@ -13,6 +13,10 @@ math.randomseed(os.time()) random_messages = {} random_messages.messages = {} --This table contains all messages. +-- Load support for intllib. +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + function table.count( t ) local i = 0 for k in pairs( t ) do i = i + 1 end @@ -58,8 +62,8 @@ function random_messages.read_messages() local output = io.open(minetest.get_worldpath().."/random_messages","w") if not default_input then -- blame the admin if not found - output:write("Blame the server admin! He/She has probably not edited the random messages yet.\n") - output:write("Tell your dumb admin that this line is in (worldpath)/random_messages \n") + output:write(S("Blame the server admin! He/She has probably not edited the random messages yet.\n")) + output:write(S("Tell your dumb admin that this line is in (worldpath)/random_messages\n")) else -- or write default_input content in worldpath message file local content = default_input:read("*all") @@ -130,7 +134,7 @@ end) local register_chatcommand_table = { params = "viewmessages | removemessage | addmessage ", privs = {server = true}, - description = "View and/or alter the server's random messages", + description = S("View and/or alter the server's random messages"), func = function(name,param) local t = string.split(param, " ") if t[1] == "viewmessages" then @@ -141,7 +145,7 @@ local register_chatcommand_table = { function (params) if not tonumber(params[2]) or random_messages.messages[tonumber(params[2])] == nil then - return false,"ERROR: No such message." + return false,S("ERROR: No such message.") end return true end, @@ -149,12 +153,12 @@ local register_chatcommand_table = { random_messages.remove_message(t[2]) elseif t[1] == "addmessage" then if not t[2] then - minetest.chat_send_player(name,"ERROR: No message.") + minetest.chat_send_player(name,S("ERROR: No message.")) else random_messages.add_message(t) end else - minetest.chat_send_player(name,"ERROR: Invalid command.") + minetest.chat_send_player(name,S("ERROR: Invalid command.")) end 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/fr.po b/locale/fr.po new file mode 100644 index 0000000..eb7c919 --- /dev/null +++ b/locale/fr.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. +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-08-04 15:04+0200\n" +"PO-Revision-Date: 2017-08-04 15:05+0200\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 1.8.12\n" +"Last-Translator: fat115 \n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" +"Language: fr\n" + +#: init.lua +msgid "" +"Blame the server admin! He/She has probably not edited the random messages " +"yet.\n" +msgstr "" +"Tirez les oreilles à l'administrateur du serveur. Il/elle n'a pas encore " +"modifié les messages aléatoires.\n" + +#: init.lua +msgid "" +"Tell your dumb admin that this line is in (worldpath)/random_messages\n" +msgstr "" +"Dites à votre administrateur à la noix que cette ligne se trouve dans " +"(worldpath)/random_messages\n" + +#: init.lua +msgid "View and/or alter the server's random messages" +msgstr "Afficher et/ou modifier les messages aléatoires du serveur" + +#: init.lua +msgid "ERROR: No such message." +msgstr "ERREUR : ce message est inexistant." + +#: init.lua +msgid "ERROR: No message." +msgstr "ERREUR : pas de message." + +#: init.lua +msgid "ERROR: Invalid command." +msgstr "ERREUR : Commande invalide." diff --git a/locale/template.pot b/locale/template.pot new file mode 100644 index 0000000..9384e0f --- /dev/null +++ b/locale/template.pot @@ -0,0 +1,44 @@ +# 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-08-04 15:04+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 "" +"Blame the server admin! He/She has probably not edited the random messages " +"yet.\n" +msgstr "" + +#: init.lua +msgid "Tell your dumb admin that this line is in (worldpath)/random_messages\n" +msgstr "" + +#: init.lua +msgid "View and/or alter the server's random messages" +msgstr "" + +#: init.lua +msgid "ERROR: No such message." +msgstr "" + +#: init.lua +msgid "ERROR: No message." +msgstr "" + +#: init.lua +msgid "ERROR: Invalid command." +msgstr ""