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?

  1. Should I do it in hook_update_N()?
  2. 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.

  • What did you end up doing? – Boy Baukema Mar 3 '16 at 8:24
  • @RelaXNow, I have not implement a solution yet. AFAICS import/export of user interface translation is not automated yet. I planned to go with a hook_update_N. Have a look at @Berdir's suggestion. – milkovsky Mar 7 '16 at 8:28
  • Do you know about the new Drupal Console and its command translation:sync? Unfortunately I can't find any detailed information about this command but maybe it does what you are looking for. – Philipp Michael May 30 '16 at 13:49
  • 1
    I rolled us a module for that: drupal.org/project/customtranslations Have fun. – geek-merlin Apr 1 '17 at 22:32
  • In our case we did a test with Potx (github.com/kgaut/drupal-potx) that is running only with Drush. To achieve this "easily" we did a .sh file who is executing the drush command to put translation file in modules/custom/translations for each module and each language. Then those file are added to the gitlab repository of the project and can be easily import in production during a deploy... – Promo Dec 18 '17 at 16:09

You have to do this yourself. @rpayanm answered where you can do it manually, you will need to look at the code there, and for example implement drush commands that allow you to export and import it again. Automating that is then relatively easy, export, sync it to the other server, and import again.

Looks like a project that helps with that exists: Drush Language Commands.

You can put default translations in a module ,but those are only imported when you install that module. hook_update_N() is designed to only run once, so you would need to write a new function every time you want to do it (and you still need to export it first).

| improve this answer | |

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->findString(['source' => $source_string]);
  if (is_null($string)) {
    $string = new SourceString();
  // Create translation. If one already exists, it will be replaced.
  $translation = $storage->createTranslation([
    'lid' => $string->lid,
    'language' => $langcode,
    'translation' => $translated_string,

Usage in an update hook:

 * Add translations.
function MYMODULE_update_8002() {
  MYMODULE_add_translation('Adjust', 'de', 'Anpassen');
| improve this answer | |

You can export the translated strings used by your site A (admin/config/regional/translate/export) and then import them on the other site (admin/config/regional/translate/import).

| improve this answer | |
  • 2
    Thx. I know this. But it is not an automatic deployment. I would like to automate this process with hook_update_N or drush cim -y. I will add this to the description. – milkovsky Mar 19 '15 at 16:01

For our project, we wrote a custom module with .po files in a subfolder. These are loaded by the Drupal 8 localization system using a few lines of code in the .info.yml.

'interface translation project': CUSTOM_MODULE
'interface translation server pattern': modules/custom/CUSTOM_MODULE/%project-%version.%language.po

See https://api.drupal.org/api/drupal/core%21modules%21locale%21locale.api.php/group/interface_translation_properties/8.2.x

| improve this answer | |

It looks like it should also be possible to do this by writing a script to run commands from Drush locale sync, although I haven't tried that module myself.

| improve this answer | |
  • 2
    please use comments for this, it's not really the answer... – mixerowsky Aug 2 '17 at 15:23
  • 1
    I wasn't sure if it was right or not, so I thought I should post it as an answer and let other people vote it up or down. Please vote down if you think its wrong. – bdsl Aug 2 '17 at 20:38

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.