4

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 Answers 3

5

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 makes 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

1
  • 1
    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. Mar 1, 2019 at 10:46
1

I found http://web.archive.org/web/20230609014802/http://vaerenbergh.com/blog/drupal-8-reimport-all-translation-files the only solution that worked:

DELETE FROM key_value WHERE collection='locale.translation_status';
UPDATE locale_file SET timestamp = 0;
UPDATE locale_file SET last_checked = 0;

then

drush ev "\Drupal::state()->set('locale.translation_last_checked', 0);"
drush cr
drush locale-check && drush locale-update && drush cr

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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