Skip to content

Instantly share code, notes, and snippets.

@guiajlopes
Created May 11, 2016 20:12
Show Gist options
  • Select an option

  • Save guiajlopes/f7f6628e566ba1759d24d55888696550 to your computer and use it in GitHub Desktop.

Select an option

Save guiajlopes/f7f6628e566ba1759d24d55888696550 to your computer and use it in GitHub Desktop.
<?php
/**
* Reloads translation file for a given module.
*
* @param mixed $module
* Module(s) name(s). An array of strings or a string.
* @param mixed $languages
* @return array
* An array with a "success" key which is a boolean and a "query" key which
* describes the SQL query executed. If additional sql parameters where
* given, a string "WITH PARAMETERS (param1, param2, ...)" is appended to
* the sql. It is compatible with hook_update and hook_install return values.
*/
function rcp_utils_locale_import_po($modules = array(), $langcodes = array(), $mode = LOCALE_IMPORT_KEEP, $group = 'default', $filename = '') {
$ret = array();
if (!is_array($modules)) {
$modules = array($modules);
}
if (!is_array($langcodes)) {
$langcodes = array($langcodes);
}
foreach ($modules as $module) {
foreach ($langcodes as $langcode) {
$file = new stdClass();
$file->filename = empty($filename) ? ($langcode . '.po') : ($filename . '.po');
$file->uri = drupal_get_path('module', $module) . '/translations/' . $file->filename;
$file->filemime = 'application/octet-stream';
$success = _locale_import_po($file, $langcode, $mode, $group);
$ret[] = array('success' => $success, 'query' => 'Reload ' . $module . ' translation file');
}
}
return $ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment