On Wed, Oct 18, 2023 at 05:28:10PM +0000, waffl3x wrote: > I've seen plenty of these G_ or _ macros on strings around like in > grokfndecl for these errors. > > G_("static member function %qD cannot have cv-qualifier") > G_("non-member function %qD cannot have cv-qualifier") > > G_("static member function %qD cannot have ref-qualifier") > G_("non-member function %qD cannot have ref-qualifier") > > I have been able to figure out it relates to translation, but not > exactly what the protocol around them is. I think in my original patch > I had refactored this code a bunch, I figured adding a 3rd case to it > justifies a refactor. I think I forgot to add those changes to the > original patch, either that or I undid it or moved it somewhere else. > Anyway, the point is, coming back to it now to re-add those diagnostics > I realized I probably shouldn't have changed those strings. > > I also have been wondering whether I should be putting macros on any > strings I add, it seemed like there might have been a macro for text > that needs translation. Is this something I should be doing?
There are different kinds of format strings in GCC, the most common are the gcc-internal-format strings. If you call a function which is expected to take such translatable format string (in particular a function which takes a gmsgid named argument like error, error_at, pedwarn, warning_at, ...) and pass a string literal to that function, nothing needs to be marked in a special way, both gcc/po/exgettext is able to collect such literals into gcc/po/gcc.pot for translations and the function is supposed to use gettext etc. to translate it - e.g. see diagnostic_set_info using _(gmsgid) for that. But, if there is e.g. a temporary pointer var which points to format strings and only that is eventually passed to the diagnostic functions, gcc/po/exgettext won't be able to collect such literals, which is where the G_() macro comes into play and one marks the string as gcc-internal-format with it; the translation is still handled by the diagnostic function at runtime. The N_() macro is similar but for c-format strings instead. The _() macro both collects for translations if it is used with string literal, and expands to gettext call to translate it at runtime, which is something that should be avoided if something translates it again. And another i18n rule is that one shouldn't try to construct diagnostic messages from parts of english sentences, it is fine to fill in with %s/%qs etc. language keywords etc. but otherwise the format string should contain the whole diagnostic line, so that translators can reorder the words etc. Jakub