From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C18F48331 for ; Wed, 30 Aug 2023 14:49:25 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9AEAA34D09 for ; Wed, 30 Aug 2023 14:48:55 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 30 Aug 2023 14:48:54 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 80B01473BB for ; Wed, 30 Aug 2023 14:48:54 +0200 (CEST) From: Maximiliano Sandoval To: pve-devel@lists.proxmox.com Date: Wed, 30 Aug 2023 14:48:51 +0200 Message-Id: <20230830124851.43586-1-m.sandoval@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.004 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH proxmox-i18n] js generator: try to extract comments from source X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Aug 2023 12:49:25 -0000 Adds a way to extract comments to the resulting .po files matching xgettext's behaviour. Useful for instances like ```js // Translators: This is the verb, not the noun gettext("Profile"); // Translators: This would read 'Manage OSD' Ext.String.format(gettext('Manage {0}'), 'OSD'); ``` where the string is not enough to guarantee is a satisfactory translation. Do note that two identical messages with different comments will count as the same message (same msgid) from the point of view of gettext. To truly differentiate them one would need to support Context, see [1]. Caveats: - Cannot extract multiline comments - Does not understand comments in the /* comment */ form [1] https://www.gnu.org/software/gettext/manual/html_node/Contexts.html Signed-off-by: Maximiliano Sandoval --- jsgettext.pl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/jsgettext.pl b/jsgettext.pl index 7f758fd..d0bf7a9 100755 --- a/jsgettext.pl +++ b/jsgettext.pl @@ -93,7 +93,7 @@ my $href = { }; sub extract_msg { - my ($filename, $linenr, $line) = @_; + my ($filename, $linenr, $line, $comment) = @_; my $count = 0; @@ -111,7 +111,7 @@ sub extract_msg { if (my $po = $href->{$text}) { $po->reference($po->reference() . " $ref"); } else { - $href->{$text} = Locale::PO->new(-msgid=> $text, -reference=> $ref, -msgstr=> ''); + $href->{$text} = Locale::PO->new(-msgid=> $text, -reference=> $ref, -msgstr=> '', -automatic=> $comment); } } die "can't extract gettext message in '$filename' line $linenr\n" if !$count; @@ -122,10 +122,13 @@ my $sources = find_js_sources($dirs); foreach my $s (@$sources) { open(my $SRC_FH, '<', $s) || die "unable to open file '$s' - $!\n"; + my $prev_line; while(defined(my $line = <$SRC_FH>)) { if ($line =~ m/gettext\s*\(/ && $line !~ m/^\s*function gettext/) { - extract_msg($s, $., $line); + my ($comment) = $prev_line =~ /\/\/\s+(.*)/; + extract_msg($s, $., $line, $comment); } + $prev_line = $line; } close($SRC_FH); } -- 2.39.2