aboutsummaryrefslogtreecommitdiff
path: root/gettext.go
diff options
context:
space:
mode:
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)))