Skip to content

Commit

Permalink
Use parameterized string for confirmation messages
Browse files Browse the repository at this point in the history
Previously, the confirmation message was built manually in several
places throughout the code, concatenating strings with variables.

We now use a string with parameters, which is fed to sprintf prior to
display. This gives translators more control to over the final message,
and allows removing now-unused $s_in_project string.

Updated strings:
  - $s_confirm_custom_field_deletion
  - $s_confirm_used_custom_field_deletion
  - $s_confirm_custom_field_unlinking
  - $s_config_delete_sure
  - $s_confirm_file_delete_msg
  - $s_delete_account_sure_msg
  - $s_query_delete_msg
  - $s_remove_user_sure_msg
  - $s_version_delete_sure

Issue #27779
  • Loading branch information
dregad committed Dec 30, 2020
1 parent f6502be commit 6c3482d
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 38 deletions.
19 changes: 9 additions & 10 deletions lang/strings_english.txt
Expand Up @@ -826,8 +826,7 @@ $s_reopen_resolution = 'Resolution to which a reopened issue is set';
$s_limit_view_unless_threshold_option = 'View other users\' issues (if not set, access will be limited to issues reported, handled, or monitored by the user)';

# manage_config_revert_page
$s_config_delete_sure = 'Are you sure you want to delete the settings for:';
$s_in_project = 'in project';
$s_config_delete_sure = 'Are you sure you want to delete the settings for: %1$s in project %2$s ?';

This comment has been minimized.

Copy link
@Nikerabbit

Nikerabbit Dec 30, 2020

Why space before ?? Also, should the colon be removed?

This comment has been minimized.

Copy link
@dregad

dregad Dec 30, 2020

Author Member

Sorry, it's a typographical convention in French to have a space before ?, unlike English. Will fix.

As for the :, you're right it makes sense to remove it, I didn't think about it as I added the parameters.

$s_delete_config_button = 'Delete Settings';

# adm_config_report.php
Expand Down Expand Up @@ -953,7 +952,7 @@ $s_version_added_msg = 'Version has been successfully added...';
$s_version_deleted_msg = 'Version has been successfully deleted...';

# manage_proj_version_delete_page.php
$s_version_delete_sure = 'Are you sure you want to delete this version?';
$s_version_delete_sure = 'Are you sure you want to delete version "%1$s" ?';
$s_delete_version_button = 'Delete Version';

# manage_proj_version_edit_page.php
Expand All @@ -972,7 +971,7 @@ $s_account_delete_protected_msg = 'Account protected. Cannot delete this account
$s_account_deleted_msg = 'Account deleted...';

# manage_user_delete_page.php
$s_delete_account_sure_msg = 'Are you sure you wish to delete this account?';
$s_delete_account_sure_msg = 'Are you sure you wish to delete user account "%1$s" ?';

# manage_user_edit_page.php
$s_notify_user = 'Notify user of this change';
Expand Down Expand Up @@ -1075,7 +1074,7 @@ $s_title = 'Title';
$s_project_file_deleted_msg = 'Project file deleted.';

# proj_doc_delete_page.php
$s_confirm_file_delete_msg = 'Are you sure you wish to delete this file?';
$s_confirm_file_delete_msg = 'Are you sure you wish to delete file "%1$s" ?';

# proj_doc_edit_page.php
$s_filename = 'Filename';
Expand All @@ -1099,7 +1098,7 @@ $s_project_user_added_msg = 'Successfully added user to project.';
$s_project_removed_user_msg = 'Successfully removed user from project.';

# proj_user_delete_page.php
$s_remove_user_sure_msg = 'Are you sure you wish to remove this user?';
$s_remove_user_sure_msg = 'Are you sure you wish to remove user "%1$s" from projectz "%2$s" ?';

This comment has been minimized.

Copy link
@Nikerabbit

Nikerabbit Dec 30, 2020

Typo in projectz.

This comment has been minimized.

Copy link
@dregad

dregad Dec 30, 2020

Author Member

Thanks for catching it

