Problem/Motivation

When user is on User Interface translation page then user is not able to see Delete string.

Original report
Hello, In D7 we had the option to edit and delete text strings in theme_locale_languages_overview_form

Now, in D8 we have the option to edit in-line, but where is the option to delete? (in TranslateEditForm)

Any alternative to deleting strings?

Thanks

Steps to reproduce

- Goto: Configuration -> User Interface Tranlsation
- Delete string is not appearing at right side.

Proposed resolution

Introduce Delete checkbox to delete the translation.
Once the checkbox is checked and the form is saved then it will delete the string.

Remaining tasks

Needs a Usability review.
Patch review
Commit

User interface changes

New checkbox will be added on string translation form.

After
Screenshot after patch in #25 (screenshot from #28)

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#59 2503893-59-fix-string-regression.patch6.12 KBptmkenny
#57 2503893-54.patch6.09 KBAshM
#53 2503893-53.patch6.09 KBk-l
#48 interdiff-2503893-45-48.txt1.21 KByogeshmpawar
#48 2503893-48.patch4.88 KByogeshmpawar
#45 reroll-interdiff-2503893-39-45.txt814 bytesmohit_aghera
#45 2503893-45.patch5.48 KBmohit_aghera
#44 Patch Fail 2503893.png418.01 KBchetanbharambe
#44 Before Patch 2503893.png334.56 KBchetanbharambe
#41 afterpatch.png69.95 KBRinku Jacob 13
#41 beforepatch.png63.51 KBRinku Jacob 13
#39 interdiff-2503893-36-39.txt2.31 KBmohit_aghera
#39 2503893-39.patch5.46 KBmohit_aghera
#36 interdiff_34-36.txt490 bytescolorfield
#36 2503893-36.patch3.16 KBcolorfield
#34 2503893-34.patch2.55 KBandypost
#34 interdiff.txt890 bytesandypost
#33 2503893-33.patch2.65 KBandypost
#33 interdiff.txt3.78 KBandypost
#28 delete_trans_feature.png31.49 KBhandkerchief
#25 2503893-translation-delete-source-string-25.patch3.5 KBjcisio
#4 source-delete-impossible-2503893-4.patch3.32 KBlegolasbo
delete_operations_in_TranslateEditForm-D8.png78.32 KBfacine
delete_operations_in_TranslateEditForm-D7.png91.28 KBfacine

Issue fork drupal-2503893

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Gábor Hojtsy’s picture

Title: delete operations in TranslateEditForm » Regression: not possible to delete source strings in Drupal 8 interface translation
Version: 8.1.x-dev » 8.0.x-dev
Component: translation.module » locale.module
Category: Support request » Bug report
Issue tags: -i18n +D8MI, +language-ui

Yeah I think that's an oversight. Not sure if it would be a good idea to integrate in this form but also not sure how to do it otherwise :/

facine’s picture

While there is no solution, if someone needs to clear a string ...

$lid = 8142;
db_delete('locales_source')
  ->condition('lid', $lid)
  ->execute();
db_delete('locales_target')
  ->condition('lid', $lid)
  ->execute();
Gábor Hojtsy’s picture

There are also other tables with location info for example to clear out. Also why did you specifically need to clear out strings?

legolasbo’s picture

Attached patch adds a checkbox to each row which allows the strings to be deleted and adds a deleteTranslationSource method to the LanguageManagerInterface and LanguageManager class.

It should probably be refactored to include a confirmation page to prevent accidental data destruction.

Gábor Hojtsy’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs screenshots

If we are to do this, we need screenshots, a confirmation form and tests. Also the UI needs to be made clear that not only the translation being seen is removed but all translations and the source string included.

Honestly I am not sure that the added UI shown on all string edit screens will be that valuable. You would barely use this UI to delete things. In fact why do you think its important to delete single strings? Drupal 8 core itself has over 8 thousand strings. Removing one or two would not make your site more performant or anything like that.

Gábor Hojtsy’s picture

Also, if a string is actually used somewhere it will show up as a source again (and if it was part of the project originally, it will get its translation update from localize.drupal.org as well), so practically restore itself soon always at least as a source and as translations too unless you actively disabled translation updates.

