Completed
Pull Request — master (#1808)
by Christian
11:08
created
drupal/sites/default/boinc/modules/boinctranslate/boinctranslate.module 2 patches
Indentation   +682 added lines, -682 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
  * with defined URL paths
29 29
  */
30 30
 function boinctranslate_menu() {
31
-  $items['admin/boinc/translation'] = array(
31
+    $items['admin/boinc/translation'] = array(
32 32
     'title' => 'Environment: Translation',
33 33
     'description' => 'Configure URLs for translation files (i.e. integration
34 34
       with BOINC Translation Services).',
@@ -37,38 +37,38 @@  discard block
 block discarded – undo
37 37
     'access arguments' => array('administer site configuration'),
38 38
     'type' => MENU_NORMAL_ITEM,
39 39
     'file' => 'boinctranslate.admin.inc'
40
-  );
41
-  $items['admin/boinc/translation/export'] = array(
40
+    );
41
+    $items['admin/boinc/translation/export'] = array(
42 42
     'title' => 'Export translations',
43 43
     'page callback' => 'boinctranslate_export_translations',
44 44
     'access arguments' => array('administer site configuration'),
45 45
     'type' => MENU_CALLBACK,
46
-  );
47
-  $items['admin/boinc/translation/import'] = array(
46
+    );
47
+    $items['admin/boinc/translation/import'] = array(
48 48
     'title' => 'Import translations',
49 49
     'page callback' => 'boinctranslate_refresh_translations',
50 50
     'access arguments' => array('administer site configuration'),
51 51
     'type' => MENU_CALLBACK,
52
-  );
53
-  $items['admin/boinc/translation/initialize-languages'] = array(
52
+    );
53
+    $items['admin/boinc/translation/initialize-languages'] = array(
54 54
     'title' => 'Install official BOINC languages',
55 55
     'page callback' => 'boinctranslate_initialize_languages',
56 56
     'access arguments' => array('administer site configuration'),
57 57
     'type' => MENU_CALLBACK,
58
-  );
59
-  $items['admin/boinc/translation/update-official-boinc'] = array(
58
+    );
59
+    $items['admin/boinc/translation/update-official-boinc'] = array(
60 60
     'title' => 'Update official BOINC translations',
61 61
     'page callback' => 'boinctranslate_update_official_boinc_translations',
62 62
     'access arguments' => array('update official BOINC translations'),
63 63
     'type' => MENU_CALLBACK,
64
-  );
65
-  $items['admin/boinc/translation/download-pot'] = array(
64
+    );
65
+    $items['admin/boinc/translation/download-pot'] = array(
66 66
     'title' => 'Download translation template',
67 67
     'page callback' => 'boinctranslate_download_pot',
68 68
     'access arguments' => array('administer site configuration'),
69 69
     'type' => MENU_CALLBACK,
70
-  );
71
-  return $items;
70
+    );
71
+    return $items;
72 72
 }
73 73
 
74 74
 /**
@@ -76,18 +76,18 @@  discard block
 block discarded – undo
76 76
  * Obsolete in Drupal 7...
77 77
  */
78 78
 function boinctranslate_nodeapi(&$node, $op, $a3 = null, $a4 = null) {
79
-  // In Drupal 7, these operation cases will all exist as their own hooks,
80
-  // so let's approximate that here so that this function can simply be removed
81
-  // upon migration to 7
82
-  switch($op) {
83
-  case 'update':
79
+    // In Drupal 7, these operation cases will all exist as their own hooks,
80
+    // so let's approximate that here so that this function can simply be removed
81
+    // upon migration to 7
82
+    switch($op) {
83
+    case 'update':
84 84
     boinctranslate_node_update($node);
85 85
     break;
86
-  case 'view':
86
+    case 'view':
87 87
     global $language;
88 88
     boinctranslate_node_view($node, 'full', $language->language);
89 89
     break;
90
-  default:
90
+    default:
91 91
   }
92 92
 }
93 93
 
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
  * is updated (forward compatible to Drupal 7)
97 97
  */
98 98
 function boinctranslate_node_update($node) {
99
-  switch($node->type) {
100
-  case 'page':
99
+    switch($node->type) {
100
+    case 'page':
101 101
     // Add page content to translation table
102 102
     $textgroup = 'project';
103 103
     $location = "node:{$node->nid}:body";
@@ -105,62 +105,62 @@  discard block
 block discarded – undo
105 105
     $lid = db_result(db_query("
106 106
       SELECT lid FROM {locales_source}
107 107
       WHERE location = '%s' AND textgroup = '%s'",
108
-      $location, $textgroup
108
+        $location, $textgroup
109 109
     ));
110 110
     if ($lid) {
111
-      $result = db_query("
111
+        $result = db_query("
112 112
         UPDATE {locales_source}
113 113
         SET source = '%s'
114 114
         WHERE lid = %d",
115 115
         $node->body, $lid
116
-      );
117
-      if ($result) {
116
+        );
117
+        if ($result) {
118 118
         watchdog(
119
-          'boinctranslate',
120
-          'Updated translation source strings for node @nid.',
121
-          array('@nid' => $node->nid)
119
+            'boinctranslate',
120
+            'Updated translation source strings for node @nid.',
121
+            array('@nid' => $node->nid)
122 122
         );
123
-      }
124
-      else {
123
+        }
124
+        else {
125 125
         drupal_set_message(
126
-          t('Unable to update translation source strings.'), 'error'
126
+            t('Unable to update translation source strings.'), 'error'
127 127
         );
128 128
         watchdog(
129
-          'boinctranslate',
130
-          'Unable to update translation source strings for node @nid.',
131
-          array('@nid' => $node->nid),
132
-          WATCHDOG_ERROR
129
+            'boinctranslate',
130
+            'Unable to update translation source strings for node @nid.',
131
+            array('@nid' => $node->nid),
132
+            WATCHDOG_ERROR
133 133
         );
134
-      }
134
+        }
135 135
     }
136 136
     else {
137
-      $result = db_query("
137
+        $result = db_query("
138 138
         INSERT INTO {locales_source}
139 139
         SET location = '%s', textgroup = '%s', source = '%s'",
140 140
         $location, $textgroup, $node->body
141
-      );
142
-      if ($result) {
141
+        );
142
+        if ($result) {
143 143
         watchdog(
144
-          'boinctranslate',
145
-          'Added translation source strings for node @nid.',
146
-          array('@nid' => $node->nid)
144
+            'boinctranslate',
145
+            'Added translation source strings for node @nid.',
146
+            array('@nid' => $node->nid)
147 147
         );
148
-      }
149
-      else {
148
+        }
149
+        else {
150 150
         drupal_set_message(
151
-          t('Unable to add translation source strings.'), 'error'
151
+            t('Unable to add translation source strings.'), 'error'
152 152
         );
153 153
         watchdog(
154
-          'boinctranslate',
155
-          'Unable to add translation source strings for node @nid.',
156
-          array('@nid' => $node->nid),
157
-          WATCHDOG_ERROR
154
+            'boinctranslate',
155
+            'Unable to add translation source strings for node @nid.',
156
+            array('@nid' => $node->nid),
157
+            WATCHDOG_ERROR
158 158
         );
159
-      }
159
+        }
160 160
     }
161 161
     break;
162 162
     
163
-  default:
163
+    default:
164 164
     
165 165
   }
166 166
 }
@@ -170,14 +170,14 @@  discard block
 block discarded – undo
170 170
  * is viewed (forward compatible to Drupal 7)
171 171
  */
172 172
 function boinctranslate_node_view($node, $view_mode, $langcode) {
173
-  switch($node->type) {
174
-  case 'page':
173
+    switch($node->type) {
174
+    case 'page':
175 175
     // Replace the node body with translated content, if available
176 176
     $node->content['body']['#value'] = bts(
177
-      $node->body, array(), $langcode, "project:node:{$node->nid}:body", FALSE
177
+        $node->body, array(), $langcode, "project:node:{$node->nid}:body", FALSE
178 178
     );
179 179
     break;
180
-  default:
180
+    default:
181 181
   }
182 182
 }
183 183
 
@@ -187,17 +187,17 @@  discard block
 block discarded – undo
187 187
  * This workaround makes panel page titles and pane titles translatable
188 188
  */
189 189
 function boinctranslate_panels_pane_content_alter($content, $pane, $args, $context) {
190
-  if ($content->title) {
190
+    if ($content->title) {
191 191
     $content->title = t($content->title);
192
-  }
193
-  return $content;
192
+    }
193
+    return $content;
194 194
 }
195 195
 
196 196
 /**
197 197
  * Implementation of hook_perm()
198 198
  */
199 199
 function boinctranslate_perm() {
200
-  return array('update official BOINC translations');
200
+    return array('update official BOINC translations');
201 201
 }
202 202
 
203 203
 /*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
@@ -209,30 +209,30 @@  discard block
 block discarded – undo
209 209
  */
210 210
 function boinctranslate_initialize_languages() {
211 211
 
212
-  require_once(getcwd() . '/includes/locale.inc');
212
+    require_once(getcwd() . '/includes/locale.inc');
213 213
   
214
-  $api_base_url = 'https://www.transifex.com/api/2';
215
-  $project_name = variable_get(
214
+    $api_base_url = 'https://www.transifex.com/api/2';
215
+    $project_name = variable_get(
216 216
     'boinc_translate_transifex_project_name', ''
217
-  );
218
-  $operations = array();
217
+    );
218
+    $operations = array();
219 219
   
220
-  if ($project_name) {
220
+    if ($project_name) {
221 221
     // Get all languages configured for this project at Transifex
222 222
     $path = "project/{$project_name}/languages";
223 223
     $response = boinctranslate_transifex_request($path);
224 224
     
225 225
     if ($response == '404 NOT FOUND') {
226
-      drupal_set_message(
226
+        drupal_set_message(
227 227
         t('Unable to get languages for %project.',
228
-          array(
228
+            array(
229 229
             '%project' => $project_name,
230
-          )
230
+            )
231 231
         ), 'warning'
232
-      );
232
+        );
233 233
     }
234 234
     elseif ($response) {
235
-      if (is_array($response)) {
235
+        if (is_array($response)) {
236 236
       
237 237
         $installed_languages = language_list();
238 238
         $available_languages = _locale_get_predefined_list();
@@ -242,13 +242,13 @@  discard block
 block discarded – undo
242 242
         
243 243
         // Set up Transifex languages in Drupal
244 244
         foreach ($response as $language) {
245
-          $posix_code = $language['language_code'];
246
-          $rfc_code = strtolower(str_replace('_', '-', $posix_code));
247
-          $transifex_languages[$rfc_code] = $language;
248
-          if (!isset($installed_languages[$rfc_code])) {
245
+            $posix_code = $language['language_code'];
246
+            $rfc_code = strtolower(str_replace('_', '-', $posix_code));
247
+            $transifex_languages[$rfc_code] = $language;
248
+            if (!isset($installed_languages[$rfc_code])) {
249 249
             // See if this language can be installed from a predefined list
250 250
             if (isset($available_languages[$rfc_code])) {
251
-              locale_add_language(
251
+                locale_add_language(
252 252
                 $rfc_code,
253 253
                 NULL,
254 254
                 NULL,
@@ -256,30 +256,30 @@  discard block
 block discarded – undo
256 256
                 NULL,
257 257
                 NULL,
258 258
                 FALSE
259
-              );
260
-              drupal_set_message(
259
+                );
260
+                drupal_set_message(
261 261
                 'Added predefined language: '.$available_languages[$rfc_code][0]
262
-              );
263
-              db_query("UPDATE {languages} SET enabled = 1 WHERE language = '%s'", $rfc_code);
262
+                );
263
+                db_query("UPDATE {languages} SET enabled = 1 WHERE language = '%s'", $rfc_code);
264 264
             }
265 265
             else {
266
-              // Retrieve language details from Transifex
267
-              $path = "language/{$posix_code}";
268
-              $response = boinctranslate_transifex_request($path);
266
+                // Retrieve language details from Transifex
267
+                $path = "language/{$posix_code}";
268
+                $response = boinctranslate_transifex_request($path);
269 269
               
270
-              if ($response == '404 NOT FOUND') {
270
+                if ($response == '404 NOT FOUND') {
271 271
                 drupal_set_message(
272
-                  t('Unable to get details for language %code.',
272
+                    t('Unable to get details for language %code.',
273 273
                     array(
274
-                      '%code' => $posix_code,
274
+                        '%code' => $posix_code,
275 275
                     )
276
-                  ), 'warning'
276
+                    ), 'warning'
277 277
                 );
278
-              }
279
-              elseif ($response) {
278
+                }
279
+                elseif ($response) {
280 280
                 if (!empty($response['name'])) {
281
-                  // Add a custom language to Drupal and enable
282
-                  locale_add_language(
281
+                    // Add a custom language to Drupal and enable
282
+                    locale_add_language(
283 283
                     $rfc_code,
284 284
                     $response['name'],
285 285
                     $response['name'],
@@ -287,362 +287,362 @@  discard block
 block discarded – undo
287 287
                     NULL,
288 288
                     NULL,
289 289
                     TRUE
290
-                  );
291
-                  drupal_set_message(
290
+                    );
291
+                    drupal_set_message(
292 292
                     'Added new language: '.$response['name']
293
-                  );
293
+                    );
294 294
                 }
295 295
                 else {
296
-                  $variables = array(
296
+                    $variables = array(
297 297
                     '%code' => $posix_code,
298
-                  );
299
-                  drupal_set_message(
298
+                    );
299
+                    drupal_set_message(
300 300
                     t('Unable to get details for language %code.', $variables),
301 301
                     'error'
302
-                  );
303
-                  watchdog(
302
+                    );
303
+                    watchdog(
304 304
                     'boinctranslate',
305 305
                     'Unable to get details for language %code.',
306 306
                     $variables,
307 307
                     WATCHDOG_ERROR
308
-                  );
308
+                    );
309
+                }
309 310
                 }
310
-              }
311
-              else {
312
-               $variables = array(
313
-                  '%code' => $posix_code,
311
+                else {
312
+                $variables = array(
313
+                    '%code' => $posix_code,
314 314
                 );
315 315
                 drupal_set_message(
316
-                  t('Invalid response while getting details for language %code.', $variables),
317
-                  'error'
316
+                    t('Invalid response while getting details for language %code.', $variables),
317
+                    'error'
318 318
                 );
319 319
                 watchdog(
320
-                  'boinctranslate',
321
-                  'Invalid response while getting details for language %code.',
322
-                  $variables,
323
-                  WATCHDOG_ERROR
320
+                    'boinctranslate',
321
+                    'Invalid response while getting details for language %code.',
322
+                    $variables,
323
+                    WATCHDOG_ERROR
324 324
                 );
325
-              }
325
+                }
326 326
             }
327 327
             // Import any language files for the newly added language
328 328
             if ($batch = locale_batch_by_language($rfc_code, '_locale_batch_language_finished')) {
329
-              $operations = array_merge($operations, $batch['operations']);
330
-              $process_batches = TRUE;
329
+                $operations = array_merge($operations, $batch['operations']);
330
+                $process_batches = TRUE;
331
+            }
331 332
             }
332
-          }
333 333
         }
334 334
         drupal_set_message('Finished installing official BOINC languages.');
335 335
         // Disable languages that are not in Transifex
336 336
         foreach ($installed_languages as $langcode => $language) {
337
-          if (!isset($transifex_languages[$langcode])) {
337
+            if (!isset($transifex_languages[$langcode])) {
338 338
             $disabled_languages[$langcode] = $langcode;
339 339
             db_query("UPDATE {languages} SET enabled = 0 WHERE language = '%s'", $langcode);
340
-          }
340
+            }
341 341
         }
342 342
         if ($disabled_languages) {
343
-          drupal_set_message('The following languages were not found in Transifex and were disabled: ' . implode(' ', $disabled_languages));
343
+            drupal_set_message('The following languages were not found in Transifex and were disabled: ' . implode(' ', $disabled_languages));
344 344
         }
345 345
         if ($process_batches) {
346
-          $batch = array(
346
+            $batch = array(
347 347
             'operations' => $operations,
348
-          );
349
-          batch_set($batch);
350
-          batch_process('admin/boinc/translation');
348
+            );
349
+            batch_set($batch);
350
+            batch_process('admin/boinc/translation');
351
+        }
351 352
         }
352
-      }
353
-      else {
353
+        else {
354 354
         $variables = array(
355
-          '%project' => $project_name,
355
+            '%project' => $project_name,
356 356
         );
357 357
         drupal_set_message(
358
-          t('No languages found for %project. (Does the configured account have sufficient privileges at Transifex?)', $variables),
359
-          'error'
358
+            t('No languages found for %project. (Does the configured account have sufficient privileges at Transifex?)', $variables),
359
+            'error'
360 360
         );
361 361
         watchdog(
362
-          'boinctranslate',
363
-          'No languages found for %project. (Does the configured account have sufficient privileges at Transifex?)',
364
-          $variables,
365
-          WATCHDOG_ERROR
362
+            'boinctranslate',
363
+            'No languages found for %project. (Does the configured account have sufficient privileges at Transifex?)',
364
+            $variables,
365
+            WATCHDOG_ERROR
366 366
         );
367
-      }
367
+        }
368 368
     }
369 369
     else {
370
-     $variables = array(
370
+        $variables = array(
371 371
         '%project' => $project_name,
372
-      );
373
-      drupal_set_message(
372
+        );
373
+        drupal_set_message(
374 374
         t('Invalid response while getting languages for %project.', $variables),
375 375
         'error'
376
-      );
377
-      watchdog(
376
+        );
377
+        watchdog(
378 378
         'boinctranslate',
379 379
         'Invalid response while getting languages for %project.',
380 380
         $variables,
381 381
         WATCHDOG_ERROR
382
-      );
382
+        );
383 383
     }
384
-  }
385
-  drupal_goto('admin/boinc/translation');
384
+    }
385
+    drupal_goto('admin/boinc/translation');
386 386
 }
387 387
 
388 388
 /**
389 389
  *
390 390
  */
391 391
 function boinctranslate_export_translations() {
392
-  require_once(getcwd() . '/includes/locale.inc');
393
-  $project_name = variable_get(
392
+    require_once(getcwd() . '/includes/locale.inc');
393
+    $project_name = variable_get(
394 394
     'boinc_translate_transifex_project_name', ''
395
-  );
396
-  // Get resource names from local config
397
-  $resource_config = (variable_get(
395
+    );
396
+    // Get resource names from local config
397
+    $resource_config = (variable_get(
398 398
     'boinc_translate_transifex_project_resources', ''
399
-  ));
400
-  $resource_names = boinctranslate_parse_resources($resource_config);
401
-  $primary_resource = reset($resource_names);
399
+    ));
400
+    $resource_names = boinctranslate_parse_resources($resource_config);
401
+    $primary_resource = reset($resource_names);
402 402
   
403
-  if ($project_name AND $primary_resource) {
403
+    if ($project_name AND $primary_resource) {
404 404
     // Create or update the translation source, if needed
405 405
     $source_exists = FALSE;
406 406
     $path = "project/{$project_name}/resources";
407 407
     $resources = boinctranslate_transifex_request($path);
408 408
     if ($resources AND is_array($resources)) {
409
-      foreach ($resources as $resource) {
409
+        foreach ($resources as $resource) {
410 410
         if ($resource['slug'] == $primary_resource) {
411
-          $source_exists = TRUE;
412
-          break;
411
+            $source_exists = TRUE;
412
+            break;
413 413
         }
414
-      }
415
-      if (!$source_exists) {
414
+        }
415
+        if (!$source_exists) {
416 416
         // Create the source
417 417
         $path = "project/{$project_name}/resources";
418 418
         $post = array(
419
-          'slug' => $primary_resource,
420
-          'name' => 'Drupal-Project',
421
-          'i18n_type' => 'PO',
422
-          'category' => 'Drupal',
423
-          'content' => boinctranslate_get_po('en', 'project'),
419
+            'slug' => $primary_resource,
420
+            'name' => 'Drupal-Project',
421
+            'i18n_type' => 'PO',
422
+            'category' => 'Drupal',
423
+            'content' => boinctranslate_get_po('en', 'project'),
424 424
         );
425 425
         $result = boinctranslate_transifex_request($path, $post);
426
-      }
427
-      else {
426
+        }
427
+        else {
428 428
         // Update the source
429 429
         $path = "project/{$project_name}/resource/{$primary_resource}/content";
430 430
         $post = array(
431
-          'content' => boinctranslate_get_po('en', 'project')
431
+            'content' => boinctranslate_get_po('en', 'project')
432 432
         );
433 433
         $result = boinctranslate_transifex_request($path, $post, TRUE, TRUE);
434
-      }
434
+        }
435 435
     }
436 436
     
437 437
     if (is_array($result) OR substr($result, 0, 6) != 'ERROR:') {
438
-      $enabled_languages = locale_language_list();
439
-      if ($source_exists) {
438
+        $enabled_languages = locale_language_list();
439
+        if ($source_exists) {
440 440
         drupal_set_message('Updated source translation strings at Transifex');
441
-      }
442
-      else {
441
+        }
442
+        else {
443 443
         drupal_set_message('Established new translation resource at Transifex');
444
-      }
445
-      // Try to export translations for all enabled languages
446
-      foreach ($enabled_languages as $langcode => $language_name) {
444
+        }
445
+        // Try to export translations for all enabled languages
446
+        foreach ($enabled_languages as $langcode => $language_name) {
447 447
         if ($langcode == 'en') {
448
-          continue;
448
+            continue;
449 449
         }
450 450
         $po_file = boinctranslate_get_po($langcode, 'project');
451 451
         if ($po_file) {
452
-          $path = "project/{$project_name}/resource/{$primary_resource}/translation/{$langcode}";
453
-          $post = array(
452
+            $path = "project/{$project_name}/resource/{$primary_resource}/translation/{$langcode}";
453
+            $post = array(
454 454
             'content' => $po_file,
455
-          );
456
-          $result = boinctranslate_transifex_request($path, $post, TRUE, TRUE);
457
-          if (!is_array($result)
455
+            );
456
+            $result = boinctranslate_transifex_request($path, $post, TRUE, TRUE);
457
+            if (!is_array($result)
458 458
           AND substr($result, 0, 6) == 'ERROR:') {
459 459
             drupal_set_message(
460
-              "Unable to update {$language_name} translations: {$result}",
461
-              'warning'
460
+                "Unable to update {$language_name} translations: {$result}",
461
+                'warning'
462 462
             );
463
-          }
464
-          else {
463
+            }
464
+            else {
465 465
             drupal_set_message("Updated {$language_name} translations");
466 466
             //drupal_set_message('DEBUG: <pre>'.print_r($result,1).'</pre>');
467
-          }
467
+            }
468 468
         }
469 469
         else {
470
-          drupal_set_message("No translations to export for {$language_name}");
470
+            drupal_set_message("No translations to export for {$language_name}");
471
+        }
471 472
         }
472
-      }
473 473
     }
474 474
     else {
475
-      drupal_set_message(
475
+        drupal_set_message(
476 476
         "Unable to update the translation source: {$result}",
477 477
         'warning'
478
-      );
478
+        );
479 479
     }
480
-  }
481
-  else {
480
+    }
481
+    else {
482 482
     drupal_set_message(
483
-      'Failed to export translations: Transifex settings are not intiailized.',
484
-      'error'
483
+        'Failed to export translations: Transifex settings are not intiailized.',
484
+        'error'
485 485
     );
486
-  }
487
-  drupal_goto('admin/boinc/translation');
486
+    }
487
+    drupal_goto('admin/boinc/translation');
488 488
 }
489 489
 
490 490
 /**
491 491
  *
492 492
  */
493 493
 function boinctranslate_update_official_boinc_translations() {
494
-  require_once(getcwd() . '/includes/locale.inc');
495
-  $project_name = variable_get(
494
+    require_once(getcwd() . '/includes/locale.inc');
495
+    $project_name = variable_get(
496 496
     'boinc_translate_transifex_standard_name', ''
497
-  );
498
-  $drupal_resource = variable_get(
497
+    );
498
+    $drupal_resource = variable_get(
499 499
     'boinc_translate_transifex_boinc_drupal_resource', ''
500
-  );
500
+    );
501 501
   
502
-  if ($project_name AND $drupal_resource) {
502
+    if ($project_name AND $drupal_resource) {
503 503
     // Create or update the translation source, if needed
504 504
     $source_exists = FALSE;
505 505
     $path = "project/{$project_name}/resources";
506 506
     $resources = boinctranslate_transifex_request($path);
507 507
     if ($resources AND is_array($resources)) {
508
-      foreach ($resources as $resource) {
508
+        foreach ($resources as $resource) {
509 509
         if ($resource['slug'] == $drupal_resource) {
510
-          $source_exists = TRUE;
511
-          break;
510
+            $source_exists = TRUE;
511
+            break;
512
+        }
512 513
         }
513
-      }
514 514
     }
515 515
     
516 516
     if ($source_exists) {
517
-      $enabled_languages = locale_language_list();
518
-      // Try to export translations for all enabled languages
519
-      foreach ($enabled_languages as $langcode => $language_name) {
517
+        $enabled_languages = locale_language_list();
518
+        // Try to export translations for all enabled languages
519
+        foreach ($enabled_languages as $langcode => $language_name) {
520 520
         if ($langcode == 'en') {
521
-          continue;
521
+            continue;
522 522
         }
523 523
         $po_file = boinctranslate_get_po($langcode, 'boinc');
524 524
         if ($po_file) {
525
-          $path = "project/{$project_name}/resource/{$drupal_resource}/translation/{$langcode}";
526
-          $post = array(
525
+            $path = "project/{$project_name}/resource/{$drupal_resource}/translation/{$langcode}";
526
+            $post = array(
527 527
             'content' => $po_file,
528
-          );
529
-          $result = boinctranslate_transifex_request($path, $post, TRUE, TRUE);
528
+            );
529
+            $result = boinctranslate_transifex_request($path, $post, TRUE, TRUE);
530 530
           
531
-          if (!is_array($result)) {
531
+            if (!is_array($result)) {
532 532
             if (substr($result, 0, 6) == 'ERROR:') {
533
-              drupal_set_message(
533
+                drupal_set_message(
534 534
                 "Unable to update {$language_name} official BOINC translations: {$result}",
535 535
                 'warning'
536
-              );
536
+                );
537 537
             }
538 538
             elseif ($result == '401 UNAUTHORIZED') {
539
-              drupal_set_message(
539
+                drupal_set_message(
540 540
                 'Not authorized to update official BOINC translations',
541 541
                 'warning'
542
-              );
543
-              break;
542
+                );
543
+                break;
544 544
             }
545 545
             elseif ($result == 'success') {
546
-              drupal_set_message("Updated {$language_name} official BOINC translations");
546
+                drupal_set_message("Updated {$language_name} official BOINC translations");
547 547
             }
548 548
             else {
549
-              drupal_set_message(
549
+                drupal_set_message(
550 550
                 "Unexpected response for {$language_name}: {$result}",
551 551
                 'warning'
552
-              );
552
+                );
553
+            }
553 554
             }
554
-          }
555
-          else {
555
+            else {
556 556
             drupal_set_message("Updated {$language_name} official BOINC translations");
557 557
             //drupal_set_message('DEBUG: <pre>'.print_r($result,1).'</pre>');
558
-          }
558
+            }
559 559
         }
560 560
         else {
561
-          drupal_set_message("No official BOINC translations to export for {$language_name}");
561
+            drupal_set_message("No official BOINC translations to export for {$language_name}");
562
+        }
562 563
         }
563
-      }
564 564
     }
565 565
     else {
566
-      drupal_set_message(
566
+        drupal_set_message(
567 567
         "The {$drupal_resource} resource does not exist in the {$project_name} project at Transifex",
568 568
         'warning'
569
-      );
569
+        );
570 570
     }
571
-  }
572
-  else {
571
+    }
572
+    else {
573 573
     drupal_set_message(
574
-      'Failed to export official BOINC translations: Transifex settings are not intiailized.',
575
-      'error'
574
+        'Failed to export official BOINC translations: Transifex settings are not intiailized.',
575
+        'error'
576 576
     );
577
-  }
578
-  drupal_goto('admin/boinc/translation');
577
+    }
578
+    drupal_goto('admin/boinc/translation');
579 579
 }
580 580
 
581 581
 /**
582 582
  *
583 583
  */
584 584
 function boinctranslate_download_pot($type = 'boinc') {
585
-  $po = boinctranslate_get_po(NULL, $type);
586
-  _locale_export_po(NULL, $po);
585
+    $po = boinctranslate_get_po(NULL, $type);
586
+    _locale_export_po(NULL, $po);
587 587
 }
588 588
 
589 589
 /**
590 590
  *
591 591
  */
592 592
 function boinctranslate_transifex_request($path, $post = NULL, $json = TRUE, $use_put = FALSE, $username = '', $password = '') {
593
-  $debug_mode = variable_get('boinc_debug_mode', 0);
593
+    $debug_mode = variable_get('boinc_debug_mode', 0);
594 594
   
595
-  // Transifex details
596
-  $api_base_url = 'https://www.transifex.com/api/2';
597
-  if (!$username) $username = variable_get('boinc_translate_transifex_user', '');
598
-  if (!$password) $password = variable_get('boinc_translate_transifex_pass', '');
595
+    // Transifex details
596
+    $api_base_url = 'https://www.transifex.com/api/2';
597
+    if (!$username) $username = variable_get('boinc_translate_transifex_user', '');
598
+    if (!$password) $password = variable_get('boinc_translate_transifex_pass', '');
599 599
   
600
-  $url = "{$api_base_url}/{$path}";
601
-  $headers = array(
600
+    $url = "{$api_base_url}/{$path}";
601
+    $headers = array(
602 602
     'Authorization' => 'Basic ' . base64_encode($username . ":" . $password),
603
-  );
604
-  $data = NULL;
603
+    );
604
+    $data = NULL;
605 605
   
606
-  if ($post) {
606
+    if ($post) {
607 607
     if ($json) {
608
-      $headers['Content-Type'] = 'application/json';
609
-      $data = json_encode($post);
608
+        $headers['Content-Type'] = 'application/json';
609
+        $data = json_encode($post);
610 610
     }
611 611
     else {
612
-      $data = drupal_query_string_encode($post);
612
+        $data = drupal_query_string_encode($post);
613 613
     }
614 614
     $method = ($use_put) ? 'PUT' : 'POST';
615
-  }
616
-  else {
615
+    }
616
+    else {
617 617
     $method = 'GET';
618
-  }
618
+    }
619 619
   
620
-  $response = drupal_http_request($url, $headers, $method, $data, 1, 10);
620
+    $response = drupal_http_request($url, $headers, $method, $data, 1, 10);
621 621
   
622
-  switch ($response->code) {
623
-  case 200:
622
+    switch ($response->code) {
623
+    case 200:
624 624
   case 304:
625 625
     if ($json) {
626
-      // Process as JSON
627
-      return json_decode($response->data, TRUE);
626
+        // Process as JSON
627
+        return json_decode($response->data, TRUE);
628 628
     }
629 629
     else {
630
-      return (string) $response->data;
630
+        return (string) $response->data;
631 631
     }
632 632
     break;
633
-  case 404:
633
+    case 404:
634 634
     return '404 NOT FOUND';
635
-  case 401:
635
+    case 401:
636 636
     return '401 UNAUTHORIZED';
637
-  case 400:
637
+    case 400:
638 638
     if ($debug_mode) watchdog('boinctranslate', "The following response was received when trying to communicate with the Transifex system: \n{$response}", array(), WATCHDOG_WARNING);
639 639
     return "ERROR: {$response->data}";
640
-  case 405:
640
+    case 405:
641 641
     if ($debug_mode) watchdog('boinctranslate', "The following response was received when trying to communicate with the Transifex system: \n{$response}", array(), WATCHDOG_WARNING);
642 642
     return "ERROR: User not allowed to perform this action";
643
-  }
643
+    }
644 644
   
645
-  return NULL;
645
+    return NULL;
646 646
 }
647 647
 
648 648
 /**
@@ -650,58 +650,58 @@  discard block
 block discarded – undo
650 650
  */
651 651
 function boinctranslate_get_po($langcode, $type = 'standard') {
652 652
 
653
-  require_once(getcwd() . '/includes/locale.inc');
653
+    require_once(getcwd() . '/includes/locale.inc');
654 654
   
655
-  $all_languages = language_list();
656
-  $language = $langcode ? $all_languages[$langcode] : NULL;
657
-  $textgroups = array();
658
-  $strings = array();
655
+    $all_languages = language_list();
656
+    $language = $langcode ? $all_languages[$langcode] : NULL;
657
+    $textgroups = array();
658
+    $strings = array();
659 659
   
660
-  switch ($type) {
661
-  case 'standard':
660
+    switch ($type) {
661
+    case 'standard':
662 662
     $textgroups = array(
663
-      'default',
664
-      'taxonomy',
665
-      'views',
663
+        'default',
664
+        'taxonomy',
665
+        'views',
666 666
     );
667 667
     break;
668
-  case 'boinc':
668
+    case 'boinc':
669 669
     $textgroups = array(
670
-      'boinc',
670
+        'boinc',
671 671
     );
672 672
     break;
673
-  case 'project':
673
+    case 'project':
674 674
     $textgroups = array(
675
-      'blocks',
676
-      'menu',
677
-      'project',
675
+        'blocks',
676
+        'menu',
677
+        'project',
678 678
     );
679 679
     break;
680
-  default:
680
+    default:
681 681
   }
682 682
   
683
-  // Merge textgroup strings together for export as one file
684
-  foreach ($textgroups as $textgroup) {
683
+    // Merge textgroup strings together for export as one file
684
+    foreach ($textgroups as $textgroup) {
685 685
     $strings += _locale_export_get_strings($language, $textgroup);
686
-  }
687
-  ksort($strings);
688
-  foreach ($strings as $id => $string) {
686
+    }
687
+    ksort($strings);
688
+    foreach ($strings as $id => $string) {
689 689
     // Set the string context
690 690
     $strings[$id]['context'] = trim($string['comment']);
691
-  }
692
-  if ($langcode AND $langcode != 'en') {
691
+    }
692
+    if ($langcode AND $langcode != 'en') {
693 693
     // If not the source language, remove untranslated strings from the ouput
694 694
     foreach ($strings as $i => $string) {
695
-      if (!$string['translation']) {
695
+        if (!$string['translation']) {
696 696
         unset($strings[$i]);
697
-      }
697
+        }
698 698
     }
699
-  }
700
-  if ($strings) {
699
+    }
700
+    if ($strings) {
701 701
     return boinctranslate_export_po_generate($language, $strings, NULL, $type);
702
-  }
702
+    }
703 703
   
704
-  return NULL;
704
+    return NULL;
705 705
 }
706 706
 
707 707
 /**
@@ -709,21 +709,21 @@  discard block
 block discarded – undo
709 709
  */
710 710
 function boinctranslate_export_po_generate($language = NULL, $strings = array(), $header = NULL, $type = NULL) {
711 711
 
712
-  require_once(getcwd() . '/includes/locale.inc');
713
-  global $user;
712
+    require_once(getcwd() . '/includes/locale.inc');
713
+    global $user;
714 714
 
715
-  // unset $language to indicate template creation
716
-  if (isset($language) && $language->language == "en") {
715
+    // unset $language to indicate template creation
716
+    if (isset($language) && $language->language == "en") {
717 717
     $language = NULL;
718
-  }
718
+    }
719 719
 
720
-  if (!isset($header)) {
720
+    if (!isset($header)) {
721 721
     if (isset($type) && $type == "project") {
722
-      $header = "# ".variable_get('site_name', 'Drupal')." drupal localization template\n";
723
-      $header .= "# Copyright (C) ".date("Y")." ".variable_get('site_name', 'Drupal')."\n";
722
+        $header = "# ".variable_get('site_name', 'Drupal')." drupal localization template\n";
723
+        $header .= "# Copyright (C) ".date("Y")." ".variable_get('site_name', 'Drupal')."\n";
724 724
     } else {
725
-      $header = "# BOINC drupal localization template\n";
726
-      $header .= "# Copyright (C) ".date("Y")." University of California\n";
725
+        $header = "# BOINC drupal localization template\n";
726
+        $header .= "# Copyright (C) ".date("Y")." University of California\n";
727 727
     }
728 728
     $header .= '# Generated by ' . $user->name . ' <' . $user->mail . ">\n";
729 729
     $header .= "#\n";
@@ -732,180 +732,180 @@  discard block
 block discarded – undo
732 732
     $header .= "msgid \"\"\n";
733 733
     $header .= "msgstr \"\"\n";
734 734
     if (isset($type) && $type == "project") {
735
-      $header .= "\"Project-Id-Version: ".variable_get('site_name', 'Drupal')." ".date("Y-m-d-H:iO")."\\n\"\n";
735
+        $header .= "\"Project-Id-Version: ".variable_get('site_name', 'Drupal')." ".date("Y-m-d-H:iO")."\\n\"\n";
736 736
     } else {
737
-      $header .= "\"Project-Id-Version: BOINC unknown\\n\"\n"; // TODO: add SHA1 of source checkout here
737
+        $header .= "\"Project-Id-Version: BOINC unknown\\n\"\n"; // TODO: add SHA1 of source checkout here
738 738
     }
739 739
     $header .= "\"Report-Msgid-Bugs-To: BOINC translation team <[email protected]>\\n\"\n";
740 740
     $header .= "\"POT-Creation-Date: " . date("Y-m-d H:iO") . "\\n\"\n";
741 741
     if (isset($language)) {
742
-      $header .= "\"PO-Revision-Date: " . date("Y-m-d H:iO") . "\\n\"\n";
742
+        $header .= "\"PO-Revision-Date: " . date("Y-m-d H:iO") . "\\n\"\n";
743 743
     }
744 744
     $header .= "\"Last-Translator: Generated automatically from Drupal translate interface\\n\"\n";
745 745
     $header .= "\"MIME-Version: 1.0\\n\"\n";
746 746
     $header .= "\"Content-Type: text/plain; charset=utf-8\\n\"\n";
747 747
     $header .= "\"Content-Transfer-Encoding: 8bit\\n\"\n";
748 748
     if (isset($language)) {
749
-      $header .= "\"Language: ".$language->language."\\n\"";
750
-      if ($language->formula && $language->plurals) {
749
+        $header .= "\"Language: ".$language->language."\\n\"";
750
+        if ($language->formula && $language->plurals) {
751 751
         $header .= "\"Plural-Forms: nplurals=" . $language->plurals . "; plural=" . strtr($language->formula, array('$' => '')) . ";\\n\"\n";
752
-      }
752
+        }
753 753
     }
754 754
     $header .= "\"X-Poedit-SourceCharset: utf-8\\n\"\n";
755
-  }
755
+    }
756 756
 
757
-  $output = $header . "\n";
757
+    $output = $header . "\n";
758 758
 
759
-  foreach ($strings as $lid => $string) {
759
+    foreach ($strings as $lid => $string) {
760 760
     // Only process non-children, children are output below their parent.
761 761
     if (!isset($string['child'])) {
762
-      if ($string['comment']) {
762
+        if ($string['comment']) {
763 763
         $output .= '#: ' . $string['comment'] . "\n";
764
-      }
765
-      if ($string['context']) {
764
+        }
765
+        if ($string['context']) {
766 766
         $output .= 'msgctxt "' . $string['context'] . "\"\n";
767
-      }
768
-      $output .= 'msgid ' . _locale_export_string($string['source']);
769
-      if (!empty($string['plural'])) {
767
+        }
768
+        $output .= 'msgid ' . _locale_export_string($string['source']);
769
+        if (!empty($string['plural'])) {
770 770
         $plural = $string['plural'];
771 771
         $output .= 'msgid_plural ' . _locale_export_string($strings[$plural]['source']);
772 772
         if (isset($language)) {
773
-          $translation = $string['translation'];
774
-          for ($i = 0; $i < $language->plurals; $i++) {
773
+            $translation = $string['translation'];
774
+            for ($i = 0; $i < $language->plurals; $i++) {
775 775
             $output .= 'msgstr[' . $i . '] ' . _locale_export_string($translation);
776 776
             if ($plural) {
777
-              $translation = _locale_export_remove_plural($strings[$plural]['translation']);
778
-              $plural = isset($strings[$plural]['plural']) ? $strings[$plural]['plural'] : 0;
777
+                $translation = _locale_export_remove_plural($strings[$plural]['translation']);
778
+                $plural = isset($strings[$plural]['plural']) ? $strings[$plural]['plural'] : 0;
779 779
             }
780 780
             else {
781
-              $translation = '';
781
+                $translation = '';
782
+            }
782 783
             }
783
-          }
784 784
         }
785 785
         else {
786
-          $output .= 'msgstr[0] ""' . "\n";
787
-          $output .= 'msgstr[1] ""' . "\n";
786
+            $output .= 'msgstr[0] ""' . "\n";
787
+            $output .= 'msgstr[1] ""' . "\n";
788
+        }
788 789
         }
789
-      }
790
-      else {
790
+        else {
791 791
         $output .= 'msgstr ' . _locale_export_string($string['translation']);
792
-      }
793
-      $output .= "\n";
792
+        }
793
+        $output .= "\n";
794 794
     }
795
-  }
796
-  return $output;
795
+    }
796
+    return $output;
797 797
 }
798 798
 
799 799
 /**
800 800
  *
801 801
  */
802 802
 function boinctranslate_refresh_translations() {
803
-  require_once(getcwd() . '/includes/locale.inc');
804
-  $errors = array();
805
-  $languages = locale_language_list();
806
-  $translation_resources = array();
807
-  $operations = array();
808
-  $debug_mode = variable_get('boinc_debug_mode', 0);
803
+    require_once(getcwd() . '/includes/locale.inc');
804
+    $errors = array();
805
+    $languages = locale_language_list();
806
+    $translation_resources = array();
807
+    $operations = array();
808
+    $debug_mode = variable_get('boinc_debug_mode', 0);
809 809
   
810
-  $boinc_name = variable_get(
810
+    $boinc_name = variable_get(
811 811
     'boinc_translate_transifex_standard_name', ''
812
-  );
813
-  $boinc_resources = boinctranslate_parse_resources(
812
+    );
813
+    $boinc_resources = boinctranslate_parse_resources(
814 814
     variable_get('boinc_translate_transifex_standard_resources', array())
815
-  );
816
-  // Add the Official BOINC resource to the list of BOINC resources;
817
-  // The official resource overrides any additional resources provided, so it
818
-  // should be added to the end so as to be processed last
819
-  $drupal_resource = variable_get(
815
+    );
816
+    // Add the Official BOINC resource to the list of BOINC resources;
817
+    // The official resource overrides any additional resources provided, so it
818
+    // should be added to the end so as to be processed last
819
+    $drupal_resource = variable_get(
820 820
     'boinc_translate_transifex_boinc_drupal_resource', ''
821
-  );
822
-  $boinc_resources[] = $drupal_resource;
823
-  if ($boinc_name AND $boinc_resources) {
821
+    );
822
+    $boinc_resources[] = $drupal_resource;
823
+    if ($boinc_name AND $boinc_resources) {
824 824
     $translation_resources[$boinc_name] = array(
825
-      'resources' => $boinc_resources,
826
-      'textgroups' => array(
825
+        'resources' => $boinc_resources,
826
+        'textgroups' => array(
827 827
         'boinc',
828 828
         'default',
829 829
         'taxonomy',
830 830
         'views',
831
-      ),
831
+        ),
832 832
     );
833
-  }
834
-  $project_name = variable_get(
833
+    }
834
+    $project_name = variable_get(
835 835
     'boinc_translate_transifex_project_name', ''
836
-  );
837
-  $project_resources = boinctranslate_parse_resources(
836
+    );
837
+    $project_resources = boinctranslate_parse_resources(
838 838
     variable_get('boinc_translate_transifex_project_resources', array())
839
-  );
840
-  if ($project_name AND $project_resources) {
839
+    );
840
+    if ($project_name AND $project_resources) {
841 841
     $translation_resources[$project_name] = array(
842
-      'resources' => $project_resources,
843
-      'textgroups' => array(
842
+        'resources' => $project_resources,
843
+        'textgroups' => array(
844 844
         'blocks',
845 845
         'menu',
846 846
         'project',
847
-      ),
847
+        ),
848 848
     );
849 849
     // Be sure any strings from the override file are added to the boinc group
850 850
     $override_file = './' . drupal_get_path('module', 'boinctranslate') . '/includes/other-boinc-translation-strings.txt';
851 851
     $other_strings = file($override_file);
852 852
     if ($other_strings) {
853
-      foreach ($other_strings as $string) {
853
+        foreach ($other_strings as $string) {
854 854
         $string = trim($string);
855 855
         if ($string) {
856
-          bts($string);
856
+            bts($string);
857
+        }
857 858
         }
858
-      }
859 859
     }
860
-  }
860
+    }
861 861
   
862
-  foreach ($languages as $langcode => $language) {
862
+    foreach ($languages as $langcode => $language) {
863 863
     if ($langcode == 'en') {
864
-      continue;
864
+        continue;
865 865
     }
866 866
     
867 867
     $import_stats = array(
868
-      'new' => 0,
869
-      'updated' => 0,
870
-      'deleted' => 0,
871
-      'skipped' => 0,
868
+        'new' => 0,
869
+        'updated' => 0,
870
+        'deleted' => 0,
871
+        'skipped' => 0,
872 872
     );
873 873
   
874 874
     foreach ($translation_resources as $project => $translation) {
875
-      foreach ($translation['resources'] as $resource) {
875
+        foreach ($translation['resources'] as $resource) {
876 876
         
877 877
         // Add this language to the batch operations
878 878
         $operations[] = array(
879
-          'boinctranslate_refresh_translations_op',
880
-          array(
879
+            'boinctranslate_refresh_translations_op',
880
+            array(
881 881
             $project, $resource, $langcode, $language, $translation['textgroups'], $debug_mode
882
-          ),
882
+            ),
883 883
         );
884
-      }
884
+        }
885 885
     }
886 886
     if ($batch = locale_batch_by_language($langcode)) {
887
-      foreach ($batch['operations'] as $op) {
887
+        foreach ($batch['operations'] as $op) {
888 888
         $operations[] = array(
889
-          'boinctranslate_refresh_translations_op',
890
-          array(
889
+            'boinctranslate_refresh_translations_op',
890
+            array(
891 891
             NULL, $op[1][0], $langcode, $language, array('default'), $debug_mode
892
-          ),
892
+            ),
893 893
         );
894
-      }
894
+        }
895
+    }
895 896
     }
896
-  }
897 897
   
898
-  $batch = array(
898
+    $batch = array(
899 899
     'operations' => $operations,
900 900
     'finished' => 'boinctranslate_refresh_translations_finished',
901 901
     'title' => t('Importing translations'),
902 902
     'init_message' => t('Beginning translation import...'),
903 903
     'progress_message' => t('Applied @current out of @total translation updates.'),
904 904
     'error_message' => t('Translation import has encountered an error.'),
905
-  );
905
+    );
906 906
   
907
-  batch_set($batch);
908
-  batch_process();
907
+    batch_set($batch);
908
+    batch_process();
909 909
 }
910 910
 
911 911
 
@@ -914,18 +914,18 @@  discard block
 block discarded – undo
914 914
  */
915 915
 function boinctranslate_refresh_translations_op($project, $resource, $langcode, $language, $textgroups, $debug_mode, &$context) {
916 916
   
917
-  require_once(getcwd() . '/includes/locale.inc');
917
+    require_once(getcwd() . '/includes/locale.inc');
918 918
   
919
-  if ($debug_mode) {
919
+    if ($debug_mode) {
920 920
     watchdog(
921
-      'boinctranslate',
922
-      'Checking for @language updates in @project:@resource',
923
-      array('@language' => $language, '@project' => $project, '@resource' => $resource),
924
-      WATCHDOG_INFO
921
+        'boinctranslate',
922
+        'Checking for @language updates in @project:@resource',
923
+        array('@language' => $language, '@project' => $project, '@resource' => $resource),
924
+        WATCHDOG_INFO
925 925
     );
926
-  }
926
+    }
927 927
   
928
-  if ($project) {
928
+    if ($project) {
929 929
     // Import the configured resources
930 930
     $success = FALSE;
931 931
     $message = '';
@@ -933,10 +933,10 @@  discard block
 block discarded – undo
933 933
     $response = boinctranslate_transifex_request($path);
934 934
     
935 935
     if ($response == '404 NOT FOUND') {
936
-      $message = "Project resource {$project}:{$resource} not found in {$language}.";
936
+        $message = "Project resource {$project}:{$resource} not found in {$language}.";
937 937
     }
938 938
     elseif ($response) {
939
-      if (!empty($response['content'])) {
939
+        if (!empty($response['content'])) {
940 940
         $po_text = $response['content'];
941 941
         
942 942
         // Write the translation file to a temporary location
@@ -944,164 +944,164 @@  discard block
 block discarded – undo
944 944
         $file->filepath = file_save_data($po_text, NULL);
945 945
         $file->filename = basename($file->filepath);
946 946
         if (!$file->filepath) {
947
-          $message = 'Unable to create temporary file in '
947
+            $message = 'Unable to create temporary file in '
948 948
             . file_directory_temp() . " for {$language} translation "
949 949
             . "resource {$project}:{$resource}";
950 950
         }
951 951
         
952 952
         foreach ($textgroups as $textgroup) {
953
-          // Import the translations from the file to each related textgroup
954
-          if (!$results = _boinctranslate_locale_import_po($file, $langcode, LOCALE_IMPORT_OVERWRITE, $textgroup)) {
953
+            // Import the translations from the file to each related textgroup
954
+            if (!$results = _boinctranslate_locale_import_po($file, $langcode, LOCALE_IMPORT_OVERWRITE, $textgroup)) {
955 955
             $message = "The {$language} translation import of"
956
-              . " {$project}:{$resource} failed.";
956
+                . " {$project}:{$resource} failed.";
957 957
             $success = FALSE;
958 958
             break;
959
-          }
960
-          else {
959
+            }
960
+            else {
961 961
             $success = TRUE;
962
-          }
962
+            }
963
+        }
963 964
         }
964
-      }
965
-      else {
965
+        else {
966 966
         $message = "Unable to read response for {$language} translation import"
967
-          . " of {$project}:{$resource}.";
968
-      }
967
+            . " of {$project}:{$resource}.";
968
+        }
969 969
     }
970 970
     else {
971
-      $message = "Translation data not found in response for {$language}"
971
+        $message = "Translation data not found in response for {$language}"
972 972
         . " translation import of {$project}:{$resource}.";
973 973
     }
974
-  }
975
-  else {
974
+    }
975
+    else {
976 976
     // If project isn't specified, import as a local Drupal resource
977 977
     $project = 'drupal.local';
978 978
     $file = new stdClass();
979 979
     $file->filepath = $resource;
980 980
     $file->filename = basename($file->filepath);
981 981
     if (!$results = _boinctranslate_locale_import_po($file, $langcode, LOCALE_IMPORT_OVERWRITE, $textgroup)) {
982
-      $message = "The {$language} translation import of"
982
+        $message = "The {$language} translation import of"
983 983
         . " local file {$resource} failed.";
984
-      $success = FALSE;
985
-      break;
984
+        $success = FALSE;
985
+        break;
986 986
     }
987 987
     else {
988
-      $success = TRUE;
988
+        $success = TRUE;
989
+    }
989 990
     }
990
-  }
991 991
   
992
-  if ($success) {
992
+    if ($success) {
993 993
     // Store some result for post-processing in the finished callback.
994 994
     $context['results']['success'][] = "{$langcode}:{$textgroup}";
995 995
     $message = "Imported {$language} translations in {$project}:{$resource} ({$results['new']} added, {$results['updated']} refreshed, {$results['deleted']} removed)";
996 996
     
997 997
     if ($debug_mode) {
998
-      watchdog(
998
+        watchdog(
999 999
         'boinctranslate',
1000 1000
         $message,
1001 1001
         array(),
1002 1002
         WATCHDOG_INFO
1003
-      );
1003
+        );
1004 1004
     }
1005
-  }
1006
-  else {
1005
+    }
1006
+    else {
1007 1007
     $context['results']['failure'][] = "{$langcode}:{$textgroup}";
1008 1008
     watchdog(
1009
-      'boinctranslate',
1010
-      $message,
1011
-      array(),
1012
-      WATCHDOG_WARNING
1009
+        'boinctranslate',
1010
+        $message,
1011
+        array(),
1012
+        WATCHDOG_WARNING
1013 1013
     );
1014
-  }
1014
+    }
1015 1015
   
1016
-  // Update our progress information.
1017
-  $context['sandbox']['progress']++;
1018
-  $context['sandbox']['language'] = $langcode;
1019
-  $context['message'] = $message;
1016
+    // Update our progress information.
1017
+    $context['sandbox']['progress']++;
1018
+    $context['sandbox']['language'] = $langcode;
1019
+    $context['message'] = $message;
1020 1020
 
1021
-  // Update the progress for the batch engine
1022
-  if ($context['sandbox']['progress'] >= $context['sandbox']['max']) {
1021
+    // Update the progress for the batch engine
1022
+    if ($context['sandbox']['progress'] >= $context['sandbox']['max']) {
1023 1023
     $context['finished'] = 1;
1024
-  }
1025
-  else {
1024
+    }
1025
+    else {
1026 1026
     $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
1027
-  }
1027
+    }
1028 1028
 }
1029 1029
 
1030 1030
 /**
1031 1031
  * Batch 'finished' callback
1032 1032
  */
1033 1033
 function boinctranslate_refresh_translations_finished($success, $results, $operations) {
1034
-  if ($success) {
1034
+    if ($success) {
1035 1035
     // Let's count our successes
1036 1036
     $count = count($results['success']);
1037 1037
     $message = "Successfully completed {$count} import operations";
1038 1038
     watchdog(
1039
-      'boinctranslate',
1040
-      'Successfully completed @count import operations.',
1041
-      array('@count' => $count),
1042
-      WATCHDOG_INFO
1039
+        'boinctranslate',
1040
+        'Successfully completed @count import operations.',
1041
+        array('@count' => $count),
1042
+        WATCHDOG_INFO
1043 1043
     ); 
1044
-  }
1045
-  else {
1044
+    }
1045
+    else {
1046 1046
     // An error occurred.
1047 1047
     // $operations contains the operations that remained unprocessed.
1048 1048
     $error_operation = reset($operations);
1049 1049
     $message = 'An error occurred while processing ' . $error_operation[0] . ' with arguments :' . print_r($error_operation[0], TRUE);
1050 1050
     watchdog(
1051
-      'boinctranslate',
1052
-      $message,
1053
-      array(),
1054
-      WATCHDOG_WARNING
1051
+        'boinctranslate',
1052
+        $message,
1053
+        array(),
1054
+        WATCHDOG_WARNING
1055 1055
     );
1056
-  }
1057
-  drupal_set_message($message);
1058
-  drupal_goto('admin/boinc/translation');
1056
+    }
1057
+    drupal_set_message($message);
1058
+    drupal_goto('admin/boinc/translation');
1059 1059
 }
1060 1060
 
1061 1061
 /**
1062 1062
  *
1063 1063
  */
1064 1064
 function _boinctranslate_locale_import_po($file, $langcode, $mode, $group = NULL) {
1065
-  // Try to allocate enough time to parse and import the data.
1066
-  if (function_exists('set_time_limit')) {
1065
+    // Try to allocate enough time to parse and import the data.
1066
+    if (function_exists('set_time_limit')) {
1067 1067
     @set_time_limit(240);
1068
-  }
1068
+    }
1069 1069
 
1070
-  require_once(getcwd() . '/includes/locale.inc');
1070
+    require_once(getcwd() . '/includes/locale.inc');
1071 1071
   
1072
-  // Check if we have the language already in the database.
1073
-  if (!db_fetch_object(db_query("SELECT language FROM {languages} WHERE language = '%s'", $langcode))) {
1072
+    // Check if we have the language already in the database.
1073
+    if (!db_fetch_object(db_query("SELECT language FROM {languages} WHERE language = '%s'", $langcode))) {
1074 1074
     drupal_set_message(t('The language selected for import is not supported.'), 'error');
1075 1075
     return FALSE;
1076
-  }
1076
+    }
1077 1077
 
1078
-  // Get strings from file (returns on failure after a partial import, or on success)
1079
-  $status = _boinctranslate_locale_import_read_po('db-store', $file, $mode, $langcode, $group);
1080
-  if ($status === FALSE) {
1078
+    // Get strings from file (returns on failure after a partial import, or on success)
1079
+    $status = _boinctranslate_locale_import_read_po('db-store', $file, $mode, $langcode, $group);
1080
+    if ($status === FALSE) {
1081 1081
     // Error messages are set in _locale_import_read_po().
1082 1082
     return FALSE;
1083
-  }
1083
+    }
1084 1084
 
1085
-  // Get status information on import process.
1086
-  list($headerdone, $additions, $updates, $deletes, $skips) = _boinctranslate_locale_import_one_string('db-report');
1085
+    // Get status information on import process.
1086
+    list($headerdone, $additions, $updates, $deletes, $skips) = _boinctranslate_locale_import_one_string('db-report');
1087 1087
   
1088
-  if (!$headerdone) {
1088
+    if (!$headerdone) {
1089 1089
     drupal_set_message(t('The translation file %filename appears to have a missing or malformed header.', array('%filename' => $file->filename)), 'error');
1090
-  }
1090
+    }
1091 1091
   
1092
-  // Clear cache and force refresh of JavaScript translations.
1093
-  _locale_invalidate_js($langcode);
1094
-  cache_clear_all('locale:', 'cache', TRUE);
1092
+    // Clear cache and force refresh of JavaScript translations.
1093
+    _locale_invalidate_js($langcode);
1094
+    cache_clear_all('locale:', 'cache', TRUE);
1095 1095
 
1096
-  // Rebuild the menu, strings may have changed.
1097
-  menu_rebuild();
1096
+    // Rebuild the menu, strings may have changed.
1097
+    menu_rebuild();
1098 1098
   
1099
-  return array(
1099
+    return array(
1100 1100
     'new' => $additions,
1101 1101
     'updated' => $updates,
1102 1102
     'deleted' => $deletes,
1103 1103
     'skipped' => $skips,
1104
-  );
1104
+    );
1105 1105
 }
1106 1106
 
1107 1107
 /**
@@ -1109,253 +1109,253 @@  discard block
 block discarded – undo
1109 1109
  */
1110 1110
 function _boinctranslate_locale_import_read_po($op, $file, $mode = NULL, $lang = NULL, $group = 'default') {
1111 1111
 
1112
-  require_once(getcwd() . '/includes/locale.inc');
1112
+    require_once(getcwd() . '/includes/locale.inc');
1113 1113
   
1114
-  $fd = fopen($file->filepath, "rb"); // File will get closed by PHP on return
1115
-  if (!$fd) {
1114
+    $fd = fopen($file->filepath, "rb"); // File will get closed by PHP on return
1115
+    if (!$fd) {
1116 1116
     watchdog(
1117
-      'boinctranslate',
1118
-      'The translation import for %lang failed, because %filename could not be read.',
1119
-      array('%lang' => $lang, '%filename' => $file->filename),
1120
-      WATCHDOG_WARNING
1117
+        'boinctranslate',
1118
+        'The translation import for %lang failed, because %filename could not be read.',
1119
+        array('%lang' => $lang, '%filename' => $file->filename),
1120
+        WATCHDOG_WARNING
1121 1121
     );
1122 1122
     _locale_import_message('The translation import failed, because the file %filename could not be read.', $file);
1123 1123
     return FALSE;
1124
-  }
1124
+    }
1125 1125
 
1126
-  $context = "COMMENT"; // Parser context: COMMENT, MSGID, MSGID_PLURAL, MSGSTR and MSGSTR_ARR
1127
-  $current = array(); // Current entry being read
1128
-  $plural = 0; // Current plural form
1129
-  $lineno = 0; // Current line
1126
+    $context = "COMMENT"; // Parser context: COMMENT, MSGID, MSGID_PLURAL, MSGSTR and MSGSTR_ARR
1127
+    $current = array(); // Current entry being read
1128
+    $plural = 0; // Current plural form
1129
+    $lineno = 0; // Current line
1130 1130
 
1131
-  while (!feof($fd)) {
1131
+    while (!feof($fd)) {
1132 1132
     $line = fgets($fd, 10 * 1024); // A line should not be this long
1133 1133
     if ($lineno == 0) {
1134
-      // The first line might come with a UTF-8 BOM, which should be removed.
1135
-      $line = str_replace("\xEF\xBB\xBF", '', $line);
1134
+        // The first line might come with a UTF-8 BOM, which should be removed.
1135
+        $line = str_replace("\xEF\xBB\xBF", '', $line);
1136 1136
     }
1137 1137
     $lineno++;
1138 1138
     $line = trim(strtr($line, array("\\\n" => "")));
1139 1139
 
1140 1140
     if (!strncmp("#", $line, 1)) { // A comment
1141
-      if ($context == "COMMENT") { // Already in comment context: add
1141
+        if ($context == "COMMENT") { // Already in comment context: add
1142 1142
         $current["#"][] = substr($line, 1);
1143
-      }
1144
-      elseif (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one
1143
+        }
1144
+        elseif (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one
1145 1145
         _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group);
1146 1146
         $current = array();
1147 1147
         $current["#"][] = substr($line, 1);
1148 1148
         $context = "COMMENT";
1149
-      }
1150
-      else { // Parse error
1149
+        }
1150
+        else { // Parse error
1151 1151
         watchdog(
1152
-          'boinctranslate',
1153
-          'The translation file %filename for %lang contains an error: "msgstr" was expected but not found on line %line.',
1154
-          array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1155
-          WATCHDOG_WARNING
1152
+            'boinctranslate',
1153
+            'The translation file %filename for %lang contains an error: "msgstr" was expected but not found on line %line.',
1154
+            array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1155
+            WATCHDOG_WARNING
1156 1156
         );
1157 1157
         _locale_import_message('The translation file %filename contains an error: "msgstr" was expected but not found on line %line.', $file, $lineno);
1158 1158
         return FALSE;
1159
-      }
1159
+        }
1160 1160
     }
1161 1161
     elseif (!strncmp("msgctxt", $line, 7)) {
1162
-      if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one
1162
+        if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one
1163 1163
         _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group);
1164 1164
         $current = array();
1165
-      }
1166
-      elseif (($context == "MSGID") || ($context == "MSGCTXT")) { // Already in this context? Parse error
1165
+        }
1166
+        elseif (($context == "MSGID") || ($context == "MSGCTXT")) { // Already in this context? Parse error
1167 1167
         watchdog(
1168
-          'boinctranslate',
1169
-          'The translation file %filename for %lang contains an error: "msgctxt" is unexpected on line %line.',
1170
-          array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1171
-          WATCHDOG_WARNING
1168
+            'boinctranslate',
1169
+            'The translation file %filename for %lang contains an error: "msgctxt" is unexpected on line %line.',
1170
+            array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1171
+            WATCHDOG_WARNING
1172 1172
         );
1173 1173
         _locale_import_message('The translation file %filename contains an error: "msgid" is unexpected on line %line.', $file, $lineno);
1174 1174
         return FALSE;
1175
-      }
1176
-      $line = trim(substr($line, 7));
1177
-      $quoted = _locale_import_parse_quoted($line);
1178
-      if ($quoted === FALSE) {
1175
+        }
1176
+        $line = trim(substr($line, 7));
1177
+        $quoted = _locale_import_parse_quoted($line);
1178
+        if ($quoted === FALSE) {
1179 1179
         watchdog(
1180
-          'boinctranslate',
1181
-          'The translation file %filename for language %lang contains a syntax error on line %line.',
1182
-          array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1183
-          WATCHDOG_WARNING
1180
+            'boinctranslate',
1181
+            'The translation file %filename for language %lang contains a syntax error on line %line.',
1182
+            array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1183
+            WATCHDOG_WARNING
1184 1184
         );
1185 1185
         _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno);
1186 1186
         return FALSE;
1187
-      }
1188
-      $current["msgctxt"] = $quoted;
1189
-      $context = "MSGCTXT";
1187
+        }
1188
+        $current["msgctxt"] = $quoted;
1189
+        $context = "MSGCTXT";
1190 1190
     }
1191 1191
     elseif (!strncmp("msgid_plural", $line, 12)) {
1192
-      if ($context != "MSGID") { // Must be plural form for current entry
1192
+        if ($context != "MSGID") { // Must be plural form for current entry
1193 1193
         watchdog(
1194
-          'boinctranslate',
1195
-          'The translation file %filename for %lang contains an error: "msgid_plural" was expected but not found on line %line.',
1196
-          array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1197
-          WATCHDOG_WARNING
1194
+            'boinctranslate',
1195
+            'The translation file %filename for %lang contains an error: "msgid_plural" was expected but not found on line %line.',
1196
+            array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1197
+            WATCHDOG_WARNING
1198 1198
         );
1199 1199
         _locale_import_message('The translation file %filename contains an error: "msgid_plural" was expected but not found on line %line.', $file, $lineno);
1200 1200
         return FALSE;
1201
-      }
1202
-      $line = trim(substr($line, 12));
1203
-      $quoted = _locale_import_parse_quoted($line);
1204
-      if ($quoted === FALSE) {
1201
+        }
1202
+        $line = trim(substr($line, 12));
1203
+        $quoted = _locale_import_parse_quoted($line);
1204
+        if ($quoted === FALSE) {
1205 1205
         watchdog(
1206
-          'boinctranslate',
1207
-          'The translation file %filename for language %lang contains a syntax error on line %line.',
1208
-          array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1209
-          WATCHDOG_WARNING
1206
+            'boinctranslate',
1207
+            'The translation file %filename for language %lang contains a syntax error on line %line.',
1208
+            array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1209
+            WATCHDOG_WARNING
1210 1210
         );
1211 1211
         _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno);
1212 1212
         return FALSE;
1213
-      }
1214
-      $current["msgid"] = $current["msgid"] . "\0" . $quoted;
1215
-      $context = "MSGID_PLURAL";
1213
+        }
1214
+        $current["msgid"] = $current["msgid"] . "\0" . $quoted;
1215
+        $context = "MSGID_PLURAL";
1216 1216
     }
1217 1217
     elseif (!strncmp("msgid", $line, 5)) {
1218
-      if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one
1218
+        if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one
1219 1219
         _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group);
1220 1220
         $current = array();
1221
-      }
1222
-      elseif ($context == "MSGID") { // Already in this context? Parse error
1221
+        }
1222
+        elseif ($context == "MSGID") { // Already in this context? Parse error
1223 1223
         watchdog(
1224
-          'boinctranslate',
1225
-          'The translation file %filename for %lang contains an error: "msgid" is unexpected on line %line.',
1226
-          array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1227
-          WATCHDOG_WARNING
1224
+            'boinctranslate',
1225
+            'The translation file %filename for %lang contains an error: "msgid" is unexpected on line %line.',
1226
+            array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1227
+            WATCHDOG_WARNING
1228 1228
         );
1229 1229
         _locale_import_message('The translation file %filename contains an error: "msgid" is unexpected on line %line.', $file, $lineno);
1230 1230
         return FALSE;
1231
-      }
1232
-      $line = trim(substr($line, 5));
1233
-      $quoted = _locale_import_parse_quoted($line);
1234
-      if ($quoted === FALSE) {
1231
+        }
1232
+        $line = trim(substr($line, 5));
1233
+        $quoted = _locale_import_parse_quoted($line);
1234
+        if ($quoted === FALSE) {
1235 1235
         watchdog(
1236
-          'boinctranslate',
1237
-          'The translation file %filename for language %lang contains a syntax error on line %line.',
1238
-          array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1239
-          WATCHDOG_WARNING
1236
+            'boinctranslate',
1237
+            'The translation file %filename for language %lang contains a syntax error on line %line.',
1238
+            array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1239
+            WATCHDOG_WARNING
1240 1240
         );
1241 1241
         _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno);
1242 1242
         return FALSE;
1243
-      }
1244
-      $current["msgid"] = $quoted;
1245
-      $context = "MSGID";
1243
+        }
1244
+        $current["msgid"] = $quoted;
1245
+        $context = "MSGID";
1246 1246
     }
