aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorJuri Linkov2019-03-24 23:55:07 +0200
committerJuri Linkov2019-03-24 23:55:07 +0200
commit5fdf4fc07df7dd897931efb5dbf5f26dfaff9274 (patch)
tree807fd09f411bd670cb0f7bc7834469366e514036 /lisp
parent36535caf9621f984f7f95d4def09bdb0ae2f1d2a (diff)
downloademacs-5fdf4fc07df7dd897931efb5dbf5f26dfaff9274.tar.gz
emacs-5fdf4fc07df7dd897931efb5dbf5f26dfaff9274.zip
i18n: Add function ngettext for pluralization.
* lisp/international/mule-cmds.el (ngettext): New function. https://lists.gnu.org/archive/html/emacs-devel/2019-03/msg00586.html * lisp/replace.el (flush-lines, how-many, occur-1, occur-engine) (perform-replace): Use ngettext. * lisp/progmodes/grep.el (grep-exit-message): Use ngettext. (grep-mode-font-lock-keywords): Match both singular and plural form of "matches".
Diffstat (limited to 'lisp')
-rw-r--r--lisp/international/mule-cmds.el14
-rw-r--r--lisp/progmodes/grep.el7
-rw-r--r--lisp/replace.el51
3 files changed, 49 insertions, 23 deletions
diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el
index 5f87d899415..035932e395d 100644
--- a/lisp/international/mule-cmds.el
+++ b/lisp/international/mule-cmds.el
@@ -2798,6 +2798,20 @@ See also `locale-charset-language-names', `locale-language-names',
2798 'a4))))))) 2798 'a4)))))))
2799 nil) 2799 nil)
2800 2800
2801;;; i18n (internationalization)
2802
2803(defun ngettext (msgid msgid_plural n)
2804 "Return the plural form of the translation of the string.
2805This function is similar to the `gettext' function as it finds the message
2806catalogs in the same way. But it takes two extra arguments. The MSGID
2807parameter must contain the singular form of the string to be converted.
2808It is also used as the key for the search in the catalog.
2809The MSGID_PLURAL parameter is the plural form. The parameter N is used
2810to determine the plural form. If no message catalog is found MSGID is
2811returned if N is equal to 1, otherwise MSGID_PLURAL."
2812 (if (= n 1) msgid msgid_plural))
2813
2814
2801;;; Character property 2815;;; Character property
2802 2816
2803(put 'char-code-property-table 'char-table-extra-slots 5) 2817(put 'char-code-property-table 'char-table-extra-slots 5)
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index a5427dd8b7e..c0f47159c95 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -459,7 +459,7 @@ abbreviated part can also be toggled with
459 ;; remove match from grep-regexp-alist before fontifying 459 ;; remove match from grep-regexp-alist before fontifying
460 ("^Grep[/a-zA-Z]* started.*" 460 ("^Grep[/a-zA-Z]* started.*"
461 (0 '(face nil compilation-message nil help-echo nil mouse-face nil) t)) 461 (0 '(face nil compilation-message nil help-echo nil mouse-face nil) t))
462 ("^Grep[/a-zA-Z]* finished with \\(?:\\(\\(?:[0-9]+ \\)?matches found\\)\\|\\(no matches found\\)\\).*" 462 ("^Grep[/a-zA-Z]* finished with \\(?:\\(\\(?:[0-9]+ \\)?match\\(?:es\\)? found\\)\\|\\(no matches found\\)\\).*"
463 (0 '(face nil compilation-message nil help-echo nil mouse-face nil) t) 463 (0 '(face nil compilation-message nil help-echo nil mouse-face nil) t)
464 (1 compilation-info-face nil t) 464 (1 compilation-info-face nil t)
465 (2 compilation-warning-face nil t)) 465 (2 compilation-warning-face nil t))
@@ -552,7 +552,10 @@ Set up `compilation-exit-message-function' and run `grep-setup-hook'."
552 ;; so the buffer is still unmodified if there is no output. 552 ;; so the buffer is still unmodified if there is no output.
553 (cond ((and (zerop code) (buffer-modified-p)) 553 (cond ((and (zerop code) (buffer-modified-p))
554 (if (> grep-num-matches-found 0) 554 (if (> grep-num-matches-found 0)
555 (cons (format "finished with %d matches found\n" grep-num-matches-found) 555 (cons (format (ngettext "finished with %d match found\n"
556 "finished with %d matches found\n"
557 grep-num-matches-found)
558 grep-num-matches-found)
556 "matched") 559 "matched")
557 '("finished with matches found\n" . "matched"))) 560 '("finished with matches found\n" . "matched")))
558 ((not (buffer-modified-p)) 561 ((not (buffer-modified-p))
diff --git a/lisp/replace.el b/lisp/replace.el
index 59ad1a375b8..318a9fb0253 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -983,7 +983,10 @@ also print the number."
983 (progn (forward-line 1) (point))) 983 (progn (forward-line 1) (point)))
984 (setq count (1+ count)))) 984 (setq count (1+ count))))
985 (set-marker rend nil) 985 (set-marker rend nil)
986 (when interactive (message "Deleted %d matching lines" count)) 986 (when interactive (message (ngettext "Deleted %d matching line"
987 "Deleted %d matching lines"
988 count)
989 count))
987 count)) 990 count))
988 991
989(defun how-many (regexp &optional rstart rend interactive) 992(defun how-many (regexp &optional rstart rend interactive)
@@ -1032,9 +1035,10 @@ a previously found match."
1032 (if (= opoint (point)) 1035 (if (= opoint (point))
1033 (forward-char 1) 1036 (forward-char 1)
1034 (setq count (1+ count)))) 1037 (setq count (1+ count))))
1035 (when interactive (message "%d occurrence%s" 1038 (when interactive (message (ngettext "%d occurrence"
1036 count 1039 "%d occurrences"
1037 (if (= count 1) "" "s"))) 1040 count)
1041 count))
1038 count))) 1042 count)))
1039 1043
1040 1044
@@ -1617,11 +1621,12 @@ See also `multi-occur'."
1617 (not (eq occur-excluded-properties t)))))) 1621 (not (eq occur-excluded-properties t))))))
1618 (let* ((bufcount (length active-bufs)) 1622 (let* ((bufcount (length active-bufs))
1619 (diff (- (length bufs) bufcount))) 1623 (diff (- (length bufs) bufcount)))
1620 (message "Searched %d buffer%s%s; %s match%s%s" 1624 (message "Searched %d %s%s; %s %s%s"
1621 bufcount (if (= bufcount 1) "" "s") 1625 bufcount
1626 (ngettext "buffer" "buffers" bufcount)
1622 (if (zerop diff) "" (format " (%d killed)" diff)) 1627 (if (zerop diff) "" (format " (%d killed)" diff))
1623 (if (zerop count) "no" (format "%d" count)) 1628 (if (zerop count) "no" (format "%d" count))
1624 (if (= count 1) "" "es") 1629 (ngettext "match" "matches" count)
1625 ;; Don't display regexp if with remaining text 1630 ;; Don't display regexp if with remaining text
1626 ;; it is longer than window-width. 1631 ;; it is longer than window-width.
1627 (if (> (+ (length (or (get-text-property 0 'isearch-string regexp) 1632 (if (> (+ (length (or (get-text-property 0 'isearch-string regexp)
@@ -1856,14 +1861,15 @@ See also `multi-occur'."
1856 (let ((beg (point)) 1861 (let ((beg (point))
1857 end) 1862 end)
1858 (insert (propertize 1863 (insert (propertize
1859 (format "%d match%s%s%s in buffer: %s%s\n" 1864 (format "%d %s%s%s in buffer: %s%s\n"
1860 matches (if (= matches 1) "" "es") 1865 matches
1866 (ngettext "match" "matches" matches)
1861 ;; Don't display the same number of lines 1867 ;; Don't display the same number of lines
1862 ;; and matches in case of 1 match per line. 1868 ;; and matches in case of 1 match per line.
1863 (if (= lines matches) 1869 (if (= lines matches)
1864 "" (format " in %d line%s" 1870 "" (format " in %d %s"
1865 lines 1871 lines
1866 (if (= lines 1) "" "s"))) 1872 (ngettext "line" "lines" lines)))
1867 ;; Don't display regexp for multi-buffer. 1873 ;; Don't display regexp for multi-buffer.
1868 (if (> (length buffers) 1) 1874 (if (> (length buffers) 1)
1869 "" (occur-regexp-descr regexp)) 1875 "" (occur-regexp-descr regexp))
@@ -1889,13 +1895,15 @@ See also `multi-occur'."
1889 (goto-char (point-min)) 1895 (goto-char (point-min))
1890 (let ((beg (point)) 1896 (let ((beg (point))
1891 end) 1897 end)
1892 (insert (format "%d match%s%s total%s:\n" 1898 (insert (format "%d %s%s total%s:\n"
1893 global-matches (if (= global-matches 1) "" "es") 1899 global-matches
1900 (ngettext "match" "matches" global-matches)
1894 ;; Don't display the same number of lines 1901 ;; Don't display the same number of lines
1895 ;; and matches in case of 1 match per line. 1902 ;; and matches in case of 1 match per line.
1896 (if (= global-lines global-matches) 1903 (if (= global-lines global-matches)
1897 "" (format " in %d line%s" 1904 "" (format " in %d %s"
1898 global-lines (if (= global-lines 1) "" "s"))) 1905 global-lines
1906 (ngettext "line" "lines" global-lines)))
1899 (occur-regexp-descr regexp))) 1907 (occur-regexp-descr regexp)))
1900 (setq end (point)) 1908 (setq end (point))
1901 (when title-face 1909 (when title-face
@@ -2730,10 +2738,10 @@ characters."
2730 (1+ num-replacements)))))) 2738 (1+ num-replacements))))))
2731 (when (and (eq def 'undo-all) 2739 (when (and (eq def 'undo-all)
2732 (null (zerop num-replacements))) 2740 (null (zerop num-replacements)))
2733 (message "Undid %d %s" num-replacements 2741 (message (ngettext "Undid %d replacement"
2734 (if (= num-replacements 1) 2742 "Undid %d replacements"
2735 "replacement" 2743 num-replacements)
2736 "replacements")) 2744 num-replacements)
2737 (ding 'no-terminate) 2745 (ding 'no-terminate)
2738 (sit-for 1))) 2746 (sit-for 1)))
2739 (setq replaced nil last-was-undo t last-was-act-and-show nil))) 2747 (setq replaced nil last-was-undo t last-was-act-and-show nil)))
@@ -2859,9 +2867,10 @@ characters."
2859 last-was-act-and-show nil)))))) 2867 last-was-act-and-show nil))))))
2860 (replace-dehighlight)) 2868 (replace-dehighlight))
2861 (or unread-command-events 2869 (or unread-command-events
2862 (message "Replaced %d occurrence%s%s" 2870 (message (ngettext "Replaced %d occurrence%s"
2871 "Replaced %d occurrences%s"
2872 replace-count)
2863 replace-count 2873 replace-count
2864 (if (= replace-count 1) "" "s")
2865 (if (> (+ skip-read-only-count 2874 (if (> (+ skip-read-only-count
2866 skip-filtered-count 2875 skip-filtered-count
2867 skip-invisible-count) 2876 skip-invisible-count)