While I see this is a feature lost, it would be great to understand what do you want to use this feature for.

facine’s picture

@Gábor Hojtsy a module created me a string in the wrong language.

Gábor Hojtsy’s picture

@facine: so basically fixing bogus behavior in a module... we should discuss whether the constant UI elements added are worth for that edge case :)

penyaskito’s picture

I would be very tempted to Won't fix this one and let this feature emerge in contrib. What do you think, Gábor?

legolasbo’s picture

I've been thinking about this some more and I think both @Gábor and @penyaskito have a valid point.

Adding these UI elements is not an improvement visually, given the clean layout of the translation form and this functionality would only serve it's purpose in edge cases.
It is also really easy to implement this functionality in a contrib module. Therefor I would vote in favour of Won't fixing this issue.

legolasbo’s picture

Priority: Major » Normal

Also, I don't think this issue should be major.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jcisio’s picture

Re #6 actually I think this feature is useful to delete a string generated by an old version of a module (mostly custom module, because a contrib module has all strings of all released versions on l.d.o). While it won't help much in performance, it makes it possible to have 100% strings translated (without adding bogus translation), and search won't return a string which is never used.

Gábor Hojtsy’s picture

l.d.o serves version specific translations the same way for contrib and core, there is no difference, so outdated core strings may have the same problem as outdated contrib strings.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ptmkenny’s picture

I agree with @jcisio, having the ability to delete strings is a useful feature when working with a custom module. If you update the code of the module and change some strings, it's nice to be able to delete the originals to get the 100% translation.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Michelle’s picture

Adding another reason. I just ran into this because I discovered the translation was done wrong on a template and ended up adding a new source string for every term that has been searched on. I didn't see any way in the UI to clean it up so I went through and deleted all the junk from the PO file and imported only to find that doesn't work, either. Would be nice to have a way to bulk delete them all.

andypost’s picture

Having clean-up of outdated translation is separate issue

Having ability to delete could be useful for customized strings

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

handkerchief’s picture

Any news on this?

andypost’s picture

Version: 8.6.x-dev » 8.9.x-dev
Issue tags: +Needs reroll
handkerchief’s picture

@thx jcisio

I tested it with 8.7.7 and it works like a charm.

jcisio’s picture

Thanks handkerchief, it was a reroll of a 4 year old patch. Next time anyone tests could you post screenshots of the new feature please? This patch needs also tests in code.

handkerchief’s picture

FileSize
31.49 KB

Here's a screenshot. But I'm the wrong guy for tests (code).

/admin/config/regional/translate

delete trans feature

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

maxplus’s picture

Thanks, patch #25 is working great with 8.9.1.
It would be nice to have a "select all" checkbox like we have in a view using VBO, but for now it is very handy!

pameeela’s picture

Issue summary: View changes
Issue tags: -Needs screenshots

Added screenshot from #28 to IS so un-tagging.

Vivek Panicker’s picture

Since we are doing this, should we not replace db_delete in deleteTranslationSource() with call to Drupal database service as db_delete() is removed in Drupal 9?

andypost’s picture

andypost’s picture

A bit of clean-up, still NW for tests

pameeela’s picture

Issue tags: +Bug Smash Initiative
colorfield’s picture

Adds support for multiple delete. As deleteStrings() in StringDatabaseStorage can get multiple values returned by dbStringSelect(), dbDelete() needs to check its condition with the IN operator.
Still NW for tests.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

markus_petrux’s picture

Patch in #36 applied well on Drupal 8.9.7

mohit_aghera’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
5.46 KB
2.31 KB

Adding test cases to validate the following things:
- Presence of delete checkbox
- Deletion process.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Rinku Jacob 13’s picture

FileSize
63.51 KB
69.95 KB

Verified and tested patch#39 on the drupal 9.3.x-dev version. Patch applied successfully and looks good to me.thanks @mohit_aghera.Adding screenshot for the reference

quietone’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update, +Novice

@Rinku Jacob 13, thanks for the screenshots. They should be put into the Issue Summary. It helps anyone working on an issue if the Summary is always up to date.

Tagging for an issue summary update for having up to date screenshots in the IS and hopefully someone will add the template. Also tagging novice because the updates to the issue summary for this issue are straightforward.