1247 1247
     elseif (!strncmp("msgstr[", $line, 7)) {
1248
-      if (($context != "MSGID") && ($context != "MSGID_PLURAL") && ($context != "MSGSTR_ARR")) { // Must come after msgid, msgid_plural, or msgstr[]
1248
+        if (($context != "MSGID") && ($context != "MSGID_PLURAL") && ($context != "MSGSTR_ARR")) { // Must come after msgid, msgid_plural, or msgstr[]
1249 1249
         watchdog(
1250
-          'boinctranslate',
1251
-          'The translation file %filename for %lang contains an error: "msgstr[]" is unexpected on line %line.',
1252
-          array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1253
-          WATCHDOG_WARNING
1250
+            'boinctranslate',
1251
+            'The translation file %filename for %lang contains an error: "msgstr[]" is unexpected on line %line.',
1252
+            array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1253
+            WATCHDOG_WARNING
1254 1254
         );
1255 1255
         _locale_import_message('The translation file %filename contains an error: "msgstr[]" is unexpected on line %line.', $file, $lineno);
1256 1256
         return FALSE;
1257
-      }
1258
-      if (strpos($line, "]") === FALSE) {
1257
+        }
1258
+        if (strpos($line, "]") === FALSE) {
1259 1259
         watchdog(
1260
-          'boinctranslate',
1261
-          'The translation file %filename for language %lang contains a syntax error on line %line.',
1262
-          array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1263
-          WATCHDOG_WARNING
1260
+            'boinctranslate',
1261
+            'The translation file %filename for language %lang contains a syntax error on line %line.',
1262
+            array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1263
+            WATCHDOG_WARNING
1264 1264
         );
1265 1265
         _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno);
1266 1266
         return FALSE;
1267
-      }
1268
-      $frombracket = strstr($line, "[");
1269
-      $plural = substr($frombracket, 1, strpos($frombracket, "]") - 1);
1270
-      $line = trim(strstr($line, " "));
1271
-      $quoted = _locale_import_parse_quoted($line);
1272
-      if ($quoted === FALSE) {
1267
+        }
1268
+        $frombracket = strstr($line, "[");
1269
+        $plural = substr($frombracket, 1, strpos($frombracket, "]") - 1);
1270
+        $line = trim(strstr($line, " "));
1271
+        $quoted = _locale_import_parse_quoted($line);
1272
+        if ($quoted === FALSE) {
1273 1273
         watchdog(
1274
-          'boinctranslate',
1275
-          'The translation file %filename for language %lang contains a syntax error on line %line.',
1276
-          array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1277
-          WATCHDOG_WARNING
1274
+            'boinctranslate',
1275
+            'The translation file %filename for language %lang contains a syntax error on line %line.',
1276
+            array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1277
+            WATCHDOG_WARNING
1278 1278
         );
1279 1279
         _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno);
1280 1280
         return FALSE;
1281
-      }
1282
-      $current["msgstr"][$plural] = $quoted;
1283
-      $context = "MSGSTR_ARR";
1281
+        }
1282
+        $current["msgstr"][$plural] = $quoted;
1283
+        $context = "MSGSTR_ARR";
1284 1284
     }
