2

I imported some translations using the locale update module but the translations are horrible and it would be better to revert to English.

How do I bulk delete all the imported translations in Drupal 8?

I found an issue on adding back the D7 translation string deletion option to the UI, but I want to mass delete all strings, not individual strings.

Drupal 7 version of this question

EDIT: Deleting the language is one approach, but I can't do that because I already have a lot of content translated into the language. I want to keep the content that I have translated into the language, but delete all the user interface strings that were imported through localization update.

3

If you intend to remove ALL strings imported through interface translation, you could execute something like this:

// Replace the empty string with your target language code.
$langcode = '';
\Drupal::database()
  ->delete('locales_target');
  ->condition('language', $langcode)
  ->condition('customized', 0)
  ->execute();

You may also want to reset the source file history information, so - if you change your mind afterwards - you can re-import the very same translations:

\Drupal::database()
  ->delete('locale_file')
  ->condition('language', $langcode)
  ->execute();

or

locale_translation_file_history_delete([], [$langcode]);

As the locale module is making heavy use of static caches, you may run above commands in a dedicated process as, e.g. Drush PHP CLI (drush php:cli).

1
  • Suggestion 1

if you want to get rid of all translations of a language, just delete the langauge in /admin/config/regional/language

  • Suggestion 2

    if there are some specific string you want to be not translated, Go to locales_source to identify those strings lids, then execute the following code (devel/php or custom hook_update_N or drush ev...)

    
$lids = [4, 5];
db_delete('locales_target')->condition('lid', $lids, 'IN')->execute();

hope this helps

  • Thanks! I don't want to delete the language because I have content translated into the language that I need to keep. I want to delete the interface translations for the language, but keep the content in the language. – Patrick Kenny Mar 1 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.