Projet

Général

Profil

Révision 8c72e82a

Ajouté par Assos Assos il y a environ 7 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/i18n/i18n_string/i18n_string.pages.inc
170 170

  
171 171
/**
172 172
 * Create field elements for strings
173
 *
174
 * @param i18n_string_object[] $strings
175
 * @param string $langcode
176
 *
177
 * @return array
173 178
 */
174 179
function i18n_string_translate_page_form_strings($strings, $langcode) {
175
  $formats = filter_formats();
180
  global $user;
181
  $form = array();
176 182
  foreach ($strings as $item) {
177
    // We may have a source or not. Load it, our string may get the format from it.
178
    $source = $item->get_source();
179
    $format_id = $source ? $source->format : $item->format;
180
    $description = '';
181 183
    // Check permissions to translate this string, depends on format, etc..
182 184
    if ($message = $item->check_translate_access()) {
183 185
      // We'll display a disabled element with the reason it cannot be translated.
......
188 190
      $disabled = FALSE;
189 191
      $description = '';
190 192
      // If we don't have a source and it can be translated, we create it.
191
      if (!$source) {
193
      if (!$item->get_source()) {
192 194
        // Enable messages just as a reminder these strings are not being updated properly.
193 195
        $status = $item->update(array('messages' => TRUE));
194 196
        if ($status === FALSE || $status === SAVED_DELETED) {
195 197
          // We don't have a source string so nothing to translate here
196 198
          $disabled = TRUE;
197 199
        }
198
        else {
199
          $source = $item->get_source();
200
        }
201 200
      }
202 201
    }
203 202

  
204 203
    $default_value = $item->format_translation($langcode, array('langcode' => $langcode, 'sanitize' => FALSE, 'debug' => FALSE));
204
    $available_formats = array_keys(filter_formats($user));
205
    if (!in_array($item->format, $available_formats)) {
206
      $item->format = NULL;
207
    }
205 208
    $form[$item->get_name()] = array(
206 209
      '#title' => $item->get_title(),
207
      '#type' => 'textarea',
210
      '#type' => $item->format ? 'text_format' : 'textarea',
208 211
      '#default_value' => $default_value,
212
      '#format' => $item->format,
213
      // This will trigger i18n_string_pre_render_text_format() to actually
214
      // alter the element.
215
      '#i18n_string_is_translation' => TRUE,
209 216
      '#disabled' => $disabled,
210
      '#description' => $description . _i18n_string_translate_format_help($format_id),
211
      //'#i18n_string_format' => $source ? $source->format : 0,
217
      '#description' => $description,
212 218
      // If disabled, provide smaller textarea (that can be expanded anyway).
213 219
      '#rows' => $disabled ? 1 : min(ceil(str_word_count($default_value) / 12), 10),
214 220
      // Change the parent for disabled strings so we don't get empty values later
......
226 232
  foreach ($form_state['values']['strings'] as $name => $value) {
227 233
    $count++;
228 234
    list($textgroup, $context) = i18n_string_context(explode(':', $name));
235
    if (is_array($value)) {
236
      if (isset($value['value'])) {
237
        $value = $value['value'];
238
        $form_state['values']['strings'][$name] = $value;
239
      }
240
      else {
241
        form_set_error("strings][$name", t('Unable to get the translated string value.'));
242
        watchdog('locale', 'Unable to get the translated string value, string array is: %string', array('%string' => var_dump($value)), WATCHDOG_WARNING);
243
      }
244
    }
229 245
    $result = i18n_string_textgroup($textgroup)->update_translation($context, $form_state['values']['langcode'], $value);
230 246
    $success += ($result ? 1 : 0);
231 247
  }

Formats disponibles : Unified diff