Message ID | 20231019151130.1929663-1-jason@redhat.com |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp453766vqb; Thu, 19 Oct 2023 08:12:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFw5MQ3CQ1i5JSCM16H4EIKg675grNMRXp0Ahq/AX+081IUe1VLOJHVWn5W6bnZnDQeVFbN X-Received: by 2002:ad4:5ae8:0:b0:66d:4569:9941 with SMTP id c8-20020ad45ae8000000b0066d45699941mr2781401qvh.45.1697728344196; Thu, 19 Oct 2023 08:12:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697728344; cv=pass; d=google.com; s=arc-20160816; b=ehGtWxSyXmMMHUI4aO58wAOGTYblZgefk9S+atcxMSCopFNehFrXizPCzniUrEU1QE N3Qm4l8BAGwSLwyHZ69WH1A3h4YKDgtAl8nB1RukybjcwRPV2brPaSERsRX1mAtQZHuT j2J89T/gpn+zO93RraWzPeiIA7mGS195v3bLNOWzR7g5KLshpBf4CX+07t9L+PxzBFYe /r+zWhivEkL7EbUJhOaDZcwr17OtHLoOREhcWcxeRzaIfQ7+KW2X3QYGfxQth1PmgElH KMkmpJk3zX1AWDHCyyNQj3MlgaxeUyAKy6X9bs2AIvtv4pwqFsVyyftep/rQAWxMU1Lh bGiw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=J1n7c2tVCptwmxj7mklK6GAXGOpMGMwekCLkvf1dS4s=; fh=Wva1Jp54HlROjkhV3NWRTEjsneLTa4Y4L5iIjnbCpy0=; b=drHvDLqjk2BlRytUZxXo6eA9g2frhlQxkcd5yEFqVdxbL8ruYAndHvZgqfCMV6RQNk E06ZQ0venqrkft1gEXshqMoL7V9htTHBIWSBL0TDF6c78eikInxy8LHIjd90JWsWEs45 yk0pYBJNL84rv+YWXRklvgwGx3icZrMMy87/8ksoooAsMiJuZNJhPuH/ORdiPBj8XGQc RqTgeFQ4HrDY4O2Hh28pZFzvvG+5SnKX1SlTGIqfY119N3nh5Awp9l4/M11lxZaHjlHr GGR36TvBN8hgHyg2E/rIRtGuwEgJeFRu7Kxv7mCJ78NU2kkbDJx1syzK/skV0tzrl5Hn FZzQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iqeQXIms; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id kr3-20020a0562142b8300b0065b32c70918si1752975qvb.232.2023.10.19.08.12.23 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 08:12:24 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iqeQXIms; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AD0263857732 for <ouuuleilei@gmail.com>; Thu, 19 Oct 2023 15:12:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 9E0E53858298 for <gcc-patches@gcc.gnu.org>; Thu, 19 Oct 2023 15:11:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9E0E53858298 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9E0E53858298 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697728298; cv=none; b=f8he108G9LVAavwPJVqma9q+N9izAtJtWEPd7Ky4qPe8jeTINzkMfNY1dy0uhW6NQVZWfzbKh4xfZYh6JJyEoRk+PBUlW55EzvC+NZUiIDtYEMLUMtQxrQN1jLrtcTDgajdrAcqbr8tBcJIW7yEVBBosWm6NqWSwsvTL1/P6dHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697728298; c=relaxed/simple; bh=LqIFIhR8KWBj7vZWzJ8SAhfzKKlxLkdPNuftNQpGDoI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=fNsTExAFcrJYECYpd5tF1jjg9IqWHMWIYQw13eMs1A1yDcLmWto+5TxtAo9UEZ0G0s1jaos86S7YD+F4qPTF1KgBtfQ7rTHwRPgiM1CG8VAPABMo6zc8Vd1/4YqhW+xjavjqMlIGDfhrSl5JjtPt6YhvdUMlumL+41FnyLpSrys= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697728297; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=J1n7c2tVCptwmxj7mklK6GAXGOpMGMwekCLkvf1dS4s=; b=iqeQXImsSMuxnfzMMi9jUgSUmXz+GJaUubGsr+gZmEW230sppdhhcvZ5xwveaaLL75P+z6 NSR8oo5dTgalL8es0Px7XKITBglCR/WNzmj2VvhwbJFHqHIQP3lS9tduRXB2Sc2ghI3p94 Hq9NLBbD/xonLidj4omk2NPWw7vjVAU= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-144-76tk9KvOOkKsTUwgwE2rUg-1; Thu, 19 Oct 2023 11:11:34 -0400 X-MC-Unique: 76tk9KvOOkKsTUwgwE2rUg-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-778915a0c73so328478285a.1 for <gcc-patches@gcc.gnu.org>; Thu, 19 Oct 2023 08:11:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697728294; x=1698333094; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=J1n7c2tVCptwmxj7mklK6GAXGOpMGMwekCLkvf1dS4s=; b=xF6GrmFHIQtV4wdy2NiFsQGaFDvB00aTaeVcnMcxjW69gXBhip+pYr5ZsDIodUBxgK CNJYW+wiihp/fdZzimbD7Y0M+jnQEYGRMRNRc6Uzs2aIcFCjirzAYOTxA0zt8noT66K8 j5G/tspEJqJYQIiDMb3/Ro0xMdhwWRr8ExxQqRGkusOkPMrh86Hi50vZ6pcgwl6Q3VVa 92lScRkTzd5l54IjN2vMUsCcVqhLTFFAps5DmGtQAZ8G1pxmZaptcNDJEOGAvn5VcyH9 Nx2P5unW4q4vW2DckOAb7aa52nGnPJch+zRPbcKL7aVHsYmBTbTDKe0mhEGypXTUhe29 xwAw== X-Gm-Message-State: AOJu0YzujthZe1V+0BYeID8shrAtBZY04l/Atru3/XDMi47ZXxgFyjA+ RQClDHuS+ARRtpBJ+TaKcp2xAxvac4YT4czhXBjrUwxSywzI4qHF9uDZafOZTaHAxNQygx3Nlgh kqDOgKGCDvFo0dCoZy1d6+ktEG3QabsXAVGSFnI/RGwzaLOHJSFAVUfPVySeFW6ngvgQhzzHh3Q == X-Received: by 2002:a05:620a:c45:b0:776:f5bb:f2fc with SMTP id u5-20020a05620a0c4500b00776f5bbf2fcmr2770363qki.9.1697728293844; Thu, 19 Oct 2023 08:11:33 -0700 (PDT) X-Received: by 2002:a05:620a:c45:b0:776:f5bb:f2fc with SMTP id u5-20020a05620a0c4500b00776f5bbf2fcmr2770334qki.9.1697728293421; Thu, 19 Oct 2023 08:11:33 -0700 (PDT) Received: from jason.com (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id w12-20020a05620a148c00b007676f3859fasm804195qkj.30.2023.10.19.08.11.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 08:11:32 -0700 (PDT) From: Jason Merrill <jason@redhat.com> To: gcc-patches@gcc.gnu.org, Jakub Jelinek <jakub@redhat.com> Subject: [PATCH] ABOUT-GCC-NLS: add usage guidance Date: Thu, 19 Oct 2023 11:11:30 -0400 Message-Id: <20231019151130.1929663-1-jason@redhat.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780197196397183994 X-GMAIL-MSGID: 1780197196397183994 |
Series |
ABOUT-GCC-NLS: add usage guidance
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Jason Merrill
Oct. 19, 2023, 3:11 p.m. UTC
A recent question led me to look at this file again, and it occurred to me that it could use to offer more guidance. OK for trunk? -- 8< -- gcc/ChangeLog: * ABOUT-GCC-NLS: Add usage guidance. --- gcc/ABOUT-GCC-NLS | 13 +++++++++++++ 1 file changed, 13 insertions(+) base-commit: faa0e82b409362ba022f6872cea9677e9dd42f0c
Comments
On Thu, Oct 19, 2023 at 11:11:30AM -0400, Jason Merrill wrote: > A recent question led me to look at this file again, and it occurred to me that > it could use to offer more guidance. OK for trunk? > > -- 8< -- > > gcc/ChangeLog: > > * ABOUT-GCC-NLS: Add usage guidance. > --- > gcc/ABOUT-GCC-NLS | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/gcc/ABOUT-GCC-NLS b/gcc/ABOUT-GCC-NLS > index e90a67144e3..4c8b94d0811 100644 > --- a/gcc/ABOUT-GCC-NLS > +++ b/gcc/ABOUT-GCC-NLS > @@ -23,6 +23,19 @@ For example, GCC source code should not contain calls like `error > ("unterminated comment")' instead, as it is the `error' function's > responsibility to translate the message before the user sees it. > > +In general, use no markup for strings that are the immediate format string > +argument of a diagnostic function. Use G_("str") for strings that will be > +used as the format string for a diagnostic but are e.g. assigned to a > +variable first. Use N_("str") for other strings, particularly in a > +statically allocated array, that will be translated later by > +e.g. _(msgs[idx]). Use _("str") for strings that will not be translated The difference between G_ and N_ is whether they are GCC internal diagnostic format strings or printf family format strings (gcc-internal-format vs. c-format in po/gcc.pot), not anything else, so G_ can be used in statically allocated array as well and both for diagnostic routines and printf* family when translation is desirable it is eventually translated through _() or other gettext invocations, either inside of diagnostics.cc or elsewhere. So, the note about statically allocated array should move to G_ as well, and N_ should be described as similarly, but for strings which after translation are passed to printf family functions or so. ANd the translated later by e.g. note should be again for both and said that it is done automatically for GCC diagnostic routines. Jakub
On 10/19/23 11:21, Jakub Jelinek wrote: > On Thu, Oct 19, 2023 at 11:11:30AM -0400, Jason Merrill wrote: >> A recent question led me to look at this file again, and it occurred to me that >> it could use to offer more guidance. OK for trunk? >> >> -- 8< -- >> >> gcc/ChangeLog: >> >> * ABOUT-GCC-NLS: Add usage guidance. >> --- >> gcc/ABOUT-GCC-NLS | 13 +++++++++++++ >> 1 file changed, 13 insertions(+) >> >> diff --git a/gcc/ABOUT-GCC-NLS b/gcc/ABOUT-GCC-NLS >> index e90a67144e3..4c8b94d0811 100644 >> --- a/gcc/ABOUT-GCC-NLS >> +++ b/gcc/ABOUT-GCC-NLS >> @@ -23,6 +23,19 @@ For example, GCC source code should not contain calls like `error >> ("unterminated comment")' instead, as it is the `error' function's >> responsibility to translate the message before the user sees it. >> >> +In general, use no markup for strings that are the immediate format string >> +argument of a diagnostic function. Use G_("str") for strings that will be >> +used as the format string for a diagnostic but are e.g. assigned to a >> +variable first. Use N_("str") for other strings, particularly in a >> +statically allocated array, that will be translated later by >> +e.g. _(msgs[idx]). Use _("str") for strings that will not be translated > > The difference between G_ and N_ is whether they are GCC internal diagnostic > format strings or printf family format strings (gcc-internal-format vs. > c-format in po/gcc.pot), not anything else, so G_ can be used in statically > allocated array as well and both for diagnostic routines and printf* family > when translation is desirable it is eventually translated through _() or > other gettext invocations, either inside of diagnostics.cc or elsewhere. > So, the note about statically allocated array should move to G_ as well, and > N_ should be described as similarly, but for strings which after translation > are passed to printf family functions or so. ANd the translated later by > e.g. note should be again for both and said that it is done automatically > for GCC diagnostic routines. How about this? In general, use no markup for strings that are the immediate format string argument of a diagnostic function. Use G_("str") for strings that will be used as the format string for a diagnostic but are e.g. assigned to a variable first. Use N_("str") for strings that are not diagnostic format strings, but will still be translated later. Use _("str") for strings that will not be translated elsewhere. It's important not to use _("str") in the initializer of a statically allocated variable; use one of the others instead and make sure that uses of that variable translate the string, whether directly with _(msg) or by passing it to a diagnostic or other function that performs the translation. Jason
On Thu, Oct 19, 2023 at 12:13:55PM -0400, Jason Merrill wrote: > How about this? > > In general, use no markup for strings that are the immediate format string > argument of a diagnostic function. Use G_("str") for strings that will be > used as the format string for a diagnostic but are e.g. assigned to a > variable first. Use N_("str") for strings that are not diagnostic format > strings, but will still be translated later. Use _("str") for strings that > will not be translated elsewhere. It's important not to use _("str") in > the initializer of a statically allocated variable; use one of the others > instead and make sure that uses of that variable translate the string, > whether directly with _(msg) or by passing it to a diagnostic or other > function that performs the translation. LGTM. Jakub
diff --git a/gcc/ABOUT-GCC-NLS b/gcc/ABOUT-GCC-NLS index e90a67144e3..4c8b94d0811 100644 --- a/gcc/ABOUT-GCC-NLS +++ b/gcc/ABOUT-GCC-NLS @@ -23,6 +23,19 @@ For example, GCC source code should not contain calls like `error ("unterminated comment")' instead, as it is the `error' function's responsibility to translate the message before the user sees it. +In general, use no markup for strings that are the immediate format string +argument of a diagnostic function. Use G_("str") for strings that will be +used as the format string for a diagnostic but are e.g. assigned to a +variable first. Use N_("str") for other strings, particularly in a +statically allocated array, that will be translated later by +e.g. _(msgs[idx]). Use _("str") for strings that will not be translated +elsewhere. + +Avoid using %s to compose a diagnostic message from multiple translateable +strings; instead, write out the full diagnostic message for each variant. +Only use %s for message components that do not need translation, such as +keywords. + By convention, any function parameter in the GCC sources whose name ends in `msgid' is expected to be a message requiring translation. If the parameter name ends with `gmsgid', it is assumed to be a GCC