From f7f4bcdaad57ce74a2b0e32c771d30178e0b14e1 Mon Sep 17 00:00:00 2001 From: José Carlos Nieto Date: Sat, 6 Oct 2012 16:07:42 -0500 Subject: Adding Deutsch and Español examples. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gettext.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'gettext.go') 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))) -- cgit v1.2.3