Import Drupal module translation .po files on installation


 * Helper function to (re)import all module's translations.
 * @param $module_name (string)
 *   - Machine name of the module.
function _ys_module_import_translations($module_name) {
  require_once 'includes/';
  $languages = language_list();

  // Try to allocate enough time to parse and import the data.

  foreach (file_scan_directory(drupal_get_path('module', $module_name), '/.*\.po/') as $file) {
    $langcode = @end(explode('.', $file-&gt;name));

    // Get strings from file (returns on failure after a partial import, or on success)
    $status = _locale_import_read_po('db-store', $file, LOCALE_IMPORT_OVERWRITE, $langcode);
    if ($status === FALSE) {
      // Error messages are set in _locale_import_read_po().

    // Get status information on import process.
    list($headerdone, $additions, $updates, $deletes, $skips) = _locale_import_one_string('db-report');

    if (!$headerdone) {
      drupal_set_message(t('The translation file %filename appears to have a missing or malformed header.', array('%filename' =&gt; $file-&gt;filename)), 'error');

    drupal_set_message(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' =&gt; $additions, '%update' =&gt; $updates, '%delete' =&gt; $deletes)));
    watchdog('locale', 'Imported %file into %locale: %number new strings added, %update updated and %delete removed.', array('%file' =&gt; $file-&gt;filename, '%locale' =&gt; $langcode, '%number' =&gt; $additions, '%update' =&gt; $updates, '%delete' =&gt; $deletes));

    if ($skips) {
      $skip_message = format_plural($skips, 'One translation string was skipped because it contains disallowed HTML.', '@count translation strings were skipped because they contain disallowed HTML.');
      watchdog('locale', $skip_message, NULL, WATCHDOG_WARNING);

  // Clear cache and force refresh of JavaScript translations.
  cache_clear_all('locale:', 'cache', TRUE);

  // Rebuild the menu, strings may have changed.


Reactie toevoegen

Plaats hier uw naam.