How can I deploy user interface translation? Strings that I translate at "User interface translation" /admin/config/regional/translate are not exportable by "Configuration management" /admin/config/development/configuration for me. Am I missing something?

I would like to automate this process with hook_update_N or drush cim -y.

What is a proper way to automatically deploy "User interface translation" in Drupal 8?


Should I do it in hook_update_N()?
Should I create some custom mytranslations.po file in the language folder?


I see there is locale_translate_batch_import_files() which might be used.
Helper function to add custom translations:

/**
 * Helper to manually add a single translation string.
 *
 * @param string $source_string
 *   Source string.
 * @param string $langcode
 *   The langcode.
 * @param string $translated_string
 *   Translated string.
 */
function MYMODULE_add_translation($source_string, $langcode, $translated_string) {
  // Find existing source string.
  $storage = \Drupal::service('locale.storage');
  $string = $storage-&gt;findString(['source' =&gt; $source_string]);
  if (is_null($string)) {
    $string = new SourceString();
    $string-&gt;setString($source_string);
    $string-&gt;setStorage($storage);
    $string-&gt;save();
  }
  // Create translation. If one already exists, it will be replaced.
  $translation = $storage-&gt;createTranslation([
    'lid' =&gt; $string-&gt;lid,
    'language' =&gt; $langcode,
    'translation' =&gt; $translated_string,
  ]);
  $translation-&gt;save();
}


Usage in an update hook:

/**
 * Add translations.
 */
function MYMODULE_update_8002() {
  MYMODULE_add_translation('Adjust', 'de', 'Anpassen');
}