Skip to content

Commit

Permalink
Fixed ngettext for large numbers that don't fit an unsigned long
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Henrique Milaré committed Jan 16, 2012
1 parent 51030e9 commit 3567f83
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions gettext-cffi.lisp
Expand Up @@ -89,12 +89,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
(__msgid :string)
(__category :int))

(cffi:defcfun ("ngettext" ngettext) :string
"The plural version of `gettext' The first string should be the return value for n == 1, and the second string the value for n != 1. The third argument is n. Use this instead of an `if' because other languages have more or less than two branches for plurals, and this function allows translators to specify the plurals for their language."
(cffi:defcfun ("ngettext" %ngettext) :string
(__msgid1 :string)
(__msgid2 :string)
(__n :unsigned-long))

(defun ngettext (msgid1 msgid2 n)
"The plural version of `gettext' The first string should be the return value for n == 1, and the second string the value for n != 1. The third argument is n. Use this instead of an `if' because other languages have more or less than two branches for plurals, and this function allows translators to specify the plurals for their language."
;; Deals with plurals for long integers as recommended by Gettext manual, see
;; http://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/Plural-forms.html
(%ngettext msgid1 msgid2 (if (> n 1000000)
(+ 1000000 (rem n 1000000))
n)))

(cffi:defcfun ("dngettext" dngettext) :string
(__domainname :string)
(__msgid1 :string)
Expand Down

0 comments on commit 3567f83

Please sign in to comment.