| 1 |
<?php |
<?php |
| 2 |
// $Id: $ |
// $Id: live_translation.update.inc,v 1.1 2009/04/19 02:35:51 brmassa Exp $ |
| 3 |
/** |
/** |
| 4 |
* @author Bruno Massa |
* @author Bruno Massa |
| 5 |
* @file |
* @file |
| 30 |
$module, |
$module, |
| 31 |
$modules[$module]['info']['version'], |
$modules[$module]['info']['version'], |
| 32 |
$langcode, |
$langcode, |
| 33 |
// (isset($import_time[$langcode][$module])) ? $import_time[$langcode][$module] : 0 |
(isset($import_time[$langcode][$module])) ? $import_time[$langcode][$module] : 0 |
|
0 |
|
| 34 |
)); |
)); |
| 35 |
|
|
| 36 |
$filename = 'live_translation_import.po'; |
$filename = 'live_translation_import.po'; |
| 44 |
$message = t('File %file already exists.', array('%file' => $file)); |
$message = t('File %file already exists.', array('%file' => $file)); |
| 45 |
} |
} |
| 46 |
|
|
| 47 |
// Download the PO file from server and save it in the local filesystem. |
// Download the PO file from server |
| 48 |
elseif (!(($contents = drupal_http_request($file_url)) && file_put_contents($file, $contents->data))) { |
elseif (!$contents = drupal_http_request($file_url)) { |
| 49 |
$message = t('Unable to download and save %download_link file.', array('%download_link' => $file_url)); |
$message = t('Unable to download and save %download_link file.', array('%download_link' => $file_url)); |
| 50 |
|
$no_file = TRUE; |
| 51 |
} |
} |
| 52 |
|
|
| 53 |
|
// Check if there is any strings |
| 54 |
|
elseif ($contents->data == '') { |
| 55 |
|
$message = t('No new strings for %module.', array('%module' => $module)); |
| 56 |
|
$no_file = TRUE; |
| 57 |
|
$ok = TRUE; |
| 58 |
|
} |
| 59 |
|
|
| 60 |
|
// Save it in the local filesystem. |
| 61 |
|
elseif (!file_put_contents($file, $contents->data)) { |
| 62 |
|
$message = t('Unable to download and save %download_link file.', array('%download_link' => $file_url)); |
| 63 |
|
} |
| 64 |
|
|
| 65 |
|
|
| 66 |
// Extract and parse the local file and remove the tarball. |
// Extract and parse the local file and remove the tarball. |
| 67 |
else { |
else { |
| 68 |
include_once './includes/locale.inc'; |
include_once './includes/locale.inc'; |
|
|
|
| 69 |
// LOCALE_IMPORT_OVERWRITE |
// LOCALE_IMPORT_OVERWRITE |
| 70 |
// LOCALE_IMPORT_KEEP |
// LOCALE_IMPORT_KEEP |
| 71 |
$mode = LOCALE_IMPORT_OVERWRITE; |
$mode = LOCALE_IMPORT_OVERWRITE; |
| 102 |
} |
} |
| 103 |
|
|
| 104 |
// Delete the file |
// Delete the file |
| 105 |
unlink($file); |
if (empty($no_file)) { |
| 106 |
|
unlink($file); |
| 107 |
|
} |
| 108 |
} |
} |
| 109 |
|
|
| 110 |
/** |
/** |
| 120 |
$languages = language_list('enabled'); |
$languages = language_list('enabled'); |
| 121 |
$import_status = variable_get('live_translation_import_status', array()); |
$import_status = variable_get('live_translation_import_status', array()); |
| 122 |
$import_time = variable_get('live_translation_import_time', array()); |
$import_time = variable_get('live_translation_import_time', array()); |
|
$update_time = variable_get('live_translation_update_time', array()); |
|
| 123 |
|
|
| 124 |
foreach ($languages[1] as $langcode => $language) { |
foreach ($languages[1] as $langcode => $language) { |
| 125 |
if ($langcode == 'en' or _live_translation_servers($langcode) == '') { |
if ($langcode == 'en' or _live_translation_servers($langcode) == '') { |
| 127 |
} |
} |
| 128 |
foreach ($modules as $mod => $module) { |
foreach ($modules as $mod => $module) { |
| 129 |
$module_releases[$mod] = $module['info']['version']; |
$module_releases[$mod] = $module['info']['version']; |
|
$import_time_releases[$mod] = $import_time[$langcode][$mod]; |
|
| 130 |
} |
} |
| 131 |
|
|
| 132 |
$pending_translations = xmlrpc( |
$pending_translations = xmlrpc( |
| 133 |
_live_translation_servers($langcode) .'/xmlrpc.php', |
_live_translation_servers($langcode) .'/xmlrpc.php', |
| 134 |
'live_translation_update', |
'live_translation_update', |
| 135 |
$langcode, |
$langcode, |
| 136 |
$update_time_releases, |
$import_time[$langcode], |
| 137 |
$module_releases |
$module_releases |
| 138 |
); |
); |
| 139 |
|
|
| 144 |
drupal_set_message(xmlrpc_error_msg(), 'error'); |
drupal_set_message(xmlrpc_error_msg(), 'error'); |
| 145 |
} |
} |
| 146 |
else { |
else { |
| 147 |
|
$update_time = variable_get('live_translation_update_time', array()); |
| 148 |
|
watchdog('live_translation', 'Translation status updated to !langname', array('!langname' => $language->native), WATCHDOG_ERROR); |
| 149 |
|
drupal_set_message(t('Translation status updated to !langname', array('!langname' => $language->native))); |
| 150 |
|
|
| 151 |
foreach ($modules as $mod => $module) { |
foreach ($modules as $mod => $module) { |
| 152 |
$update_time[$langcode][$mod] = time() + LIVE_TRANSLATION_LIMIT; |
$update_time[$langcode][$mod] = time() + LIVE_TRANSLATION_LIMIT; |
| 153 |
$import_status[$langcode][$mod] = $pending_translations[$mod]; |
$import_status[$langcode][$mod] = $pending_translations[$mod]; |
| 154 |
} |
} |
| 155 |
|
|
| 156 |
watchdog('live_translation', 'Translation status updated to !langname', array('!langname' => $language->native), WATCHDOG_ERROR); |
// Update the status |
| 157 |
drupal_set_message(t('Translation status updated to !langname', array('!langname' => $language->native))); |
variable_set('live_translation_update_time', $update_time); |
| 158 |
|
variable_set('live_translation_import_status', $import_status); |
| 159 |
} |
} |
| 160 |
} |
} |
|
|
|
|
// Update the status |
|
|
variable_set('live_translation_update_time', $update_time); |
|
|
variable_set('live_translation_import_status', $import_status); |
|
| 161 |
} |
} |