$s_remove_user_button = 'Remove User';
$s_remove_all_users_sure_msg = 'Are you sure you wish to remove all the users of this project?';
$s_remove_all_users_button = 'Remove All Users';
Expand Down Expand Up @@ -1258,7 +1257,7 @@ $s_query_blank_name = 'You cannot store a filter without a name. Please give thi
$s_query_name_too_long = 'You cannot store a filter name with more than 64 characters. Please give this filter a shorter name.';
$s_query_store_error = 'There was an error saving this filter.';
$s_open_queries = 'Manage Filters';
$s_query_delete_msg = 'Are you sure you wish to delete this filter?';
$s_query_delete_msg = 'Are you sure you wish to delete filter "%1$s" ?';
$s_edit_filter = 'Edit Filter';
$s_owner = 'Owner';
$s_update_filter = 'Update filter';
Expand Down Expand Up @@ -1337,10 +1336,10 @@ $s_linked_projects_label = 'Linked Projects';
$s_custom_field_sequence = 'Sequence';
$s_custom_field_sequence_label = 'Sequence';
$s_custom_field_type_enum_string = '0:String,1:Numeric,2:Float,3:Enumeration,4:E-mail,5:Checkbox,6:List,7:Multiselection list,8:Date,9:Radio,10:Textarea';
$s_confirm_used_custom_field_deletion = 'This field is currently linked to at least one project. If you continue all values for this field will be permanently deleted. This action cannot be undone. If you do not want to delete this field, hit the Back button in your browser. To proceed, click the button below';
$s_confirm_custom_field_deletion = 'Are you sure you want to delete this custom field and all associated values?';
$s_confirm_used_custom_field_deletion = 'Field "%1$s" is currently linked to at least one project. If you continue, all values for this field will be permanently deleted. This action cannot be undone. If you do not want to delete this field, hit the Back button in your browser. To proceed, click the button below';
$s_confirm_custom_field_deletion = 'Are you sure you want to delete custom field "%1$s" and all associated values?';
$s_field_delete_button = 'Delete Field';
$s_confirm_custom_field_unlinking = 'Are you sure you want to unlink this custom field from the project? The values will not be deleted as long as the custom field itself is not deleted.';
$s_confirm_custom_field_unlinking = 'Are you sure you want to unlink custom field "%1$s" from the project? The values will not be deleted as long as the custom field itself is not deleted.';
$s_field_remove_button = 'Remove Field';
$s_hide_status = 'Hide Status';
$s_filter_closed = 'Closed';
Expand Down
7 changes: 5 additions & 2 deletions manage_config_revert.php
Expand Up @@ -73,8 +73,11 @@