1285 1285
     elseif (!strncmp("msgstr", $line, 6)) {
1286
-      if ($context != "MSGID") { // Should come just after a msgid block
1286
+        if ($context != "MSGID") { // Should come just after a msgid block
1287 1287
         watchdog(
1288
-          'boinctranslate',
1289
-          'The translation file %filename for %lang contains an error: "msgstr" is unexpected on line %line.',
1290
-          array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1291
-          WATCHDOG_WARNING
1288
+            'boinctranslate',
1289
+            'The translation file %filename for %lang contains an error: "msgstr" is unexpected on line %line.',
1290
+            array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1291
+            WATCHDOG_WARNING
1292 1292
         );
1293 1293
         _locale_import_message('The translation file %filename contains an error: "msgstr" is unexpected on line %line.', $file, $lineno);
1294 1294
         return FALSE;
1295
-      }
1296
-      $line = trim(substr($line, 6));
1297
-      $quoted = _locale_import_parse_quoted($line);
1298
-      if ($quoted === FALSE) {
1295
+        }
1296
+        $line = trim(substr($line, 6));
1297
+        $quoted = _locale_import_parse_quoted($line);
1298
+        if ($quoted === FALSE) {
1299 1299
         watchdog(
1300
-          'boinctranslate',
1301
-          'The translation file %filename for language %lang contains a syntax error on line %line.',
1302
-          array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1303
-          WATCHDOG_WARNING
1300
+            'boinctranslate',
1301
+            'The translation file %filename for language %lang contains a syntax error on line %line.',
1302
+            array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1303
+            WATCHDOG_WARNING
1304 1304
         );
1305 1305
         _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno);
1306 1306
         return FALSE;
1307
-      }
1308
-      $current["msgstr"] = $quoted;
1309
-      $context = "MSGSTR";
1307
+        }
1308
+        $current["msgstr"] = $quoted;
1309
+        $context = "MSGSTR";
1310 1310
     }
