aboutsummaryrefslogtreecommitdiff
path: root/gettext.go
diff options
context:
space:
mode:
authorSQP <meuarrr@gmail.com>2015-06-08 13:59:21 +0200
committerSQP <meuarrr@gmail.com>2015-06-08 13:59:21 +0200
commitc7205ad47e6bd7e7816ef5186f463c53ea4a046e (patch)
treeb291ecbcd587165c27a3fd16162019daf924348f /gettext.go
parentStyling typos. (diff)
downloadgotext-c7205ad47e6bd7e7816ef5186f463c53ea4a046e.tar.gz
gotext-c7205ad47e6bd7e7816ef5186f463c53ea4a046e.tar.xz
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.
Diffstat (limited to 'gettext.go')
-rw-r--r--gettext.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/gettext.go b/gettext.go
index 352c857..624ab34 100644
--- a/gettext.go
+++ b/gettext.go
@@ -120,7 +120,7 @@ func Gettext(msgid string) string {
// Like Gettext(), but looking up the message in the specified domain.
func DGettext(domain string, msgid string) string {
- cdomain := C.CString(domain)
+ cdomain := cDomainName(domain)
cmsgid := C.CString(msgid)
res := C.GoString(C.dgettext(cdomain, cmsgid))
@@ -133,7 +133,7 @@ func DGettext(domain string, msgid string) string {
// Like Gettext(), but looking up the message in the specified domain and
// category.
func DCGettext(domain string, msgid string, category uint) string {
- cdomain := C.CString(domain)
+ cdomain := cDomainName(domain)
cmsgid := C.CString(msgid)
res := C.GoString(C.dcgettext(cdomain, cmsgid, C.int(category)))
@@ -177,7 +177,7 @@ func Sprintf(format string, a ...interface{}) string {
// Like NGettext(), but looking up the message in the specified domain.
func DNGettext(domainname string, msgid string, msgid_plural string, n uint64) string {
- cdomainname := C.CString(domainname)
+ cdomainname := cDomainName(domainname)
cmsgid := C.CString(msgid)
cmsgid_plural := C.CString(msgid_plural)
@@ -193,7 +193,7 @@ func DNGettext(domainname string, msgid string, msgid_plural string, n uint64) s
// Like NGettext(), but looking up the message in the specified domain and
// category.
func DCNGettext(domainname string, msgid string, msgid_plural string, n uint64, category uint) string {
- cdomainname := C.CString(domainname)
+ cdomainname := cDomainName(domainname)
cmsgid := C.CString(msgid)
cmsgid_plural := C.CString(msgid_plural)
@@ -205,3 +205,11 @@ func DCNGettext(domainname string, msgid string, msgid_plural string, n uint64,
return res
}
+
+// cDomainName returns the domain name CString that can be nil.
+func cDomainName(domain string) *C.char {
+ if domain == "" {
+ return nil
+ }
+ return C.CString(domain)
+}