emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Before l10n, better practices for (message) ?


From: Yuri Khan
Subject: Re: Before l10n, better practices for (message) ?
Date: Sat, 27 May 2017 01:08:20 +0700

On Fri, May 26, 2017 at 9:44 PM, Eli Zaretskii <address@hidden> wrote:

>> Is it very different from global variables clashing or not between packages?
>
> No.  But the need to name messages with package qualifiers is a
> significant nuisance, and will fill the "namespace" of a file with
> many symbols.

Messages do not have to be global variables. They could be retrieved
by a helper function accepting a package namespace and a message key.
In gettext, this function is dgettext.

    (require 'gettext)

    (message (dgettext "hello" "Hello World!"))

Gettext also has a helper function named gettext and aliased _, which
use the domain set by an earlier invocation of textdomain(). In Elisp,
it seems most natural to express that like this:

    (defun hello-_ (key)
      (dgettext "hello" key))
    (message (hello-_ "Hello World!"))

The function hello-_ would be defined once in the hello package and
then used throughout it. Another package would define its own wrapper
around dgettext, with a different domain.


Inside, dgettext could consult a two-level hashtable, first keyed by
domain, second by key. Alternatively, a domain could be a hashtable
variable; in the latter case:

    ;; in hello.el
    (defvar hello-domain nil)
    (defun hello-_ (key)
      (dgettext hello-domain key))
    (message (hello-_ "Hello World!"))

    ;; in gettext.el
    (defun dgettext (domain key)
      (gethash key domain key))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]