Projet

Général

Profil

Révision 503b3f7b

Ajouté par Assos Assos il y a environ 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/l10n_update/l10n_update.module
87 87
 */
88 88
function l10n_update_menu_alter(&$menu) {
89 89
  // Redirect l10n_client AJAX callback path for strings.
90
  $menu['l10n_client/save']['page callback'] = 'l10n_update_client_save_string';
90
  if (module_exists('l10n_client')) {
91
    $menu['l10n_client/save']['page callback'] = 'l10n_update_client_save_string';
92
  }
91 93
}
92 94

  
93 95
/**
......
96 98
 * Check one project/language at a time, download and import if update available
97 99
 */
98 100
function l10n_update_cron() {
99
  if ($frequency = variable_get('l10n_update_check_frequency', 0)) {
101
  $last = variable_get('l10n_update_last_check', 0);
102
  $frequency = variable_get('l10n_update_check_frequency', 0) * 24 *3600;
103
  if ($frequency && $last < REQUEST_TIME - $frequency) {
100 104
    module_load_include('check.inc', 'l10n_update');
101
    list($checked, $updated) = l10n_update_check_translations(L10N_UPDATE_CRON_PROJECTS, REQUEST_TIME - $frequency * 24 * 3600, L10N_UPDATE_CRON_UPDATES);
102
    watchdog('l10n_update', 'Automatically checked @checked translations, updated @updated.', array('@checked' => count($checked), '@updated' => count($updated)));
105
    list($checked, $updated) = l10n_update_check_translations(L10N_UPDATE_CRON_PROJECTS, REQUEST_TIME - $frequency, L10N_UPDATE_CRON_UPDATES);
106
    if (count($checked) || count($updated)) {
107
      watchdog('l10n_update', 'Automatically checked @checked translations, updated @updated.', array('@checked' => count($checked), '@updated' => count($updated)));
108
    }
109
    variable_set('l10n_update_last_check', REQUEST_TIME);
103 110
  }
104 111
}
105 112

  
......
109 116
function l10n_update_form_alter(&$form, $form_state, $form_id) {
110 117
  switch ($form_id) {
111 118
    case 'locale_translate_edit_form':
112
      // Replace the submit callback by our own customized version
113
      $form['#submit'] = array('l10n_update_locale_translate_edit_form_submit');
119
    case 'i18n_string_locale_translate_edit_form':
120
      $form['#submit'][] = 'l10n_update_locale_translate_edit_form_submit';
114 121
      break;
115 122
    case 'locale_languages_predefined_form':
116 123
    case 'locale_languages_custom_form':
......
177 184
}
178 185

  
179 186
/**
180
 * Replacement submit handler for translation edit form.
187
 * Additional submit handler for locale and i18n_string translation edit form.
181 188
 *
182
 * Process string editing form submissions marking translations as customized.
183
 * Saves all translations of one string submitted from a form.
189
 * Mark locally edited translations as customized.
184 190
 *
185 191
 * @see l10n_update_form_alter()
186
 * @todo Just mark as customized when string changed.
187 192
 */
188 193
function l10n_update_locale_translate_edit_form_submit($form, &$form_state) {
189 194
  module_load_include('inc', 'l10n_update');
190 195
  $lid = $form_state['values']['lid'];
191
  foreach ($form_state['values']['translations'] as $key => $value) {
192
    $translation = db_query("SELECT translation FROM {locales_target} WHERE lid = :lid AND language = :language", array(':lid' => $lid, ':language' => $key))->fetchField();
193
    if (!empty($value)) {
194
      // Only update or insert if we have a value to use.
195
      if (!empty($translation)) {
196
        db_update('locales_target')
197
          ->fields(array(
198
            'translation' => $value,
199
            'l10n_status' => L10N_UPDATE_STRING_CUSTOM,
200
          ))
201
          ->condition('lid', $lid)
202
          ->condition('language', $key)
203
          ->execute();
204
      }
205
      else {
206
        db_insert('locales_target')
207
          ->fields(array(
208
            'lid' => $lid,
209
            'translation' => $value,
210
            'language' => $key,
211
            'l10n_status' => L10N_UPDATE_STRING_CUSTOM,
212
          ))
213
          ->execute();
214
      }
215
    }
216
    elseif (!empty($translation)) {
217
      // Empty translation entered: remove existing entry from database.
218
      db_delete('locales_target')
196
  foreach ($form_state['values']['translations'] as $langcode => $value) {
197
    if (!empty($value) && $value != $form_state['complete form']['translations'][$langcode]['#default_value']) {
198
      // An update has been made, mark the string as customized.
199
      db_update('locales_target')
200
        ->fields(array('l10n_status' => L10N_UPDATE_STRING_CUSTOM))
219 201
        ->condition('lid', $lid)
220
        ->condition('language', $key)
202
        ->condition('language', $langcode)
221 203
        ->execute();
222 204
    }
223

  
224
    // Force JavaScript translation file recreation for this language.
225
    _locale_invalidate_js($key);
226 205
  }
206
}
227 207

  
228
  drupal_set_message(t('The string has been saved.'));
229

  
230
  // Clear locale cache.
231
  _locale_invalidate_js();
232
  cache_clear_all('locale:', 'cache', TRUE);
208
/**
209
 * Implements hook_stream_wrappers().
210
 *
211
 * Add a stream wrapper. The wrapper is not used in 7.x-1.x but is required to
212
 * make upgrade to 7.x-2.x painless.
213
 */
214
function l10n_update_stream_wrappers() {
215
  $wrappers['translations'] = array(
216
    'name' => t('Translation files'),
217
    'class' => 'TranslationsStreamWrapper',
218
    'description' => t('Translation files.'),
219
    'type' => STREAM_WRAPPERS_LOCAL_HIDDEN,
220
  );
233 221

  
234
  $form_state['redirect'] = 'admin/config/regional/translate/translate';
235
  return;
222
  return $wrappers;
236 223
}
237 224

  
238 225
/**
......
246 233
      // Ensure we have this source string before we attempt to save it.
247 234
      // @todo: add actual context support.
248 235
      $lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = :context AND textgroup = :textgroup", array(':source' => $_POST['source'], ':context' => '', ':textgroup' => $_POST['textgroup']))->fetchField();
249
      
236

  
250 237
      if (!empty($lid)) {
251 238
        module_load_include('inc', 'l10n_update');
252 239
        $report = array('skips' => 0, 'additions' => 0, 'updates' => 0, 'deletes' => 0);

Formats disponibles : Unified diff