aboutsummaryrefslogtreecommitdiff
path: root/gettext.go
diff options
context:
space:
mode:
authorJosé Carlos Nieto <xiam@menteslibres.org>2012-10-06 16:07:42 -0500
committerJosé Carlos Nieto <xiam@menteslibres.org>2012-10-06 16:07:42 -0500
commitf7f4bcdaad57ce74a2b0e32c771d30178e0b14e1 (patch)
treea28a5a3622436028ae93185a2cb603efa05464ad /gettext.go
parentInitial commit. (diff)
downloadgotext-f7f4bcdaad57ce74a2b0e32c771d30178e0b14e1.tar.gz
gotext-f7f4bcdaad57ce74a2b0e32c771d30178e0b14e1.tar.xz
Adding Deutsch and Español examples.
Diffstat (limited to 'gettext.go')
-rw-r--r--gettext.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/gettext.go b/gettext.go
index 95ad582..b8fd4c9 100644
--- a/gettext.go
+++ b/gettext.go
@@ -30,6 +30,11 @@ package gettext
*/
import "C"
+import (
+ "fmt"
+ "strings"
+)
+
var (
// For all of the locale.
LC_ALL = uint(C.LC_ALL)
@@ -95,6 +100,23 @@ func NGettext(msgid string, msgid_plural string, n uint64) string {
return C.GoString(C.ngettext(C.CString(msgid), C.CString(msgid_plural), C.ulong(n)))
}
+// Like fmt.Sprintf() but without %!(EXTRA) errors.
+func Sprintf(format string, a ...interface{}) string {
+ expects := strings.Count(format, "%") - strings.Count(format, "%%")
+
+ if expects > 0 {
+ arguments := make([]interface{}, expects)
+ for i := 0; i < expects; i++ {
+ if len(a) > i {
+ arguments[i] = a[i]
+ }
+ }
+ return fmt.Sprintf(format, arguments...)
+ }
+
+ return format
+}
+
// Like NGettext(), but looking up the message in the specified domain.
func DNGettext(domainname string, msgid string, msgid_plural string, n uint64) string {
return C.GoString(C.dngettext(C.CString(domainname), C.CString(msgid), C.CString(msgid_plural), C.ulong(n)))