Bug 19776 – [internals] Support i18n in error messages

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-03-30T11:03:49Z
Last change time
2024-12-13T19:02:44Z
Assigned to
No Owner
Creator
Iain Buclaw
Moved to GitHub: dmd#17900 →

Attachments

IDFilenameSummaryContent-TypeSize
1743fr.poFrench translation of expressionsem.d, and others.text/x-gettext-translation27248
1744sv.poSwedish translation of expressionsem.d, and others.text/x-gettext-translation30931

Comments

Comment #0 by ibuclaw — 2019-03-30T11:03:49Z
Created attachment 1743 French translation of expressionsem.d, and others. Attaching a partial translation that was done by the French Translation team by accident (I forgot to update the EXCLUDES for new files). For brevity, posting a few random examples from that file: --- > #: d/dmd/expressionsem.c:435 > #, gcc-internal-format, gfc-internal-format > msgid "`%s` is not defined, perhaps `import %s;` is needed?" > msgstr "« %s » n'est pas défini, peut-être que « import %s; » est nécessaire ?" > > #. Because COM classes are deleted by IUnknown.Release() > #. > #: d/dmd/expressionsem.c:4014 > #, gcc-internal-format, gfc-internal-format > msgid "cannot delete instance of COM interface %s" > msgstr "impossible de supprimer l'instance de l'interface COM %s" > > #: d/dmd/safe.c:75 > #, gcc-internal-format, gfc-internal-format > msgid "field %s.%s cannot modify fields in @safe code that overlap fields with other storage classes" > msgstr "le champs %s.%s ne peut pas modifier des champs dans du code @safe qui recouvre des champs avec d'autres classes de stockage" > > #: d/dmd/staticcond.c:85 > #, gcc-internal-format, gfc-internal-format > msgid "expression %s of type %s does not have a boolean value" > msgstr "l'expression %s de type %s n'a pas une valeur booléenne" --- This will be deleted, however I'm not opposed to this sort of work being done, it would be great if the dmd front-end was more fit for purpose in order to allow such work to be undertaken. One example where i18n can be frustrated by the front-end, is by some cases where errors are squashed into a programmatically computed message (to save a couple of lines?) For example, in expressionsem.d there is this piece of code: > const(char)* s = exp.op == TOK.plusPlus ? "increment" : "decrement"; > exp.error("cannot post-%s array slice `%s`, use pre-%s instead", s, exp.e1.toChars(), s); The string "cannot post-%s ..." will be extracted for translation, but the inserted words, "increment" and "decrement", will not. At a minimum, these words need to be marked for translation too, however the better option is to make it two complete messages. While for some languages it would work to compose the sentence in the same way as the original format, it would be safe to assume that languages further removed from English would have more trouble.
Comment #1 by ibuclaw — 2019-03-30T22:48:21Z
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"); > } > }
Comment #2 by ibuclaw — 2019-03-30T23:05:27Z
For future reference, keyword flags used to extract strings from dmd front-end. --keyword= --keyword=_ --keyword=error --flag=error:2:c-format --keyword=errorSupplemental --flag=errorSupplemental:2:c-format --keyword=warning --flag=warning:2:c-format --keyword=warningSupplemental --flag=warningSupplemental:2:c-format --keyword=deprecation --flag=deprecation:2:c-format --keyword=deprecationSupplemental --flag=deprecationSupplemental:2:c-format --keyword=message --keyword=verror --flag=verror:2:c-format --keyword=verrorSupplemental --flag=verrorSupplemental:2:c-format --keyword=vwarning --flag=vwarning:2:c-format --keyword=vwarningSupplemental --flag=vwarningSupplemental:2:c-format --keyword=vdeprecation --flag=vdeprecation:2:c-format --keyword=vdeprecationSupplemental --flag=vdeprecationSupplemental:2:c-format --keyword=vmessage
Comment #3 by ibuclaw — 2019-03-31T21:43:04Z
Created attachment 1744 Swedish translation of expressionsem.d, and others.
Comment #4 by dfj1esp02 — 2019-04-01T09:38:30Z
Personal anecdote with translated error messages: in English is was like "decimal bytes are not valid decimal", English is succinct enough, so you can make sense of it. Translated was something like "les octets decimals ne sont pas decimals valables", now that was cryptic (how a byte can be decimal? and all other european languages except for english are quite nuanced). Also imagine people coming to the learn group with Chinese error messages.
Comment #5 by robert.schadek — 2024-12-13T19:02:44Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17900 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB