[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Emacs i18n
From: |
Juri Linkov |
Subject: |
Re: Emacs i18n |
Date: |
Wed, 27 Mar 2019 23:22:07 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) |
>> Is it possible to generate a regexp from ngettext arguments?
>> For example, given the same arguments and calling a hypothetical
>> function ‘rx-ngettext’:
>>
>> (rx-ngettext "finished with %d match found\n"
>> "finished with %d matches found\n")
>>
>> to generate a regexp like:
>>
>> "finished with \\(?:\\(\\(?:[0-9]+ \\)?match\\(?:es\\)? found\\)"
>
> Trivially so by generating an or-pattern: "singular text\\|plural text".
> Anything better is a matter of optimisation, basically a diff algorithm
> (or just prefix and suffix merging).
>
> Is it practical, though? For %s, we would need to generate a match-anything
> subexpression, even though the argument is much more constrained in practice.
I tried ‘regexp-opt’ and it generates a ready-to-use regexp:
(replace-regexp-in-string
"%d" "\\\\([0-9]+\\\\)"
(regexp-opt '("finished with %d match found"
"finished with %d matches found"
"finished with no matches found")))
⇒ "\\(?:finished with \\(?:\\(?:\\([0-9]+\\) match\\(?:es\\)?\\|no matches\\)
found\\)\\)"
- Re: Emacs i18n, (continued)
- Re: Emacs i18n, Paul Eggert, 2019/03/26
- Re: Emacs i18n, Eli Zaretskii, 2019/03/24
- Re: Emacs i18n, Jean-Christophe Helary, 2019/03/25
- Re: Emacs i18n, Juri Linkov, 2019/03/25
- Re: Emacs i18n, Eli Zaretskii, 2019/03/25
- Re: Emacs i18n, Richard Stallman, 2019/03/27
- Re: Emacs i18n, Mattias Engdegård, 2019/03/25
- Re: Emacs i18n, Eli Zaretskii, 2019/03/25
- Re: Emacs i18n, Juri Linkov, 2019/03/25
- Re: Emacs i18n, Mattias Engdegård, 2019/03/25
- Re: Emacs i18n,
Juri Linkov <=
- Re: Emacs i18n, Mattias Engdegård, 2019/03/28
Re: Emacs i18n (was: bug#34520: delete-matching-lines should report how many lines it deleted), Richard Stallman, 2019/03/03
- Re: Emacs i18n (was: bug#34520: delete-matching-lines should report how many lines it deleted), Eli Zaretskii, 2019/03/04
- Re: Emacs i18n (was: bug#34520: delete-matching-lines should report how many lines it deleted), Paul Eggert, 2019/03/04
- Re: Emacs i18n (was: bug#34520: delete-matching-lines should report how many lines it deleted), Eli Zaretskii, 2019/03/04
- Re: Emacs i18n (was: bug#34520: delete-matching-lines should report how many lines it deleted), Paul Eggert, 2019/03/04
- Re: Emacs i18n, Juri Linkov, 2019/03/05
- Re: Emacs i18n, Richard Stallman, 2019/03/05
- Re: Emacs i18n, Eli Zaretskii, 2019/03/06
- Re: Emacs i18n, Paul Eggert, 2019/03/06