1311 1311
     elseif ($line != "") {
1312
-      $quoted = _locale_import_parse_quoted($line);
1313
-      if ($quoted === FALSE) {
1312
+        $quoted = _locale_import_parse_quoted($line);
1313
+        if ($quoted === FALSE) {
1314 1314
         watchdog(
1315
-          'boinctranslate',
1316
-          'The translation file %filename for language %lang contains a syntax error on line %line.',
1317
-          array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1318
-          WATCHDOG_WARNING
1315
+            'boinctranslate',
1316
+            'The translation file %filename for language %lang contains a syntax error on line %line.',
1317
+            array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1318
+            WATCHDOG_WARNING
1319 1319
         );
1320 1320
         _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno);
1321 1321
         return FALSE;
1322
-      }
1323
-      if (($context == "MSGID") || ($context == "MSGID_PLURAL")) {
1322
+        }
1323
+        if (($context == "MSGID") || ($context == "MSGID_PLURAL")) {
1324 1324
         $current["msgid"] .= $quoted;
1325
-      }
1326
-      elseif ($context == "MSGSTR") {
1325
+        }
1326
+        elseif ($context == "MSGSTR") {
1327 1327
         $current["msgstr"] .= $quoted;
1328
-      }
1329
-      elseif ($context == "MSGSTR_ARR") {
1328
+        }
1329
+        elseif ($context == "MSGSTR_ARR") {
1330 1330
         $current["msgstr"][$plural] .= $quoted;
1331
-      }
1332
-      else {
1331
+        }
1332
+        else {
1333 1333
         watchdog(
1334
-          'boinctranslate',
1335
-          'The translation file %filename for %lang contains an error: there is an unexpected string on line %line.',
1336
-          array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1337
-          WATCHDOG_WARNING
1334
+            'boinctranslate',
1335
+            'The translation file %filename for %lang contains an error: there is an unexpected string on line %line.',
1336
+            array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1337
+            WATCHDOG_WARNING
1338 1338
         );
1339 1339
         _locale_import_message('The translation file %filename contains an error: there is an unexpected string on line %line.', $file, $lineno);
1340 1340
         return FALSE;
1341
-      }
1341
+        }
1342
+    }
1342 1343
     }
