From 64d095b9806f23130b32cefd23162ae679a3c011 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Sun, 12 Jul 2020 21:01:14 +0400 Subject: [PATCH] Bug 25067: Do not set msgctxt in pref PO files By having msgctxt set, msgmerge will "lose" some translations, forcing translators to re-translate them. Also, Pootle does not offer the ability to search by context, making it harder to translate all strings related to a single preference. --- misc/translator/xgettext-pref | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/misc/translator/xgettext-pref b/misc/translator/xgettext-pref index 7ddbc883fe..1113a27f95 100755 --- a/misc/translator/xgettext-pref +++ b/misc/translator/xgettext-pref @@ -45,6 +45,7 @@ display this help and exit use Modern::Perl; +use File::Basename; use Getopt::Long; use Locale::PO; use Pod::Usage; @@ -90,14 +91,15 @@ my $pot = { for my $file (@files) { my $pref = LoadFile($file); while ( my ($tab, $tab_content) = each %$pref ) { - add_po($file, undef, $tab); + add_po(undef, basename($file)); if ( ref($tab_content) eq 'ARRAY' ) { add_prefs( $file, $tab, $tab_content ); } else { while ( my ($section, $sysprefs) = each %$tab_content ) { my $context = "$tab > $section"; - add_po($file, $tab, $section); + my $msgid = sprintf('%s %s', basename($file), $section); + add_po($tab, $msgid); add_prefs( $file, $context, $sysprefs ); } } @@ -123,26 +125,26 @@ sub add_prefs { next unless $key eq 'choices' or $key eq 'multiple'; next unless ref($value) eq 'HASH'; for my $ckey ( keys %$value ) { - add_po( $file, "$context > $pref_name", $value->{$ckey} ); + my $msgid = sprintf('%s#%s# %s', basename($file), $pref_name, $value->{$ckey}); + add_po( "$context > $pref_name", $msgid ); } } } elsif ($element) { - add_po( $file, "$context > $pref_name", $element ); + my $msgid = sprintf('%s#%s# %s', basename($file), $pref_name, $element); + add_po( "$context > $pref_name", $msgid ); } } } } sub add_po { - my ( $reference, $msgctxt, $msgid ) = @_; + my ($comment, $msgid ) = @_; return unless $msgid; - my $key = ($msgctxt // '') . ";$msgid"; - $pot->{$key} = Locale::PO->new( - -reference => $reference, - -msgctxt => $msgctxt, + $pot->{$msgid} = Locale::PO->new( + -comment => $comment, -msgid => $msgid, -msgstr => '', ); -- 2.20.1