From c7205ad47e6bd7e7816ef5186f463c53ea4a046e Mon Sep 17 00:00:00 2001 From: SQP Date: Mon, 8 Jun 2015 13:59:21 +0200 Subject: Fix translations with DGettext (and other D... func) when the domain name is empty. According to the doc, NULL allow to use the current domain as fallback: http://www.gnu.org/software/libc/manual/html_node/Translation-with-gettext.html If the domainname parameter is the null pointer the dgettext function is exactly equivalent to gettext since the default value for the domain name is used. --- gettext_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'gettext_test.go') diff --git a/gettext_test.go b/gettext_test.go index b651152..8e88180 100644 --- a/gettext_test.go +++ b/gettext_test.go @@ -128,3 +128,36 @@ func TestGermanDeutschland(t *testing.T) { } } + +func TestDGettextFallback(t *testing.T) { + os.Setenv("LANGUAGE", "de_DE.utf8") + + SetLocale(LC_ALL, "") + BindTextdomain("example", "./examples/") + Textdomain("example") + + t1 := DGettext("", "Hello, world!") + + fmt.Println(t1) + + if t1 != "Hallo, Welt!" { + t.Errorf("Failed translation fallback.") + } + + t2 := Sprintf(DNGettext("", "An apple", "%d apples", 1), 1, "garbage") + + fmt.Println(t2) + + if t2 != "Ein Apfel" { + t.Errorf("Failed translation fallback.") + } + + t3 := Sprintf(DNGettext("", "An apple", "%d apples", 3), 3) + + fmt.Println(t3) + + if t3 != "3 Äpfel" { + t.Errorf("Failed translation fallback.") + } + +} -- cgit v1.2.3