@c This file is part of the GNU gettext manual.
@c Copyright (C) 1995-2025 Free Software Foundation, Inc.
@c See the file gettext.texi for copying conditions.

@node D
@subsection D
@cindex D

@table @asis
@item RPMs
gcc-gdc or ldc

@item Ubuntu packages
gdc or ldc

@item File extension
@code{d}

@item String syntax
@c https://dlang.org/spec/lex.html#string_literals
@code{r"abc"}, @code{`abc`}, @code{"abc"},
@code{q"[abc]"}, @code{q"(abc)"}, @code{q"<abc>"}, @code{q"@{abc@}"},
@code{q@{abc@}}, @code{x"6A 6B 6C"}

@item gettext shorthand
@code{_("abc")}

@item gettext/ngettext functions
@code{gettext}, @code{dgettext}, @code{dcgettext},
@code{ngettext}, @code{dngettext}, @code{dcngettext}

Note that the @code{ngettext}-like functions need to take
two argument strings that consume the same number of arguments.
For example, you cannot write
@code{format(ngettext("a piece", "%d pieces", n), n)}
because in the singular case,
@code{format} would treat the unused argument as an error and
throw an exception.
As a workaround, you need to convert @code{n} to a string and
format that string with precision zero:
@code{format(ngettext("%.0sa piece", "%s pieces", n), to!string(n))}
or
@code{format(ngettext("%.0sa piece", "%s pieces", n), text(n))}

@item textdomain
@code{textdomain} function

@item bindtextdomain
@code{bindtextdomain} function

@item setlocale
Programmer must call @code{setlocale (LC_ALL, "")}

@item Prerequisite
@code{import gnu.libintl;}
@*@code{alias _ = gettext;}

@item Use or emulate GNU gettext
Use

@item Extractor
@code{xgettext -k_ --flag=_:1:pass-c-format --flag=_:1:pass-d-format}

@item Formatting with positions
@code{fprintf "%2$d %1$d"}, @code{format "%2$d %1$d"}

@item Portability
fully portable

@item po-mode marking
---
@end table

An example is available in the @file{examples} directory: @code{hello-d}.
