Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBS-13117: Prevent localizing admin-only messages #3091

Merged
merged 13 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc.unfixed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ rules:
wrap-iife: warn
camelcase: [warn, {properties: never,
allow: [
"l_admin",
"ln_admin",
"l_attributes",
"ln_attributes",
"lp_attributes",
Expand Down
2 changes: 2 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ globals:
N_lp: readonly
exp: readonly
texp: readonly
l_admin: readonly
ln_admin: readonly
l_attributes: readonly
ln_attributes: readonly
lp_attributes: readonly
Expand Down
2 changes: 1 addition & 1 deletion docker/musicbrainz-tests/run_circleci_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rm /etc/service/{postgresql,redis}/down && sv start postgresql redis

sudo -E -H -u musicbrainz carton exec -- ./script/create_test_db.sh

sudo -E -H -u musicbrainz make -C po all_quiet deploy
sudo -E -H -u musicbrainz make -C po test_source all_quiet deploy

MUSICBRAINZ_RUNNING_TESTS=1 \
NODE_ENV=test \
Expand Down
9 changes: 4 additions & 5 deletions lib/MusicBrainz/Server/Controller/Admin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use Try::Tiny;

BEGIN { extends 'MusicBrainz::Server::Controller' }

use MusicBrainz::Server::Translation qw( l );
use MusicBrainz::Server::Constants qw( :privileges );
use MusicBrainz::Server::ControllerUtils::JSON qw( serialize_pager );
use MusicBrainz::Server::Data::Utils qw( boolean_to_json );
Expand Down Expand Up @@ -89,7 +88,7 @@ sub edit_user : Path('/admin/user/edit') Args(1) RequireAuth HiddenOnMirrors Sec
}
}

$c->flash->{message} = l('User successfully edited.');
$c->flash->{message} = 'User successfully edited.';
$c->response->redirect($c->uri_for_action('/user/profile', [$form->field('username')->value]));
$c->detach;
} else {
Expand Down Expand Up @@ -151,7 +150,7 @@ sub edit_banner : Path('/admin/banner/edit') Args(0) RequireAuth(banner_editor)
$store->set($alert_cache_key, $form->values->{message});
$store->set($alert_mtime_cache_key, time());

$c->flash->{message} = l('Banner updated. Remember that each server has its own, independent banner.');
$c->flash->{message} = 'Banner updated. Remember that each server has its own, independent banner.';
$c->response->redirect($c->uri_for('/'));
$c->detach;
} else {
Expand Down Expand Up @@ -187,7 +186,7 @@ sub email_search : Path('/admin/email-search') Args(0) RequireAuth(account_admin
} catch {
my $error = $_;
if ("$error" =~ m/invalid regular expression/) {
$form->field('email')->add_error(l('Invalid regular expression.'));
$form->field('email')->add_error('Invalid regular expression.');
$c->response->status(HTTP_BAD_REQUEST);
} else {
die $error;
Expand Down Expand Up @@ -253,7 +252,7 @@ sub locked_username_search : Path('/admin/locked-usernames/search') Args(0) Requ
} catch {
my $error = $_;
if ("$error" =~ m/invalid regular expression/) {
$form->field('username')->add_error(l('Invalid regular expression.'));
$form->field('username')->add_error('Invalid regular expression.');
$c->response->status(HTTP_BAD_REQUEST);
} else {
die $error;
Expand Down
8 changes: 4 additions & 4 deletions lib/MusicBrainz/Server/Controller/Admin/Attributes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use utf8;
use MusicBrainz::Server::Data::Utils qw( contains_string );
use MusicBrainz::Server::Entity::Util::JSON qw( to_json_array );

use MusicBrainz::Server::Translation qw( l );

BEGIN { extends 'MusicBrainz::Server::Controller' }

my @models = qw(
Expand Down Expand Up @@ -127,7 +125,8 @@ sub delete : Chained('attribute_base') Args(1) RequireAuth(account_admin) Secure
$c->stash->{attribute} = $attr;

if ($c->model($model)->in_use($id)) {
my $error_message = l('You cannot remove the attribute "{name}" because it is still in use.', { name => $attr->name });
my $attr_name = $attr->name;
my $error_message = "You cannot remove the attribute “$attr_name” because it is still in use.";

$c->stash(
current_view => 'Node',
Expand All @@ -139,7 +138,8 @@ sub delete : Chained('attribute_base') Args(1) RequireAuth(account_admin) Secure
}

if ($c->model($model)->has_children($id)) {
my $error_message = l('You cannot remove the attribute “{name}” because it is the parent of other attributes.', { name => $attr->name });
my $attr_name = $attr->name;
my $error_message = "You cannot remove the attribute “$attr_name” because it is the parent of other attributes.";

$c->stash(
current_view => 'Node',
Expand Down
7 changes: 3 additions & 4 deletions lib/MusicBrainz/Server/Form/Admin/Attributes/Language.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use warnings;
use HTML::FormHandler::Moose;

use MusicBrainz::Server::Constants qw( :language_frequency );
use MusicBrainz::Server::Translation qw( lp );

extends 'MusicBrainz::Server::Form';
with 'MusicBrainz::Server::Form::Role::Edit';
Expand Down Expand Up @@ -48,9 +47,9 @@ has_field 'frequency' => (

sub options_frequency {
return [
$LANGUAGE_FREQUENCY_HIDDEN, lp('Hidden', 'language optgroup'),
$LANGUAGE_FREQUENCY_OTHER, lp('Other', 'language optgroup'),
$LANGUAGE_FREQUENCY_FREQUENT, lp('Frequently used', 'language optgroup'),
$LANGUAGE_FREQUENCY_HIDDEN, 'Hidden',
$LANGUAGE_FREQUENCY_OTHER, 'Other',
$LANGUAGE_FREQUENCY_FREQUENT, 'Frequently used',
];
}

Expand Down
9 changes: 4 additions & 5 deletions lib/MusicBrainz/Server/Form/Admin/Attributes/Script.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use warnings;
use HTML::FormHandler::Moose;

use MusicBrainz::Server::Constants qw( :script_frequency );
use MusicBrainz::Server::Translation qw( lp );

extends 'MusicBrainz::Server::Form';
with 'MusicBrainz::Server::Form::Role::Edit';
Expand Down Expand Up @@ -39,10 +38,10 @@ has_field 'frequency' => (

sub options_frequency {
return [
$SCRIPT_FREQUENCY_HIDDEN, lp('Hidden', 'script frequency'),
$SCRIPT_FREQUENCY_UNCOMMON, lp('Other (Uncommon)', 'script frequency'),
$SCRIPT_FREQUENCY_OTHER, lp('Other', 'script frequency'),
$SCRIPT_FREQUENCY_FREQUENT, lp('Frequently used', 'script frequency'),
$SCRIPT_FREQUENCY_HIDDEN, 'Hidden',
$SCRIPT_FREQUENCY_UNCOMMON, 'Other (Uncommon)',
$SCRIPT_FREQUENCY_OTHER, 'Other',
$SCRIPT_FREQUENCY_FREQUENT, 'Frequently used',
];
}

Expand Down
3 changes: 1 addition & 2 deletions lib/MusicBrainz/Server/Form/Admin/LinkAttributeType.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use warnings;
use HTML::FormHandler::Moose;
use MusicBrainz::Server::Form::Utils qw( select_options_tree );
use MusicBrainz::Server::Constants qw( $INSTRUMENT_ROOT_ID );
use MusicBrainz::Server::Translation qw( l );

extends 'MusicBrainz::Server::Form';
with 'MusicBrainz::Server::Form::Role::Edit';
Expand Down Expand Up @@ -56,7 +55,7 @@ after validate => sub {

my $root = defined $parent ? ($parent->root_id // $parent->id) : 0;
if ($root == $INSTRUMENT_ROOT_ID) {
$self->field('parent_id')->add_error(l('Cannot add or edit instruments here; use the instrument editing forms instead.'));
$self->field('parent_id')->add_error('Cannot add or edit instruments here; use the instrument editing forms instead.');
}
};

Expand Down
28 changes: 18 additions & 10 deletions po/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ MSGWRAP:=79

GIT_LS_PERL:=git ls-files -- \
':(top,glob)lib/**/*.pm' \
':(top,glob)lib/**/*.pl' \
':(top,glob,exclude)lib/**/*Admin*.pm' \
':(top,glob,exclude)lib/**/*Admin*/**/*.pm' \
| $(SED_ESCAPE_SPACES)

GIT_LS_JS:=git ls-files -- \
':(top,glob)root/**/*.js' \
':(top,glob,exclude)root/static/scripts/tests/**/*.js' \
':(top,glob,exclude)root/static/build/**/*.js' \
':(top,glob,exclude)root/static/lib/**/*.js' \
':(top,glob,exclude)root/statistics/**/*.js' \
| $(SED_ESCAPE_SPACES)
':(top,glob)root/**/*.js' \
':(top,glob,exclude)root/admin/**/*.js' \
':(top,glob,exclude)root/static/scripts/tests/**/*.js' \
':(top,glob,exclude)root/static/build/**/*.js' \
':(top,glob,exclude)root/static/lib/**/*.js' \
':(top,glob,exclude)root/statistics/**/*.js' \
| $(SED_ESCAPE_SPACES)

GIT_LS_TT:=git ls-files -- \
':(top,glob)root/**/*.tt' \
':(top,glob,exclude)root/statistics/**/*.tt' \
| $(SED_ESCAPE_SPACES)
':(top,glob)root/**/*.tt' \
':(top,glob,exclude)root/admin/**/*.tt' \
':(top,glob,exclude)root/statistics/**/*.tt' \
| $(SED_ESCAPE_SPACES)

GIT_LS_STATTT:=git ls-files -- \
':(top,glob)root/statistics/**/*.tt' \
Expand Down Expand Up @@ -139,3 +142,8 @@ check_quiet:
@for file in $(POFILES); do \
msgfmt -o /dev/null -c $$file;\
done

test_source:
@../t/no_gettext_for_admin.sh

.PHONY: all all_quiet check check_quiet clean pot test_source
10 changes: 5 additions & 5 deletions root/admin/DeleteUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ const DeleteUser = ({
<UserAccountLayout
entity={user}
page="delete"
title={l('Delete Account')}
title="Delete Account"
>
<h2>{l('Delete Account')}</h2>
<h2>{'Delete Account'}</h2>
<p>
{exp.l(
{exp.l_admin(
`Are you sure you want to delete all information about {e}?
This cannot be undone!`,
{e: <EditorLink editor={user} />},
Expand All @@ -53,7 +53,7 @@ const DeleteUser = ({
<FormRowCheckbox
field={form.field.allow_reuse}
hasNoMargin
label={texp.l(
label={texp.l_admin(
'Allow the name “{editor_name}” to be reused.',
{editor_name: user.name},
)}
Expand All @@ -63,7 +63,7 @@ const DeleteUser = ({
<div className="row no-margin">
<FormSubmit
inputClassName="negative"
label={texp.l('Delete {e}', {e: user.name})}
label={texp.l_admin('Delete {e}', {e: user.name})}
/>
</div>
</form>
Expand Down
13 changes: 7 additions & 6 deletions root/admin/EditBanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import Layout from '../layout/index.js';
import {l_admin} from '../static/scripts/common/i18n/admin.js';
import FormCsrfToken
from '../static/scripts/edit/components/FormCsrfToken.js';
import FormRowTextArea
Expand All @@ -22,21 +23,21 @@ type Props = {
};

const EditBanner = ({form}: Props): React$Element<typeof Layout> => (
<Layout fullWidth title={l('Edit Banner Message')}>
<Layout fullWidth title="Edit Banner Message">
<div id="content">
<h1>{l('Edit banner message')}</h1>
<h1>{'Edit banner message'}</h1>
<p>
{l(`This will set the banner message that is shown at the top
of each page. An empty string removes the banner.`)}
{l_admin(`This will set the banner message that is shown at the top
reosarevok marked this conversation as resolved.
Show resolved Hide resolved
of each page. An empty string removes the banner.`)}
</p>
<form action="/admin/banner/edit" method="post">
<FormCsrfToken form={form} />
<FormRowTextArea
field={form.field.message}
label={addColonText(l('Banner message'))}
label="Banner message:"
/>
<div className="row no-label">
<FormSubmit label={l('Update')} />
<FormSubmit label="Update" />
</div>
</form>
</div>
Expand Down
Loading