1343
-  }
1344 1344
 
1345
-  // End of PO file, flush last entry
1346
-  if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) {
1345
+    // End of PO file, flush last entry
1346
+    if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) {
1347 1347
     _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group);
1348
-  }
1349
-  elseif ($context != "COMMENT") {
1348
+    }
1349
+    elseif ($context != "COMMENT") {
1350 1350
     watchdog(
1351
-      'boinctranslate',
1352
-      'The translation file %filename for %lang ended unexpectedly at line %line.',
1353
-      array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1354
-      WATCHDOG_WARNING
1351
+        'boinctranslate',
1352
+        'The translation file %filename for %lang ended unexpectedly at line %line.',
1353
+        array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno),
1354
+        WATCHDOG_WARNING
1355 1355
     );
1356 1356
     _locale_import_message('The translation file %filename ended unexpectedly at line %line.', $file, $lineno);
1357 1357
     return FALSE;
1358
-  }
1358
+    }
1359 1359
 
1360 1360
 }
1361 1361
 
@@ -1364,28 +1364,28 @@  discard block
 block discarded – undo
1364 1364
  */
1365 1365
 function _boinctranslate_locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NULL, $file = NULL, $group = 'default') {
1366 1366
   
1367
-  require_once(getcwd() . '/includes/locale.inc');
1367
+    require_once(getcwd() . '/includes/locale.inc');
1368 1368
   
1369
-  static $report = array(
1369
+    static $report = array(
1370 1370
     'additions' => 0,
1371 1371
     'updates' => 0,
1372 1372
     'deletes' => 0,
1373 1373
     'skips' => 0,
1374
-  );
1375
-  static $headerdone = FALSE;
1376
-  static $strings = array();
1374
+    );
1375
+    static $headerdone = FALSE;
1376
+    static $strings = array();
1377 1377
 
1378
-  switch ($op) {
1378
+    switch ($op) {
1379 1379
     // Return stored strings
1380 1380
     case 'mem-report':
1381 1381
       return $strings;
1382 1382
 
1383
-      // Store string in memory (only supports single strings)
1383
+        // Store string in memory (only supports single strings)
1384 1384
     case 'mem-store':
1385 1385
       $strings[$value['msgid']] = $value['msgstr'];
1386
-      return;
1386
+        return;
1387 1387
 
1388
-      // Called at end of import to inform the user
1388
+        // Called at end of import to inform the user
1389 1389
     case 'db-report':
1390 1390
       return array(
1391 1391
         $headerdone,
@@ -1393,115 +1393,115 @@  discard block
 block discarded – undo
1393 1393
         $report['updates'],
1394 1394
         $report['deletes'],
1395 1395
         $report['skips'],
1396
-      );
1396
+        );
1397 1397
 
1398
-      // Store the string we got in the database.
1398
+        // Store the string we got in the database.
1399 1399
     case 'db-store':
1400 1400
       // We got header information.
1401 1401
       if ($value['msgid'] == '') {
1402 1402
         $languages = language_list();
1403 1403
         if (($mode != LOCALE_IMPORT_KEEP) || empty($languages[$lang]->plurals)) {
1404
-          // Since we only need to parse the header if we ought to update the
1405
-          // plural formula, only run this if we don't need to keep existing
1406
-          // data untouched or if we don't have an existing plural formula.
1407
-          $header = _locale_import_parse_header($value['msgstr']);
1404
+            // Since we only need to parse the header if we ought to update the
1405
+            // plural formula, only run this if we don't need to keep existing
1406
+            // data untouched or if we don't have an existing plural formula.
1407
+            $header = _locale_import_parse_header($value['msgstr']);
1408 1408
 
1409
-          // Get and store the plural formula if available.
1410
-          if (isset($header["Plural-Forms"]) && $p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->filename)) {
1409
+            // Get and store the plural formula if available.
1410
+            if (isset($header["Plural-Forms"]) && $p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->filename)) {
1411 1411
             list($nplurals, $plural) = $p;
1412 1412
             db_query("UPDATE {languages} SET plurals = %d, formula = '%s' WHERE language = '%s'", $nplurals, $plural, $lang);
1413
-          }
1413
+            }
1414 1414
         }
1415 1415
         $headerdone = TRUE;
1416
-      }
1416
+        }
1417 1417
 
1418
-      else {
1418
+        else {
1419 1419
         // Some real string to import.
1420 1420
         $comments = _locale_import_shorten_comments(empty($value['#']) ? array() : $value['#']);
1421 1421
 
1422 1422
         if (strpos($value['msgid'], "\0")) {
1423
-          // This string has plural versions.
1424
-          $english = explode("\0", $value['msgid'], 2);
1425
-          $entries = array_keys($value['msgstr']);
1426
-          for ($i = 3; $i <= count($entries); $i++) {
1423
+            // This string has plural versions.
1424
+            $english = explode("\0", $value['msgid'], 2);
1425
+            $entries = array_keys($value['msgstr']);
1426
+            for ($i = 3; $i <= count($entries); $i++) {
1427 1427
             $english[] = $english[1];
1428
-          }
1429
-          $translation = array_map('_locale_import_append_plural', $value['msgstr'], $entries);
1430
-          $english = array_map('_locale_import_append_plural', $english, $entries);
1431
-          foreach ($translation as $key => $trans) {
1428
+            }
1429
+            $translation = array_map('_locale_import_append_plural', $value['msgstr'], $entries);
1430
+            $english = array_map('_locale_import_append_plural', $english, $entries);
1431
+            foreach ($translation as $key => $trans) {
1432 1432
             if ($key == 0) {
1433
-              $plid = 0;
1433
+                $plid = 0;
1434 1434
             }
1435 1435
             $plid = _boinctranslate_locale_import_one_string_db($report, $lang, $english[$key], $trans, $group, $comments, $mode, $plid, $key);
1436
-          }
1436
+            }
1437 1437
         }
1438 1438
 
1439 1439
         else {
1440
-          // A simple string to import.
1441
-          $english = $value['msgid'];
1442
-          $translation = $value['msgstr'];
1443
-          _boinctranslate_locale_import_one_string_db($report, $lang, $english, $translation, $group, $comments, $mode);
1440
+            // A simple string to import.
1441
+            $english = $value['msgid'];
1442
+            $translation = $value['msgstr'];
1443
+            _boinctranslate_locale_import_one_string_db($report, $lang, $english, $translation, $group, $comments, $mode);
1444 1444
         }
1445
-      }
1446
-  } // end of db-store operation
1445
+        }
1446
+    } // end of db-store operation
1447 1447
 }
1448 1448
 
1449 1449
 /**
1450 1450
  * Modify the _locale_import_one_string_db() function so that it does not add
1451 1451
  * translation strings that do not exist on the site
1452 1452
  */