chetanbharambe’s picture

Issue summary: View changes
chetanbharambe’s picture

Hi, @quietone,

Added the Issue summary.

Hi @Rinku Jacob 13
I have applied the #39 patch on the 9.3.x-dev version.
The patch is not applied successfully.

Steps to reproduce:
# Goto: Configuration -> User Interface Translation
# Delete string is not appearing on the right side.

Please refer attached screenshots for the same.
Needs to be re-roll to the patch.

mohit_aghera’s picture

Status: Needs work » Needs review
FileSize
5.48 KB
814 bytes

Re-roll for 9.3.x

andypost’s picture

andypost’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/locale/src/Form/TranslateEditForm.php
    @@ -47,6 +47,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    +        $this->t('Delete'),
    
    @@ -138,6 +139,11 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    +        $form['strings'][$string->lid]['delete'] = [
    +          '#type' => 'checkbox',
    +          '#title' => $this->t('Delete string'),
    +          '#title_display' => 'invisible',
    

    I think it needs better Label - kinda "Delete translation"

    Also the "Delete string" is disappointing as it will delete translation instead of source string

  2. +++ b/core/modules/locale/src/StringDatabaseStorage.php
    @@ -526,7 +526,7 @@ protected function dbStringUpdate($string) {
    -      $query->condition($field, $value);
    +      $query->condition($field, (array) $value, 'IN');
    

    that's changing behavior for key fields so will affect performance

    See #2031261: Make SQLite faster by combining multiple inserts and updates in a single query

yogeshmpawar’s picture

Status: Needs work » Needs review
FileSize
4.88 KB
1.21 KB

Addressed comments mentioned in #47 & added interdiff for reference.

quietone’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: -Needs issue summary update, -Novice +Needs usability review

I tested this on Drupal 9.3.x, standard install with a second language.

  1. Navigate to admin/config/regional/translate
  2. See the delete box on the right hand side
  3. Tick the box for 'account settings'
  4. Scroll to bottom
  5. The button text is 'Save translation'
  6. Click 'Save translation'
  7. Message "The strings have been saved."
  8. The source string and the translation 'account settings' are removed.

I did not expect to see 'save translation' as the button text when I am trying to delete something. There was no confirm screen for the deletion and after the delete operation the message is 'The strings have been saved'. I expect a button that is clearly a 'delete' and a confirm screen and then a confirmation telling me what I just deleted.

#47.1 points out that this deletes the string and the translation, it turns out that is how it behaves in Drupal 7. At least by my testing.

This needs more work on the user experience, tagging for a usability review to get direction.

I moved things around in the IS a bit for readability.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

D34dMan’s picture

Tested #48 on 9.3.16

Deleting a single item works as expected as experienced in #49. However when trying to delete multiple strings by selecting multiple checkbxoes, it throws following error,


Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not
                                                match number of tokens: DELETE FROM "locales_target"
                                                WHERE "li

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

k-l’s picture

Tested #48 on 9.4.9
Same experience as in #49 and same error as in #51.

Applied some changes to #48 patch:
- introduced separate `Delete translations` button that would handle just deletion. It appears when `delete` checkbox is checked. For now I didn't need confirmation step.
- fixed database error when deleting multiple strings.

Note: not sure if `testLocaleStringDelete()` test would pass.

a.sotirov’s picture

Tested #53 with php 8.1 and Drupal Core 9.5.4. Works perfectly both with single or multiple selections for delete.
RTBTC +1

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

DuneBL’s picture

Tested #53 with 9.5.9 and it works nicely

AshM’s picture

FileSize
6.09 KB

Same patch as #53 with a typo fixed.

ptmkenny’s picture

I re-rolled #57 and created an MR for work going forward. The patch is the current state of the MR.

Bohus Ulrych’s picture

FYI Patch #57 works with the latest Drupal 10.1.6

But #59 can't be applied, maybe works only with the latest core dev?
Drush error: Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2023-12-02/2503893-59-fix-string-reg...

ptmkenny’s picture

Patch #59 is for the 11.x-dev branch, because that's the current commit target. It should also work with Drupal 10.2.x, which will be out in a few days.