[Issue 19776] [internals] Support i18n in error messages

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Mar 30 22:48:21 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=19776

Iain Buclaw <ibuclaw at gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ibuclaw at gdcproject.org

--- Comment #1 from Iain Buclaw <ibuclaw at gdcproject.org> ---
As well as making sure the format string of errors are translation-friendly,
there's also a couple of functions - verror and vdeprecation - that have
optional parameters. Incidentally, they are only ever set as `kind()` and
`toPrettyChars()`.

The former kind() function returns a string literal, such as declaration
(déclaration), template (patron), function (fonction), etc...

However these will never be translated unless the function kind() returns
calling gettext().

A bare minimal example being:

> // module dmd.errors;
> nothrow @nogc
> {
>     version (ENABLE_NLS)
>     {
>         extern (C) const(char)* gettext(scope const char* msgid);
>     }
>     else
>     {
>         const(char)* gettext(scope const char* msgid)
>         {
>             pragma(inline, true);
>             return msgid;
>         }
>     }
> }
> 
> alias _ = gettext;
> 
> // module dmd.func;
> extern (C++) class FuncDeclaration : Declaration
> {
>     override const(char)* kind() const
>     {
>         return generated ? _("generated function") : _("function");
>     }
> }

--


More information about the Digitalmars-d-bugs mailing list