From d028ecfc55b42dc15da65a34f627483934f3e252 Mon Sep 17 00:00:00 2001 From: supertobi Date: Tue, 26 Jan 2016 22:40:36 +0100 Subject: [PATCH 1/5] Update gettextExample.lua improved readability --- examples/gettextExample.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/gettextExample.lua b/examples/gettextExample.lua index 7a90410..6efbe06 100644 --- a/examples/gettextExample.lua +++ b/examples/gettextExample.lua @@ -42,10 +42,12 @@ dt.configuration.check_version(...,{3,0,0}) -- Not translated Text dt.print_error("Hello World!") +local gettext = dt.gettext -- Translate a string using the darktable textdomain -dt.print_error(dt.gettext.gettext("image")) +dt.print_error(gettext.gettext("image")) -- Tell gettext where to find the .mo file translating messages for a particular domain -dt.gettext.bindtextdomain("gettextExample",".config/darktable/lua/") +gettext.bindtextdomain("gettextExample",".config/darktable/lua/") -- Translate a string using the specified textdomain -dt.print_error(dt.gettext.dgettext("gettextExample", 'Hello World!')) +local _ = gettext.dgettext +dt.print_error(_("gettextExample", 'Hello World!')) From 95d8e777db7fb68a8ec14ac78ccd76528460c589 Mon Sep 17 00:00:00 2001 From: supertobi Date: Fri, 29 Jan 2016 14:21:46 +0100 Subject: [PATCH 2/5] Update gettextExample.lua --- examples/gettextExample.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/examples/gettextExample.lua b/examples/gettextExample.lua index 6efbe06..c59fe8d 100644 --- a/examples/gettextExample.lua +++ b/examples/gettextExample.lua @@ -18,6 +18,22 @@ --[[ darktable script to show how translations works +To create the .po file run: +xgettext -l lua gettextExample.lua + +xgettext is not a lua tool, it knows (almost) nothing about Lua, and not +enough to do a proper parsing. It takes a text file (In our case a Lua +file) and recognises a few (language dependant) keyword in there. +It matches those keywords with internal description on how functions are +called and creates the .po file accordingly. (For example, it knows that +the first argument of gettext() is the translated string, but that it's +the second argument for dgettext) +This is important because it means that if you use some neat Lua tricks +(like renaming functions) xgettext won't recognize those calls and won't +extract the string to the .po file. +So, this is why we create a local variagle gettext = dt.gettext, so +xgettext recognises gettext.gettext as a function but not dt.gettext.gettext + To create a .mo file run: msgfmt -v gettextExample.po -o gettextExample.mo @@ -49,5 +65,4 @@ dt.print_error(gettext.gettext("image")) -- Tell gettext where to find the .mo file translating messages for a particular domain gettext.bindtextdomain("gettextExample",".config/darktable/lua/") -- Translate a string using the specified textdomain -local _ = gettext.dgettext dt.print_error(_("gettextExample", 'Hello World!')) From 87a6ed3e46e05c895434929a4fd5af833ad8e3a6 Mon Sep 17 00:00:00 2001 From: supertobi Date: Fri, 29 Jan 2016 14:26:31 +0100 Subject: [PATCH 3/5] Update gettextExample.lua bindtextdomain changed: ~/ --- examples/gettextExample.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gettextExample.lua b/examples/gettextExample.lua index c59fe8d..21e42f5 100644 --- a/examples/gettextExample.lua +++ b/examples/gettextExample.lua @@ -63,6 +63,6 @@ local gettext = dt.gettext dt.print_error(gettext.gettext("image")) -- Tell gettext where to find the .mo file translating messages for a particular domain -gettext.bindtextdomain("gettextExample",".config/darktable/lua/") +gettext.bindtextdomain("gettextExample","~/.config/darktable/lua/") -- Translate a string using the specified textdomain dt.print_error(_("gettextExample", 'Hello World!')) From 72a97ecbd60e64e7b94c4985a8c8ee46450afc4a Mon Sep 17 00:00:00 2001 From: supertobi Date: Fri, 29 Jan 2016 22:18:54 +0100 Subject: [PATCH 4/5] Update gettextExample.lua --- examples/gettextExample.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/gettextExample.lua b/examples/gettextExample.lua index 21e42f5..0230953 100644 --- a/examples/gettextExample.lua +++ b/examples/gettextExample.lua @@ -63,6 +63,5 @@ local gettext = dt.gettext dt.print_error(gettext.gettext("image")) -- Tell gettext where to find the .mo file translating messages for a particular domain -gettext.bindtextdomain("gettextExample","~/.config/darktable/lua/") -- Translate a string using the specified textdomain -dt.print_error(_("gettextExample", 'Hello World!')) +dt.print_error(gettext.dgettext("gettextExample", 'Hello World!')) From 077a7de605ba8b96e28e2dd00adef797e7eac3fb Mon Sep 17 00:00:00 2001 From: supertobi Date: Fri, 29 Jan 2016 23:01:05 +0100 Subject: [PATCH 5/5] Update gettextExample.lua function _(msgid) --- examples/gettextExample.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/gettextExample.lua b/examples/gettextExample.lua index 0230953..6207333 100644 --- a/examples/gettextExample.lua +++ b/examples/gettextExample.lua @@ -63,5 +63,14 @@ local gettext = dt.gettext dt.print_error(gettext.gettext("image")) -- Tell gettext where to find the .mo file translating messages for a particular domain + +gettext.bindtextdomain("gettextExample",dt.configuration.config_dir.."/lua/") -- Translate a string using the specified textdomain dt.print_error(gettext.dgettext("gettextExample", 'Hello World!')) + +-- Define a local function called _ to make the code more readable and have it call dgettext +-- with the proper domain. +local function _(msgid) + return gettext.dgettext("gettextExample", msgid) +end +dt.print_error(_('Hello World!'))