if( '' != $f_revert ) {
# Confirm with the user
helper_ensure_confirmed( lang_get( 'config_delete_sure' ) . lang_get( 'word_separator' ) .
string_html_specialchars( implode( ', ', $t_revert_vars ) ) . lang_get( 'word_separator' ) . lang_get( 'in_project' ) . lang_get( 'word_separator' ) . string_attribute( project_get_name( $f_project_id ) ),
helper_ensure_confirmed(
sprintf( lang_get( 'config_delete_sure' ),
string_html_specialchars( implode( ', ', $t_revert_vars ) ),
string_attribute( project_get_name( $f_project_id ) )
),
lang_get( 'delete_config_button' ) );

foreach ( $t_revert_vars as $t_revert ) {
Expand Down
12 changes: 6 additions & 6 deletions manage_custom_field_delete.php
Expand Up @@ -60,14 +60,14 @@
$t_definition = custom_field_get_definition( $f_field_id );

if( 0 < count( custom_field_get_project_ids( $f_field_id ) ) ) {
helper_ensure_confirmed( lang_get( 'confirm_used_custom_field_deletion' ) .
'<br />' . lang_get( 'custom_field_label' ) . lang_get( 'word_separator' ) . string_attribute( $t_definition['name'] ),
lang_get( 'field_delete_button' ) );
$t_msg = lang_get( 'confirm_used_custom_field_deletion' );
} else {
helper_ensure_confirmed( lang_get( 'confirm_custom_field_deletion' ) .
'<br />' . lang_get( 'custom_field_label' ) . lang_get( 'word_separator' ) . string_attribute( $t_definition['name'] ),
lang_get( 'field_delete_button' ) );
$t_msg = lang_get( 'confirm_custom_field_deletion' );
}
helper_ensure_confirmed(
sprintf( $t_msg, string_attribute( $t_definition['name'] ) ),
lang_get( 'field_delete_button' )
);

custom_field_destroy( $f_field_id );

Expand Down
8 changes: 6 additions & 2 deletions manage_filter_delete.php
Expand Up @@ -56,8 +56,12 @@
exit;
}

helper_ensure_confirmed( lang_get( 'query_delete_msg' ) . '<br>"' . string_attribute( filter_get_field( $f_filter_id, 'name' ) ) . '"',
lang_get( 'delete_query' ) );
helper_ensure_confirmed(
sprintf( lang_get( 'query_delete_msg' ),
string_attribute( filter_get_field( $f_filter_id, 'name' ) )
),
lang_get( 'delete_query' )
);

filter_db_delete_filter( $f_filter_id );

Expand Down
10 changes: 7 additions & 3 deletions manage_proj_custom_field_remove.php
Expand Up @@ -66,9 +66,13 @@
$t_definition = custom_field_get_definition( $f_field_id );

# Confirm with the user
helper_ensure_confirmed( lang_get( 'confirm_custom_field_unlinking' ) .
'<br />' . lang_get( 'custom_field_label' ) . lang_get( 'word_separator' ) . string_attribute( $t_definition['name'] ),
lang_get( 'field_remove_button' ) );
helper_ensure_confirmed(
sprintf(
lang_get( 'confirm_custom_field_unlinking' ),
string_attribute( $t_definition['name'] )
),
lang_get( 'field_remove_button' )
);

if( $f_return == 'custom_field' ) {
$t_redirect_url = 'manage_custom_field_edit_page.php?field_id=' . $f_field_id;
Expand Down
10 changes: 7 additions & 3 deletions manage_proj_user_remove.php
Expand Up @@ -73,9 +73,13 @@
$t_user = user_get_row( $f_user_id );

# Confirm with the user
helper_ensure_confirmed( lang_get( 'remove_user_sure_msg' ) .
'<br />' . lang_get( 'username_label' ) . lang_get( 'word_separator' ) . string_attribute( $t_user['username'] ),
lang_get( 'remove_user_button' ) );
helper_ensure_confirmed(
sprintf( lang_get( 'remove_user_sure_msg' ),
string_attribute( $t_user['username'] ),
string_attribute( project_get_name( $f_project_id ) )
),
lang_get( 'remove_user_button' )
);

project_remove_user( $f_project_id, $f_user_id );
}
Expand Down
9 changes: 6 additions & 3 deletions manage_proj_ver_delete.php
Expand Up @@ -59,9 +59,12 @@
access_ensure_project_level( config_get( 'manage_project_threshold' ), $t_version_info->project_id );

# Confirm with the user
helper_ensure_confirmed( lang_get( 'version_delete_sure' ) .
'<br />' . lang_get( 'version_label' ) . lang_get( 'word_separator' ) . string_display_line( $t_version_info->version ),
lang_get( 'delete_version_button' ) );
helper_ensure_confirmed(
sprintf( lang_get( 'version_delete_sure' ),
string_display_line( $t_version_info->version )
),
lang_get( 'delete_version_button' )
);

version_remove( $f_version_id );

Expand Down
9 changes: 6 additions & 3 deletions manage_user_delete.php
Expand Up @@ -56,9 +56,12 @@
$f_user_id = gpc_get_int( 'user_id' );

$t_user = user_get_row( $f_user_id );
helper_ensure_confirmed( lang_get( 'delete_account_sure_msg' ) .
'<br />' . lang_get( 'username_label' ) . lang_get( 'word_separator' ) . string_attribute( $t_user['username'] ),
lang_get( 'delete_account_button' ) );
helper_ensure_confirmed(
sprintf( lang_get( 'delete_account_sure_msg' ),
string_attribute( $t_user['username'] )
),
lang_get( 'delete_account_button' )
);

# If an administrator is trying to delete their own account, use
# account_delete.php instead as it is handles logging out and redirection
Expand Down
10 changes: 7 additions & 3 deletions manage_user_proj_delete.php
Expand Up @@ -64,9 +64,13 @@
$t_project_name = project_get_name( $f_project_id );

# Confirm with the user
helper_ensure_confirmed( lang_get( 'remove_user_sure_msg' ) .
'<br />' . lang_get( 'project_name_label' ) . lang_get( 'word_separator' ) . string_attribute( $t_project_name ),
lang_get( 'remove_user_button' ) );
helper_ensure_confirmed(
sprintf( lang_get( 'remove_user_sure_msg' ),
string_attribute( user_get_name( $f_user_id ) ),
string_attribute( $t_project_name )
),
lang_get( 'remove_user_button' )
);

project_remove_user( $f_project_id, $f_user_id );

Expand Down
9 changes: 6 additions & 3 deletions proj_doc_delete.php
Expand Up @@ -67,9 +67,12 @@
$t_title = db_result( $t_result );

# Confirm with the user
helper_ensure_confirmed( lang_get( 'confirm_file_delete_msg' ) .
'<br />' . lang_get( 'filename_label' ) . lang_get( 'word_separator' ) . string_display_line( $t_title ),
lang_get( 'file_delete_button' ) );
helper_ensure_confirmed(
sprintf( lang_get( 'confirm_file_delete_msg' ),
string_display_line( $t_title )
),
lang_get( 'file_delete_button' )
);

file_delete( $f_file_id, 'project' );

Expand Down

0 comments on commit 6c3482d

Please sign in to comment.