Skip to content

Instantly share code, notes, and snippets.

@webflo
Last active July 14, 2016 14:50
Show Gist options
  • Save webflo/42e53d724c1bf6c98fd66e35f66a729a to your computer and use it in GitHub Desktop.
Save webflo/42e53d724c1bf6c98fd66e35f66a729a to your computer and use it in GitHub Desktop.
<?php
/**
* @file
* Custom drush commands.
*/
/**
* Implements hook_drush_command().
*
* @return array
*/
function translation_drush_command() {
$items['translation-import'] = array(
'description' => 'Import custom translations',
'arguments' => array(
'file' => 'The po file.',
),
'options' => array(
'language' => array(
'required' => TRUE,
),
'customized' => array(
'required' => TRUE,
),
),
'required-arguments' => TRUE,
);
return $items;
}
/**
* Import translations.
*/
function drush_translation_import($filepath) {
if (!file_exists($filepath)) {
drush_set_error('error', '*.po file not found.');
return;
}
$file = new stdClass();
$file->langcode = drush_get_option('language');
$file->uri = $filepath;
Drupal\locale\Gettext::fileToDatabase($file, ['customized' => (int) drush_get_option('customized')]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment