Skip to content

Commit

Permalink
Fix issues with localized_note
Browse files Browse the repository at this point in the history
The way this currently works causes issues with functions like comma_list
(because it inserts an unwanted message even if none is passed)
and with attempts to call it recursively on its own arguments
(such as a localized_note containing additional levels of localized_note
variables).
  • Loading branch information
reosarevok committed Nov 5, 2024
1 parent 7c53816 commit 5d9e1a1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/MusicBrainz/Server/Entity/EditNote.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use Moose;
use namespace::autoclean;

use MusicBrainz::Server::Constants qw( $EDITOR_MODBOT );
use MusicBrainz::Server::Data::Utils qw( datetime_to_iso8601 );
use MusicBrainz::Server::Data::Utils qw(
contains_string
datetime_to_iso8601
);
use MusicBrainz::Server::Entity::Types;
use MusicBrainz::Server::Entity::Util::JSON qw( to_json_object );
use MusicBrainz::Server::Filters qw( format_editnote );
Expand Down Expand Up @@ -75,17 +78,22 @@ sub _localize_text {
my $version = $source->{version} // 0;
my $fn_package = 'MusicBrainz::Server::Translation';
my $fn_name = 'l';
my @args = ($source->{message} // '');
my @args;
my $source_vars;

if ($version == 0) {
@args = ($source->{message} // '');
# old versions of `localized_note` passed substitution
# variables as `args`.
$source_vars = $source->{args};
} elsif ($version == 1) {
push @args, @{ $source->{args} // [] };
my $no_message_functions = [ qw ( comma_list comma_only_list ) ];

$fn_name = $source->{function} // 'l';
@args = ($source->{message} // '')
unless contains_string($no_message_functions, $fn_name);
push @args, map { _localize_text($_, $depth + 1) } @{ $source->{args} // [] };

$source_vars = $source->{vars};

my $domain = $source->{domain};
Expand Down

0 comments on commit 5d9e1a1

Please sign in to comment.