plural-forms.lisp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. ;; This software is Copyright (c) Leslie P. Polzer, 2011.
  2. ;; Leslie P. Polzer grants you the rights to distribute
  3. ;; and use this software as governed by the terms
  4. ;; of the Lisp Lesser GNU Public License
  5. ;; (http://opensource.franz.com/preamble.html),
  6. ;; known as the LLGPL
  7. (in-package :cl-i18n)
  8. (defmacro define-plural-form ((lang) &body body)
  9. (if (and
  10. (listp lang)
  11. (not (null lang)))
  12. (progn
  13. `(progn
  14. ,@(mapcar (lambda (name) `(define-plural-form (,name) ,@body)) lang)))
  15. (progn
  16. `(defun
  17. ,(alexandria:format-symbol t "~:@(~a~)-PLURAL-FORM" lang)
  18. (n) ;anaphora
  19. ,@body))))
  20. (define-plural-form ((n/=1 english german dutch swedish danish norwegian faroese spanish italian bulgarian greek finnish estonian hebrew esperanto hungarian turkish))
  21. (if (/= n 1)
  22. 1
  23. 0))
  24. (define-plural-form (polish)
  25. (cond
  26. ((or (= n 0)
  27. (= n 1))
  28. 0)
  29. ((and (>= (mod n 10) 2)
  30. (<= (mod n 10) 4)
  31. (or (< (mod n 100) 10)
  32. (>= (mod n 100) 20)))
  33. 1)
  34. (t 2)))
  35. (define-plural-form (slovenian)
  36. (cond
  37. ((or (= n 0)
  38. (= (mod n 100) 1))
  39. 0)
  40. ((= (mod n 100) 2)
  41. 1)
  42. ((or (= (mod n 100) 3)
  43. (= (mod n 100) 4))
  44. 2)
  45. (t 3)))
  46. (define-plural-form ((czech slovak))
  47. (cond
  48. ((or (= n 0)
  49. (= n 1))
  50. 0)
  51. ((and (>= n 2)
  52. (<= n 4))
  53. 1)
  54. (t 2)))
  55. (define-plural-form ((russian ukrainian serbian croatian))
  56. (cond
  57. ((or
  58. (= n 0)
  59. (and
  60. (= (mod n 10) 1)
  61. (/= (mod n 100) 11)))
  62. 0)
  63. ((and
  64. (>= (mod n 10) 2)
  65. (<= (mod n 10) 4)
  66. (or (< (mod n 100) 10)
  67. (>= (mod n 100) 20)))
  68. 1)
  69. (t 2)))
  70. (define-plural-form ((brazilian portuguese french))
  71. (cond
  72. ((or (= n 0)
  73. (= n 1))
  74. 0)
  75. (t 1)))
  76. (define-plural-form (latvian)
  77. (cond
  78. ((and
  79. (= (mod n 10) 1)
  80. (/= (mod n 100) 11))
  81. 0)
  82. ((/= n 0)
  83. 1)
  84. (t 2)))
  85. (define-plural-form ((gaeilge irish))
  86. (cond
  87. ((or (= n 0)
  88. (= n 1))
  89. 0)
  90. ((= n 2)
  91. 1)
  92. (t 2)))
  93. (define-plural-form (romanian)
  94. (cond
  95. ((= n 1)
  96. 0)
  97. ((or
  98. (= n 0)
  99. (and
  100. (> (mod n 100) 0)
  101. (< (mod n 100) 20)))
  102. 1)
  103. (t 2)))
  104. (define-plural-form (lithuanian)
  105. (cond
  106. ((or (= n 0)
  107. (= n 1)
  108. (and (= (mod n 10) 1)
  109. (/= (mod n 100) 11)))
  110. 0)
  111. ((and
  112. (>= (mod n 10) 2)
  113. (or (< (mod n 100) 10)
  114. (>= (mod n 100) 20)))
  115. 1)
  116. (t 2)))