aboutsummaryrefslogtreecommitdiff
path: root/gettext.go
diff options
context:
space:
mode:
authorJosé Carlos <jose.carlos@menteslibres.net>2016-01-09 09:06:46 -0600
committerJosé Carlos <jose.carlos@menteslibres.net>2016-01-09 09:06:46 -0600
commitea286668e74dbb65abeea59f0c51f00cd8df3c73 (patch)
treeb291ecbcd587165c27a3fd16162019daf924348f /gettext.go
parentStyling typos. (diff)
parentFix translations with DGettext (and other D... func) when the domain name is ... (diff)
downloadgotext-ea286668e74dbb65abeea59f0c51f00cd8df3c73.tar.gz
gotext-ea286668e74dbb65abeea59f0c51f00cd8df3c73.tar.xz
Merge pull request #2 from sqp/nil_string
Fix translations with DGettext (and other D... func) when the domain name is empty.
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)
+}