[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#34520: delete-matching-lines should report how many lines it deleted
From: |
Juri Linkov |
Subject: |
bug#34520: delete-matching-lines should report how many lines it deleted |
Date: |
Sat, 02 Mar 2019 22:55:52 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) |
> > Ok, waiting for the times when ‘gettext’ will arrive to Emacs.
>
> It would be very desirable to make Emacs support gettext-style
> translations. I have a feeling that it can't use the same
> code as gettext -- but with all of Emacs's other facilities,
> I think that transposing the useful part of gettext into
> Emacs won't be a big job.
>
> Would someone like to do this?
Emacs can do much better job of text translation than gettext.
It's easy to translate text transparently to the caller,
i.e. without changing the caller code at all, by adding
a new intermediate layer to some text output functions
that will translate their string arguments to the
language of the default language environment.
Here is an experimental but extensible implementation
that handles the case of formatting the recently added message
taking into account grammatical number of its argument:
(defvar i18n-translations-hash (make-hash-table :test 'equal))
(defun i18n-add-translation (_language-environment from to)
(puthash from to i18n-translations-hash))
(i18n-add-translation
"English"
"Deleted %d matching lines"
(lambda (format-string count)
(if (= count 1)
"Deleted %d matching line"
"Deleted %d matching lines")))
(defun i18n-get-translation (format-string &rest args)
(pcase (gethash format-string i18n-translations-hash)
((and (pred functionp) f) (apply f format-string args))
((and (pred stringp) s) s)
(_ format-string)))
(advice-add 'message :around
(lambda (orig-fun format-string &rest args)
(apply orig-fun (apply 'i18n-get-translation format-string
args) args))
'((name . message-i18n)))
In addition to translating format strings of the function 'message',
doing the same for more text output functions like 'describe-function',
'describe-variable' and 'menu-item' in 'define-key' would cover most
of the internationalization needs.
- bug#34520: delete-matching-lines should report how many lines it deleted,
Juri Linkov <=