1453
- function _boinctranslate_locale_import_one_string_db(&$report, $langcode, $source, $translation, $textgroup, $location, $mode, $plid = NULL, $plural = NULL) {
1454
-  $lid = db_result(db_query("SELECT lid FROM {locales_source} WHERE location = '%s' AND source = '%s' AND textgroup = '%s'", $location, $source, $textgroup));
1453
+    function _boinctranslate_locale_import_one_string_db(&$report, $langcode, $source, $translation, $textgroup, $location, $mode, $plid = NULL, $plural = NULL) {
1454
+    $lid = db_result(db_query("SELECT lid FROM {locales_source} WHERE location = '%s' AND source = '%s' AND textgroup = '%s'", $location, $source, $textgroup));
1455 1455
 
1456
-  if (!empty($translation)) {
1456
+    if (!empty($translation)) {
1457 1457
     // Skip this string unless it passes a check for dangerous code.
1458 1458
     // Text groups other than default still can contain HTML tags
1459 1459
     // (i.e. translatable blocks).
1460 1460
     if ($textgroup == "default" && !locale_string_is_safe($translation)) {
1461
-      $report['skips']++;
1462
-      $lid = 0;
1461
+        $report['skips']++;
1462
+        $lid = 0;
1463 1463
     }
1464 1464
     elseif ($lid) {
1465
-      // We have this source string saved already.
1466
-      // Don't update location, that just makes Drupal add the same strings
1467
-      // over and over
1468
-      //db_query("UPDATE {locales_source} SET location = '%s' WHERE lid = %d", $location, $lid);
1469
-      $exists = (bool) db_result(db_query("SELECT lid FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $langcode));
1470
-      if (!$exists) {
1465
+        // We have this source string saved already.
1466
+        // Don't update location, that just makes Drupal add the same strings
1467
+        // over and over
1468
+        //db_query("UPDATE {locales_source} SET location = '%s' WHERE lid = %d", $location, $lid);
1469
+        $exists = (bool) db_result(db_query("SELECT lid FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $langcode));
1470
+        if (!$exists) {
1471 1471
         // No translation in this language.
1472 1472
         db_query("INSERT INTO {locales_target} (lid, language, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $langcode, $translation, $plid, $plural);
1473 1473
         $report['additions']++;
1474
-      }
1475
-      else if ($mode == LOCALE_IMPORT_OVERWRITE) {
1474
+        }
1475
+        else if ($mode == LOCALE_IMPORT_OVERWRITE) {
1476 1476
         // Translation exists, only overwrite if instructed.
1477 1477
         db_query("UPDATE {locales_target} SET translation = '%s', plid = %d, plural = %d WHERE language = '%s' AND lid = %d", $translation, $plid, $plural, $langcode, $lid);
1478 1478
         $report['updates']++;
1479
-      }
1479
+        }
1480 1480
     }
1481 1481
     else {
1482
-      // No such source string in the database yet.
1483
-      // Do not insert the source string if it does not belong on the site!
1484
-      /*
1482
+        // No such source string in the database yet.
1483
+        // Do not insert the source string if it does not belong on the site!
1484
+        /*
1485 1485
       db_query("INSERT INTO {locales_source} (location, source, textgroup) VALUES ('%s', '%s', '%s')", $location, $source, $textgroup);
1486 1486
       $lid = db_result(db_query("SELECT lid FROM {locales_source} WHERE source = '%s' AND textgroup = '%s'", $source, $textgroup));
1487 1487
       db_query("INSERT INTO {locales_target} (lid, language, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $langcode, $translation, $plid, $plural);
1488 1488
       $report['additions']++;
1489 1489
       */
1490 1490
     }
1491
-  }
1492
-  elseif ($mode == LOCALE_IMPORT_OVERWRITE AND $lid) {
1491
+    }
1492
+    elseif ($mode == LOCALE_IMPORT_OVERWRITE AND $lid) {
1493 1493
     $exists = (bool) db_result(db_query("SELECT lid FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $langcode));
1494 1494
     if ($exists) {
1495
-      // Empty translation, remove existing if instructed.
1496
-      db_query("DELETE FROM {locales_target} WHERE language = '%s' AND lid = %d AND plid = %d AND plural = %d", $langcode, $lid, $plid, $plural);
1497
-      $report['deletes']++;
1495
+        // Empty translation, remove existing if instructed.
1496
+        db_query("DELETE FROM {locales_target} WHERE language = '%s' AND lid = %d AND plid = %d AND plural = %d", $langcode, $lid, $plid, $plural);
1497
+        $report['deletes']++;
1498 1498
     }
1499
-  }
1500
-  else {
1499
+    }
1500
+    else {
1501 1501
     $report['skips']++;
1502
-  }
1502
+    }
1503 1503
 
1504
-  return $lid;
1504
+    return $lid;
1505 1505
 }
1506 1506
 
1507 1507
 
@@ -1510,15 +1510,15 @@  discard block
 block discarded – undo
1510 1510
  * Parse valid resources out of configuration
1511 1511
  */
1512 1512
 function boinctranslate_parse_resources($resource_text) {
1513
-  $resources = array();
1514
-  $resource_array = explode(
1513
+    $resources = array();
1514
+    $resource_array = explode(
1515 1515
     "\n", $resource_text
1516
-  );
1517
-  foreach ($resource_array as $resource) {
1516
+    );
1517
+    foreach ($resource_array as $resource) {
1518 1518
     $resource = trim($resource);
1519 1519
     if ($resource AND $resource[0] != '#') {
1520
-      $resources[] = $resource;
1520
+        $resources[] = $resource;
1521 1521
     }
1522
-  }
1523
-  return $resources;
1522
+    }
1523
+    return $resources;
1524 1524
 }
Please login to merge, or discard this patch.
Braces   +71 added lines, -124 removed lines patch added patch discarded remove patch
@@ -120,8 +120,7 @@  discard block
 block discarded – undo
120 120
           'Updated translation source strings for node @nid.',
121 121
           array('@nid' => $node->nid)
122 122
         );
123
-      }
124
-      else {
123
+      } else {
125 124
         drupal_set_message(
126 125
           t('Unable to update translation source strings.'), 'error'
127 126
         );
@@ -132,8 +131,7 @@  discard block
 block discarded – undo
132 131
           WATCHDOG_ERROR
133 132
         );
134 133
       }
135
-    }
136
-    else {
134
+    } else {
137 135
       $result = db_query("
138 136
         INSERT INTO {locales_source}
139 137
         SET location = '%s', textgroup = '%s', source = '%s'",
@@ -145,8 +143,7 @@  discard block
 block discarded – undo
145 143
           'Added translation source strings for node @nid.',
146 144
           array('@nid' => $node->nid)
147 145
         );
148
-      }
149
-      else {
146
+      } else {
150 147
         drupal_set_message(
151 148
           t('Unable to add translation source strings.'), 'error'
152 149
         );
@@ -230,8 +227,7 @@  discard block
 block discarded – undo
230 227
           )
231 228
         ), 'warning'
232 229
       );
233
-    }
234
-    elseif ($response) {
230
+    } elseif ($response) {
235 231
       if (is_array($response)) {
236 232
       
237 233
         $installed_languages = language_list();
@@ -261,8 +257,7 @@  discard block
 block discarded – undo
261 257
                 'Added predefined language: '.$available_languages[$rfc_code][0]
262 258
               );
263 259
               db_query("UPDATE {languages} SET enabled = 1 WHERE language = '%s'", $rfc_code);
264
-            }
265
-            else {
260
+            } else {
266 261
               // Retrieve language details from Transifex
267 262
               $path = "language/{$posix_code}";
268 263
               $response = boinctranslate_transifex_request($path);
@@ -275,8 +270,7 @@  discard block
 block discarded – undo
275 270
                     )
276 271
                   ), 'warning'
277 272
                 );
278
-              }
279
-              elseif ($response) {
273
+              } elseif ($response) {
280 274
                 if (!empty($response['name'])) {
281 275
                   // Add a custom language to Drupal and enable
282 276
                   locale_add_language(
@@ -291,8 +285,7 @@  discard block
 block discarded – undo
291 285
                   drupal_set_message(
292 286
                     'Added new language: '.$response['name']
293 287
                   );
294
-                }
295
-                else {
288
+                } else {
296 289
                   $variables = array(
297 290
                     '%code' => $posix_code,
298 291
                   );
@@ -307,8 +300,7 @@  discard block
 block discarded – undo
307 300
                     WATCHDOG_ERROR
308 301
                   );
309 302
                 }
310
-              }
311
-              else {
303
+              } else {
312 304
                $variables = array(
313 305
                   '%code' => $posix_code,
314 306
                 );
@@ -349,8 +341,7 @@  discard block
 block discarded – undo
349 341
           batch_set($batch);
350 342
           batch_process('admin/boinc/translation');
351 343
         }
352
-      }
353
-      else {
344
+      } else {
354 345
         $variables = array(
355 346
           '%project' => $project_name,
356 347
         );
@@ -365,8 +356,7 @@  discard block
 block discarded – undo
365 356
           WATCHDOG_ERROR
366 357
         );
367 358
       }
368
-    }
369
-    else {
359
+    } else {
370 360
      $variables = array(
371 361
         '%project' => $project_name,
372 362
       );
@@ -423,8 +413,7 @@  discard block
 block discarded – undo
423 413
           'content' => boinctranslate_get_po('en', 'project'),
424 414
         );
425 415
         $result = boinctranslate_transifex_request($path, $post);
426
-      }
427
-      else {
416
+      } else {
428 417
         // Update the source
429 418
         $path = "project/{$project_name}/resource/{$primary_resource}/content";
430 419
         $post = array(
@@ -438,8 +427,7 @@  discard block
 block discarded – undo
438 427
       $enabled_languages = locale_language_list();
439 428
       if ($source_exists) {
440 429
         drupal_set_message('Updated source translation strings at Transifex');
441
-      }
442
-      else {
430
+      } else {
443 431
         drupal_set_message('Established new translation resource at Transifex');
444 432
       }
445 433
       // Try to export translations for all enabled languages
@@ -460,25 +448,21 @@  discard block
 block discarded – undo
460 448
               "Unable to update {$language_name} translations: {$result}",
461 449
               'warning'
462 450
             );
463
-          }
464
-          else {
451
+          } else {
465 452
             drupal_set_message("Updated {$language_name} translations");
466 453
             //drupal_set_message('DEBUG: <pre>'.print_r($result,1).'</pre>');
467 454
           }
468
-        }
469
-        else {
455
+        } else {
470 456
           drupal_set_message("No translations to export for {$language_name}");
471 457
         }
472 458
       }
473
-    }
474
-    else {
459
+    } else {
475 460
       drupal_set_message(
476 461
         "Unable to update the translation source: {$result}",
477 462
         'warning'
478 463
       );
479 464
     }
480
-  }
481
-  else {
465
+  } else {
482 466
     drupal_set_message(
483 467
       'Failed to export translations: Transifex settings are not intiailized.',
484 468
       'error'
@@ -534,42 +518,35 @@  discard block
 block discarded – undo
534 518
                 "Unable to update {$language_name} official BOINC translations: {$result}",
535 519
                 'warning'
536 520
               );
537
-            }
538
-            elseif ($result == '401 UNAUTHORIZED') {
521
+            } elseif ($result == '401 UNAUTHORIZED') {
539 522
               drupal_set_message(
540 523
                 'Not authorized to update official BOINC translations',
541 524
                 'warning'
542 525
               );
543 526
               break;
544
-            }
545
-            elseif ($result == 'success') {
527
+            } elseif ($result == 'success') {
546 528
               drupal_set_message("Updated {$language_name} official BOINC translations");
547
-            }
548
-            else {
529
+            } else {
549 530
               drupal_set_message(
550 531
                 "Unexpected response for {$language_name}: {$result}",
551 532
                 'warning'
552 533
               );
553 534
             }
554
-          }
555
-          else {
535
+          } else {
556 536
             drupal_set_message("Updated {$language_name} official BOINC translations");
557 537
             //drupal_set_message('DEBUG: <pre>'.print_r($result,1).'</pre>');
558 538
           }
559
-        }
560
-        else {
539
+        } else {
561 540
           drupal_set_message("No official BOINC translations to export for {$language_name}");
562 541
         }
563 542
       }
564
-    }
565
-    else {
543
+    } else {
566 544
       drupal_set_message(
567 545
         "The {$drupal_resource} resource does not exist in the {$project_name} project at Transifex",
568 546
         'warning'
569 547
       );
570 548
     }
571
-  }
572
-  else {
549
+  } else {
573 550
     drupal_set_message(
574 551
       'Failed to export official BOINC translations: Transifex settings are not intiailized.',
575 552
       'error'
@@ -594,8 +571,12 @@  discard block
 block discarded – undo
594 571
   
595 572
   // Transifex details
596 573
   $api_base_url = 'https://www.transifex.com/api/2';
597
-  if (!$username) $username = variable_get('boinc_translate_transifex_user', '');
598
-  if (!$password) $password = variable_get('boinc_translate_transifex_pass', '');
574
+  if (!$username) {
575
+      $username = variable_get('boinc_translate_transifex_user', '');
576
+  }
577
+  if (!$password) {
578
+      $password = variable_get('boinc_translate_transifex_pass', '');
579
+  }
599 580
   
600 581
   $url = "{$api_base_url}/{$path}";
601 582
   $headers = array(
@@ -607,13 +588,11 @@  discard block
 block discarded – undo
607 588
     if ($json) {
608 589
       $headers['Content-Type'] = 'application/json';
609 590
       $data = json_encode($post);
610
-    }
611
-    else {
591
+    } else {
612 592
       $data = drupal_query_string_encode($post);
613 593
     }
614 594
     $method = ($use_put) ? 'PUT' : 'POST';
615
-  }
616
-  else {
595
+  } else {
617 596
     $method = 'GET';
618 597
   }
619 598
   
@@ -625,8 +604,7 @@  discard block
 block discarded – undo
625 604
     if ($json) {
626 605
       // Process as JSON
627 606
       return json_decode($response->data, TRUE);
628
-    }
629
-    else {
607
+    } else {
630 608
       return (string) $response->data;
631 609
     }
632 610
     break;
@@ -635,10 +613,14 @@  discard block
 block discarded – undo
635 613
   case 401:
636 614
     return '401 UNAUTHORIZED';
637 615
   case 400:
638
-    if ($debug_mode) watchdog('boinctranslate', "The following response was received when trying to communicate with the Transifex system: \n{$response}", array(), WATCHDOG_WARNING);
616
+    if ($debug_mode) {
617
+        watchdog('boinctranslate', "The following response was received when trying to communicate with the Transifex system: \n{$response}", array(), WATCHDOG_WARNING);
618
+    }
639 619
     return "ERROR: {$response->data}";
640 620
   case 405:
641
-    if ($debug_mode) watchdog('boinctranslate', "The following response was received when trying to communicate with the Transifex system: \n{$response}", array(), WATCHDOG_WARNING);
621
+    if ($debug_mode) {
622
+        watchdog('boinctranslate', "The following response was received when trying to communicate with the Transifex system: \n{$response}", array(), WATCHDOG_WARNING);
623
+    }
642 624
     return "ERROR: User not allowed to perform this action";
643 625
   }
644 626
   
@@ -776,18 +758,15 @@  discard block
 block discarded – undo
776 758
             if ($plural) {
777 759
               $translation = _locale_export_remove_plural($strings[$plural]['translation']);
778 760
               $plural = isset($strings[$plural]['plural']) ? $strings[$plural]['plural'] : 0;
779
-            }
780
-            else {
761
+            } else {
781 762
               $translation = '';
782 763
             }
783 764
           }
