Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from gugamilare/master

Fixed ngettext for large numbers and added better support for non-GNU systems
  • Loading branch information...
commit 85d5dcea00e7448e10ac4f3ee0168bc691135fe9 2 parents 51030e9 + 5d4a6ee
@krzysz00 authored
Showing with 24 additions and 7 deletions.
  1. +15 −3 gettext-cffi.lisp
  2. +9 −4 gettext-loader.lisp
View
18 gettext-cffi.lisp
@@ -89,18 +89,30 @@ 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))
-(cffi:defcfun ("dngettext" dngettext) :string
+(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)
(__msgid2 :string)
(__n :unsigned-long))
+(defun dngettext (domainname msgid1 msgid2 n)
+ (%dngettext domainname msgid1 msgid2 (if (> n 1000000)
+ (+ 1000000 (rem n 1000000))
+ n)))
+
(cffi:defcfun ("textdomain" textdomain) :string
"Set the textdomain for the application. The textdomain is the name (before the dot) of your project's .mo files"
(__domainname :string))
View
13 gettext-loader.lisp
@@ -19,7 +19,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
(in-package :cl-gettext)
-;; (cffi:define-foreign-library gettext
-;; (:unix "libc.so")
-;; (t (:default "libintl")))
-;; (cffi:use-foreign-library gettext)
+(cffi:define-foreign-library gettext
+ (:unix (or "libintl.so"
+ "libintl"))
+ (:windows "libintl.dll")
+ (t (:default "libintl")))
+
+(handler-case (assert (cffi:foreign-funcall "gettext" :string "abc" :string))
+ (error ()
+ (cffi:use-foreign-library gettext)))
Please sign in to comment.
Something went wrong with that request. Please try again.