784
-        }
785
-        else {
765
+        } else {
786 766
           $output .= 'msgstr[0] ""' . "\n";
787 767
           $output .= 'msgstr[1] ""' . "\n";
788 768
         }
789
-      }
790
-      else {
769
+      } else {
791 770
         $output .= 'msgstr ' . _locale_export_string($string['translation']);
792 771
       }
793 772
       $output .= "\n";
@@ -934,8 +913,7 @@  discard block
 block discarded – undo
934 913
     
935 914
     if ($response == '404 NOT FOUND') {
936 915
       $message = "Project resource {$project}:{$resource} not found in {$language}.";
937
-    }
938
-    elseif ($response) {
916
+    } elseif ($response) {
939 917
       if (!empty($response['content'])) {
940 918
         $po_text = $response['content'];
941 919
         
@@ -956,23 +934,19 @@  discard block
 block discarded – undo
956 934
               . " {$project}:{$resource} failed.";
957 935
             $success = FALSE;
958 936
             break;
959
-          }
960
-          else {
937
+          } else {
961 938
             $success = TRUE;
962 939
           }
963 940
         }
964
-      }
965
-      else {
941
+      } else {
966 942
         $message = "Unable to read response for {$language} translation import"
967 943
           . " of {$project}:{$resource}.";
968 944
       }
969
-    }
970
-    else {
945
+    } else {
971 946
       $message = "Translation data not found in response for {$language}"
972 947
         . " translation import of {$project}:{$resource}.";
973 948
     }
974
-  }
975
-  else {
949
+  } else {
976 950
     // If project isn't specified, import as a local Drupal resource
977 951
     $project = 'drupal.local';
978 952
     $file = new stdClass();
@@ -983,8 +957,7 @@  discard block
 block discarded – undo
983 957
         . " local file {$resource} failed.";
984 958
       $success = FALSE;
985 959
       break;
986
-    }
987
-    else {
960
+    } else {
988 961
       $success = TRUE;
989 962
     }
990 963
   }
@@ -1002,8 +975,7 @@  discard block
 block discarded – undo
1002 975
         WATCHDOG_INFO
1003 976
       );
1004 977
     }
1005
-  }
1006
-  else {
978
+  } else {
1007 979
     $context['results']['failure'][] = "{$langcode}:{$textgroup}";
1008 980
     watchdog(
1009 981
       'boinctranslate',
@@ -1021,8 +993,7 @@  discard block
 block discarded – undo
1021 993
   // Update the progress for the batch engine
1022 994
   if ($context['sandbox']['progress'] >= $context['sandbox']['max']) {
1023 995
     $context['finished'] = 1;
1024
-  }
1025
-  else {
996
+  } else {
1026 997
     $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
1027 998
   }
1028 999
 }
@@ -1041,8 +1012,7 @@  discard block
 block discarded – undo
1041 1012
       array('@count' => $count),
1042 1013
       WATCHDOG_INFO
1043 1014
     ); 
1044
-  }
1045
-  else {
1015
+  } else {
1046 1016
     // An error occurred.
1047 1017
     // $operations contains the operations that remained unprocessed.
1048 1018
     $error_operation = reset($operations);
@@ -1140,14 +1110,12 @@  discard block
 block discarded – undo
1140 1110
     if (!strncmp("#", $line, 1)) { // A comment
1141 1111
       if ($context == "COMMENT") { // Already in comment context: add
1142 1112
         $current["#"][] = substr($line, 1);
1143
-      }
1144
-      elseif (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one
1113
+      } elseif (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one
1145 1114
         _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group);
1146 1115
         $current = array();
1147 1116
         $current["#"][] = substr($line, 1);
1148 1117
         $context = "COMMENT";
1149
-      }
1150
-      else { // Parse error
1118
+      } else { // Parse error
1151 1119
         watchdog(
1152 1120
           'boinctranslate',
1153 1121
           'The translation file %filename for %lang contains an error: "msgstr" was expected but not found on line %line.',
@@ -1157,13 +1125,11 @@  discard block
 block discarded – undo
1157 1125
         _locale_import_message('The translation file %filename contains an error: "msgstr" was expected but not found on line %line.', $file, $lineno);
1158 1126
         return FALSE;
1159 1127
       }
1160
-    }
1161
-    elseif (!strncmp("msgctxt", $line, 7)) {
1128
+    } elseif (!strncmp("msgctxt", $line, 7)) {
1162 1129
       if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one
1163 1130
         _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group);
1164 1131
         $current = array();
1165
-      }
1166
-      elseif (($context == "MSGID") || ($context == "MSGCTXT")) { // Already in this context? Parse error
1132
+      } elseif (($context == "MSGID") || ($context == "MSGCTXT")) { // Already in this context? Parse error
1167 1133
         watchdog(
1168 1134
           'boinctranslate',
1169 1135
           'The translation file %filename for %lang contains an error: "msgctxt" is unexpected on line %line.',
@@ -1187,8 +1153,7 @@  discard block
 block discarded – undo
1187 1153
       }
1188 1154
       $current["msgctxt"] = $quoted;
1189 1155
       $context = "MSGCTXT";
1190
-    }
1191
-    elseif (!strncmp("msgid_plural", $line, 12)) {
1156
+    } elseif (!strncmp("msgid_plural", $line, 12)) {
1192 1157
       if ($context != "MSGID") { // Must be plural form for current entry
1193 1158
         watchdog(
1194 1159
           'boinctranslate',
@@ -1213,13 +1178,11 @@  discard block
 block discarded – undo
1213 1178
       }
1214 1179
       $current["msgid"] = $current["msgid"] . "\0" . $quoted;
1215 1180
       $context = "MSGID_PLURAL";
1216
-    }
1217
-    elseif (!strncmp("msgid", $line, 5)) {
1181
+    } elseif (!strncmp("msgid", $line, 5)) {
1218 1182
       if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one
1219 1183
         _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group);
1220 1184
         $current = array();
1221
-      }
1222
-      elseif ($context == "MSGID") { // Already in this context? Parse error
1185
+      } elseif ($context == "MSGID") { // Already in this context? Parse error
1223 1186
         watchdog(
1224 1187
           'boinctranslate',
1225 1188
           'The translation file %filename for %lang contains an error: "msgid" is unexpected on line %line.',
@@ -1243,8 +1206,7 @@  discard block
 block discarded – undo
1243 1206
       }
1244 1207
       $current["msgid"] = $quoted;
1245 1208
       $context = "MSGID";
1246
-    }
1247
-    elseif (!strncmp("msgstr[", $line, 7)) {
1209
+    } elseif (!strncmp("msgstr[", $line, 7)) {
1248 1210
       if (($context != "MSGID") && ($context != "MSGID_PLURAL") && ($context != "MSGSTR_ARR")) { // Must come after msgid, msgid_plural, or msgstr[]
1249 1211
         watchdog(
1250 1212
           'boinctranslate',
@@ -1281,8 +1243,7 @@  discard block
 block discarded – undo
1281 1243
       }
1282 1244
       $current["msgstr"][$plural] = $quoted;
1283 1245
       $context = "MSGSTR_ARR";
1284
-    }
1285
-    elseif (!strncmp("msgstr", $line, 6)) {
1246
+    } elseif (!strncmp("msgstr", $line, 6)) {
1286 1247
       if ($context != "MSGID") { // Should come just after a msgid block
1287 1248
         watchdog(
1288 1249
           'boinctranslate',
@@ -1307,8 +1268,7 @@  discard block
 block discarded – undo
1307 1268
       }
1308 1269
       $current["msgstr"] = $quoted;
1309 1270
       $context = "MSGSTR";
1310
-    }
1311
-    elseif ($line != "") {
1271
+    } elseif ($line != "") {
1312 1272
       $quoted = _locale_import_parse_quoted($line);
1313 1273
       if ($quoted === FALSE) {
1314 1274
         watchdog(
@@ -1322,14 +1282,11 @@  discard block
 block discarded – undo
1322 1282
       }
1323 1283
       if (($context == "MSGID") || ($context == "MSGID_PLURAL")) {
1324 1284
         $current["msgid"] .= $quoted;
1325
-      }
1326
-      elseif ($context == "MSGSTR") {
1285
+      } elseif ($context == "MSGSTR") {
1327 1286
         $current["msgstr"] .= $quoted;
1328
-      }
1329
-      elseif ($context == "MSGSTR_ARR") {
1287
+      } elseif ($context == "MSGSTR_ARR") {
1330 1288
         $current["msgstr"][$plural] .= $quoted;
1331
-      }
1332
-      else {
1289
+      } else {
1333 1290
         watchdog(
1334 1291
           'boinctranslate',
1335 1292
           'The translation file %filename for %lang contains an error: there is an unexpected string on line %line.',
@@ -1345,8 +1302,7 @@  discard block
 block discarded – undo
1345 1302
   // End of PO file, flush last entry
1346 1303
   if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) {
1347 1304
     _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group);
1348
-  }
1349
-  elseif ($context != "COMMENT") {
1305
+  } elseif ($context != "COMMENT") {
1350 1306
     watchdog(
1351 1307
       'boinctranslate',
1352 1308
       'The translation file %filename for %lang ended unexpectedly at line %line.',
@@ -1413,9 +1369,7 @@  discard block
 block discarded – undo
1413 1369
           }
1414 1370
         }
1415 1371
         $headerdone = TRUE;
1416
-      }
1417
-
1418
-      else {
1372
+      } else {
1419 1373
         // Some real string to import.
1420 1374
         $comments = _locale_import_shorten_comments(empty($value['#']) ? array() : $value['#']);
1421 1375
 
@@ -1434,9 +1388,7 @@  discard block
 block discarded – undo
1434 1388
             }
1435 1389
             $plid = _boinctranslate_locale_import_one_string_db($report, $lang, $english[$key], $trans, $group, $comments, $mode, $plid, $key);
1436 1390
           }
1437
-        }
1438
-
1439
-        else {
1391
+        } else {
1440 1392
           // A simple string to import.
1441 1393
           $english = $value['msgid'];
1442 1394
           $translation = $value['msgstr'];
@@ -1460,8 +1412,7 @@  discard block
 block discarded – undo
1460 1412
     if ($textgroup == "default" && !locale_string_is_safe($translation)) {
1461 1413
       $report['skips']++;
1462 1414
       $lid = 0;
1463
-    }
1464
-    elseif ($lid) {
1415
+    } elseif ($lid) {
1465 1416
       // We have this source string saved already.
1466 1417
       // Don't update location, that just makes Drupal add the same strings
1467 1418
       // over and over
@@ -1471,14 +1422,12 @@  discard block
 block discarded – undo
1471 1422
         // No translation in this language.
1472 1423
         db_query("INSERT INTO {locales_target} (lid, language, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $langcode, $translation, $plid, $plural);
1473 1424
         $report['additions']++;
1474
-      }
1475
-      else if ($mode == LOCALE_IMPORT_OVERWRITE) {
1425
+      } else if ($mode == LOCALE_IMPORT_OVERWRITE) {
1476 1426
         // Translation exists, only overwrite if instructed.
1477 1427
         db_query("UPDATE {locales_target} SET translation = '%s', plid = %d, plural = %d WHERE language = '%s' AND lid = %d", $translation, $plid, $plural, $langcode, $lid);
1478 1428
         $report['updates']++;
1479 1429
       }
1480
-    }
1481
-    else {
1430
+    } else {
1482 1431
       // No such source string in the database yet.
1483 1432
       // Do not insert the source string if it does not belong on the site!
1484 1433
       /*
@@ -1488,16 +1437,14 @@  discard block
 block discarded – undo
1488 1437
       $report['additions']++;
1489 1438
       */
1490 1439
     }
1491
-  }
1492
-  elseif ($mode == LOCALE_IMPORT_OVERWRITE AND $lid) {
1440
+  } elseif ($mode == LOCALE_IMPORT_OVERWRITE AND $lid) {
1493 1441
     $exists = (bool) db_result(db_query("SELECT lid FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $langcode));
1494 1442
     if ($exists) {
1495 1443
       // Empty translation, remove existing if instructed.
1496 1444
       db_query("DELETE FROM {locales_target} WHERE language = '%s' AND lid = %d AND plid = %d AND plural = %d", $langcode, $lid, $plid, $plural);
1497 1445
       $report['deletes']++;
1498 1446
     }
1499
-  }
1500
-  else {
1447
+  } else {
1501 1448
     $report['skips']++;
1502 1449
   }
1503 1450
 
Please login to merge, or discard this patch.