language.module 23.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php

/**
 * @file
 * Add language handling functionality to Drupal.
 */

/**
 * Implements hook_help().
 */
function language_help($path, $arg) {
  switch ($path) {
    case 'admin/help#language':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
16
      $output .= '<p>' . t('The Language module allows you to maintain a list of languages used on your Drupal site for providing language information for content and for interface translation (using the Locale module). For more information, see the online handbook entry for <a href="@language">Language module</a>.', array('@language' => 'http://drupal.org/documentation/modules/language')) . '</p>';
17
18
19
20
      $output .= '<h3>' . t('Uses') . '</h3>';
      $output .= '<dl>';
      $output .= '<dt>' . t('Configuring the list of languages') . '</dt>';
      $output .= '<dd>' . t('<a href="@configure-languages">Configure the list of languages</a> either using the built-in language list or providing any custom languages you wish.', array('@configure-languages' => url('admin/config/regional/language'))) . '</dd>';
21
22
      $output .= '<dt>' . t('Configuring a multilingual site') . '</dt>';
      $output .= '<dd>' . t("Language negotiation allows your site to automatically change language based on the domain or path used for each request. Users may (optionally) select their preferred language on their <em>My account</em> page, and your site can be configured to honor a web browser's preferred language settings. Site content can be translated using the <a href='@content-help'>Content Translation module</a>.", array('@content-help' => url('admin/help/translation'))) . '</dd>';
23
24
25
26
27
28
29
30
      $output .= '</dl>';
      return $output;

    case 'admin/config/regional/language':
      return '<p>' . t('With multiple languages enabled, registered users may select their preferred language and authors can assign a specific language to content.') . '</p>';

    case 'admin/config/regional/language/add':
      return '<p>' . t('Add a language to be supported by your site. If your desired language is not available, pick <em>Custom language...</em> at the end and provide a language code and other details manually.') . '</p>';
31
32
33
34
35
36
37
38
39

    case 'admin/config/regional/language/detection':
      $output = '<p>' . t("Define how to decide which language is used to display page elements (primarily text provided by Drupal and modules, such as field labels and help text). This decision is made by evaluating a series of detection methods for languages; the first detection method that gets a result will determine which language is used for that type of text. Define the order of evaluation of language detection methods on this page.") . '</p>';
      return $output;

    case 'admin/config/regional/language/detection/session':
      $output = '<p>' . t('Determine the language from a request/session parameter. Example: "http://example.com?language=de" sets language to German based on the use of "de" within the "language" parameter.') . '</p>';
      return $output;

40
41
42
43
    case 'admin/config/regional/language/detection/browser':
      $output = '<p>' . t('Browsers use different language codes to refer to the same languages. You can add and edit mappings from browser language codes to the <a href="@configure-languages">languages used by Drupal</a>.', array('@configure-languages' => url('admin/config/regional/language'))) . '</p>';
      return $output;

44
45
46
47
48
49
    case 'admin/config/regional/language/detection/selected':
      $output = '<p>' . t('Changing the selected language here (and leaving this option as the last among the detection and selection options) is the easiest way to change the fallback language for the website, if you need to change how your site works by default (eg. when using an empty path prefix or using the default domain). <a href="@admin-change-language">Changing the site\'s default language</a> itself might have other undesired side effects.
', array('@admin-change-language' => url('admin/config/regional/language'))) . '</p>';

      return $output;

50
51
    case 'admin/structure/block/manage/%/%':
      if ($arg[4] == 'language' && $arg[5] == 'language_interface') {
52
        return '<p>' . t('With multiple languages enabled, registered users can select their preferred language and authors can assign a specific language to content.') . '</p>';
53
54
      }
      break;
55
56
57
58
59
60
61
  }
}

/**
 * Implements hook_menu().
 */
function language_menu() {
62
  // Base language management and configuration.
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
  $items['admin/config/regional/language'] = array(
    'title' => 'Languages',
    'description' => 'Configure languages for content and the user interface.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('language_admin_overview_form'),
    'access arguments' => array('administer languages'),
    'file' => 'language.admin.inc',
    'weight' => -10,
  );
  $items['admin/config/regional/language/list'] = array(
    'title' => 'List',
    'weight' => 0,
    'type' => MENU_DEFAULT_LOCAL_TASK,
  );
  $items['admin/config/regional/language/add'] = array(
    'title' => 'Add language',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('language_admin_add_form'),
    'access arguments' => array('administer languages'),
    'weight' => 5,
    'type' => MENU_LOCAL_ACTION,
    'file' => 'language.admin.inc',
  );
  $items['admin/config/regional/language/edit/%language'] = array(
    'title' => 'Edit language',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('language_admin_edit_form', 5),
90
91
    'access callback' => 'language_access_language_edit_or_delete',
    'access arguments' => array(5),
92
93
94
95
96
97
    'file' => 'language.admin.inc',
  );
  $items['admin/config/regional/language/delete/%language'] = array(
    'title' => 'Confirm delete',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('language_admin_delete_form', 5),
98
99
    'access callback' => 'language_access_language_edit_or_delete',
    'access arguments' => array(5),
100
101
    'file' => 'language.admin.inc',
  );
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128

  // Language negotiation.
  $items['admin/config/regional/language/detection'] = array(
    'title' => 'Detection and selection',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('language_negotiation_configure_form'),
    'access arguments' => array('administer languages'),
    'weight' => 10,
    'file' => 'language.admin.inc',
    'type' => MENU_LOCAL_TASK,
  );
  $items['admin/config/regional/language/detection/url'] = array(
    'title' => 'URL language detection configuration',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('language_negotiation_configure_url_form'),
    'access arguments' => array('administer languages'),
    'file' => 'language.admin.inc',
    'type' => MENU_VISIBLE_IN_BREADCRUMB,
  );
  $items['admin/config/regional/language/detection/session'] = array(
    'title' => 'Session language detection configuration',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('language_negotiation_configure_session_form'),
    'access arguments' => array('administer languages'),
    'file' => 'language.admin.inc',
    'type' => MENU_VISIBLE_IN_BREADCRUMB,
  );
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  $items['admin/config/regional/language/detection/browser'] = array(
    'title' => 'Browser language detection configuration',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('language_negotiation_configure_browser_form'),
    'access arguments' => array('administer languages'),
    'file' => 'language.admin.inc',
    'type' => MENU_VISIBLE_IN_BREADCRUMB,
  );
  $items['admin/config/regional/language/detection/browser/delete/%'] = array(
    'title' => 'Delete language mapping',
    'page arguments' => array('language_negotiation_configure_browser_delete_form', 7),
    'type' => MENU_CALLBACK,
    'access arguments' => array('administer languages'),
    'file' => 'language.admin.inc',
  );
144
145
146
147
148
149
150
151
  $items['admin/config/regional/language/detection/selected'] = array(
    'title' => 'Selected language detection configuration',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('language_negotiation_configure_selected_form'),
    'access arguments' => array('administer languages'),
    'file' => 'language.admin.inc',
    'type' => MENU_VISIBLE_IN_BREADCRUMB,
  );
152

153
154
155
  return $items;
}

156
157
158
159
160
161
162
/**
 * Editing or deleting locked languages should not be possible.
 */
function language_access_language_edit_or_delete($language) {
  return !$language->locked && user_access('administer languages');
}

163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/**
 * Implements hook_permission().
 */
function language_permission() {
  return array(
    'administer languages' => array(
      'title' => t('Administer languages'),
    ),
  );
}

/**
 * Implements hook_theme().
 */
function language_theme() {
  return array(
    'language_admin_overview_form_table' => array(
      'render element' => 'form',
      'file' => 'language.admin.inc',
    ),
    'language_admin_operations' => array(
      'render element' => 'elements',
      'file' => 'language.admin.inc',
    ),
187
188
189
    'language_negotiation_configure_form' => array(
      'render element' => 'form',
    ),
190
191
192
193
    'language_negotiation_configure_browser_form_table' => array(
      'render element' => 'form',
      'file' => 'language.admin.inc',
    ),
194
195
196
  );
}

197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/**
 * Implements hook_element_info_alter().
 */
function language_element_info_alter(&$type) {
  // Alter the language_select element so that it will be rendered like a select
  // field.
  if (isset($type['language_select'])) {
    if (!isset($type['language_select']['#process'])) {
      $type['language_select']['#process'] = array();
    }
    if (!isset($type['language_select']['#theme_wrappers'])) {
      $type['language_select']['#theme_wrappers'] = array();
    }
    $type['language_select']['#process'] = array_merge($type['language_select']['#process'], array('language_process_language_select', 'form_process_select', 'ajax_process_form'));
    $type['language_select']['#theme'] = 'select';
    $type['language_select']['#theme_wrappers'] = array_merge($type['language_select']['#theme_wrappers'], array('form_element'));
    $type['language_select']['#languages'] = LANGUAGE_CONFIGURABLE;
    $type['language_select']['#multiple'] = FALSE;
  }
}

/**
 * Processes a language select list form element.
 *
 * @param array $element
 *   The form element to process.
 *
 * @return array $element
 *   The processed form element.
 */
function language_process_language_select($element) {
228
  // Don't set the options if another module (translation for example) already
229
230
231
232
233
234
235
236
237
238
  // set the options.
  if (!isset($element['#options'])) {
    $element['#options'] = array();
    foreach (language_list($element['#languages']) as $langcode => $language) {
      $element['#options'][$langcode] = $language->locked ? t('- @name -', array('@name' => $language->name)) : $language->name;
    }
  }
  return $element;
}

239
240
241
242
243
244
245
/**
 * API function to add or update a language.
 *
 * @param $language
 *   Language object with properties corresponding to 'language' table columns.
 */
function language_save($language) {
246
  $language->is_new = !(bool) db_query_range('SELECT 1 FROM {language} WHERE langcode = :langcode', 0, 1, array(':langcode' => $language->langcode))->fetchField();
247
248
249
250
251

  // Let other modules modify $language before saved.
  module_invoke_all('language_presave', $language);

  // Save the record and inform others about the change.
252
  $t_args = array('%language' => $language->name, '%langcode' => $language->langcode);
253
254
255
256
257
258
  if ($language->is_new) {
    drupal_write_record('language', $language);
    module_invoke_all('language_insert', $language);
    watchdog('language', 'The %language (%langcode) language has been created.', $t_args);
  }
  else {
259
    drupal_write_record('language', $language, array('langcode'));
260
261
262
263
264
265
266
    module_invoke_all('language_update', $language);
    watchdog('language', 'The %language (%langcode) language has been updated.', $t_args);
  }

  if (!empty($language->default)) {
    // Set the new version of this language as default in a variable.
    $default_language = language_default();
267
    variable_set('language_default', (array) $language);
268
269
  }

270
  // Update language count based on unlocked language count.
271
  language_update_count();
272
273
274
275

  // Kill the static cache in language_list().
  drupal_static_reset('language_list');

276
277
278
279
  // Update URL Prefixes for all languages after the new default language is
  // propagated and the language_list() cache is flushed.
  language_negotiation_url_prefixes_update();

280
281
282
  return $language;
}

283
284
285
286
287
288
289
290
291
292
293
/**
 * Updates the language_count variable.
 *
 * This is used to check if a site is multilingual or not.
 *
 * @see language_multilingual()
 */
function language_update_count() {
  variable_set('language_count', db_query('SELECT COUNT(langcode) FROM {language} WHERE locked = 0')->fetchField());
}

294
295
296
297
298
299
300
301
302
/**
 * Delete a language.
 *
 * @param $langcode
 *   Language code of the language to be deleted.
 * @return
 *   TRUE if language is successfully deleted. Otherwise FALSE.
 */
function language_delete($langcode) {
303
304
  $languages = language_list(LANGUAGE_ALL);
  if (isset($languages[$langcode]) && !$languages[$langcode]->locked) {
305
306
307
308
309
310
    $language = $languages[$langcode];

    module_invoke_all('language_delete', $language);

    // Remove the language.
    db_delete('language')
311
      ->condition('langcode', $language->langcode)
312
313
      ->execute();

314
    language_update_count();
315
316
317

    drupal_static_reset('language_list');

318
    $t_args = array('%language' => $language->name, '%langcode' => $language->langcode);
319
320
321
322
323
    watchdog('language', 'The %language (%langcode) language has been removed.', $t_args);
    return TRUE;
  }
  return FALSE;
}
324
325
326
327
328
329
330
331

/**
 * Implements hook_css_alter().
 *
 * This function checks all CSS files currently added via drupal_add_css() and
 * and checks to see if a related right to left CSS file should be included.
 */
function language_css_alter(&$css) {
332
  $language_interface = language(LANGUAGE_TYPE_INTERFACE);
333
334

  // If the current language is RTL, add the CSS file with the RTL overrides.
335
  if ($language_interface->direction == LANGUAGE_RTL) {
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
    foreach ($css as $data => $item) {
      // Only provide RTL overrides for files.
      if ($item['type'] == 'file') {
        $rtl_path = str_replace('.css', '-rtl.css', $item['data']);
        if (file_exists($rtl_path) && !isset($css[$rtl_path])) {
          // Replicate the same item, but with the RTL path and a little larger
          // weight so that it appears directly after the original CSS file.
          $item['data'] = $rtl_path;
          $item['weight'] += 0.01;
          $css[$rtl_path] = $item;
        }
      }
    }
  }
}
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402

/**
 * Implements hook_language_types_info().
 *
 * Defines the three core language types:
 * - Interface language is the only configurable language type in core. It is
 *   used by t() as the default language if none is specified.
 * - Content language is by default non-configurable and inherits the interface
 *   language negotiated value. It is used by the Field API to determine the
 *   display language for fields if no explicit value is specified.
 * - URL language is by default non-configurable and is determined through the
 *   URL language negotiation method or the URL fallback language negotiation
 *   method if no language can be detected. It is used by l() as the default
 *   language if none is specified.
 */
function language_language_types_info() {
  language_negotiation_include();

  return array(
    LANGUAGE_TYPE_INTERFACE => array(
      'name' => t('User interface text'),
      'description' => t('Order of language detection methods for user interface text. If a translation of user interface text is available in the detected language, it will be displayed.'),
    ),
    LANGUAGE_TYPE_CONTENT => array(
      'name' => t('Content'),
      'description' => t('Order of language detection methods for content. If a version of content is available in the detected language, it will be displayed.'),
      'fixed' => array(LANGUAGE_NEGOTIATION_INTERFACE),
    ),
    LANGUAGE_TYPE_URL => array(
      'fixed' => array(LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_URL_FALLBACK),
    ),
  );
}

/**
 * Implements hook_language_negotiation_info().
 */
function language_language_negotiation_info() {
  language_negotiation_include();
  $file = drupal_get_path('module', 'language') . '/language.negotiation.inc';

  $negotiation_info = array();
  $negotiation_info[LANGUAGE_NEGOTIATION_URL] = array(
    'types' => array(LANGUAGE_TYPE_CONTENT, LANGUAGE_TYPE_INTERFACE, LANGUAGE_TYPE_URL),
    'callbacks' => array(
      'negotiation' => 'language_from_url',
      'language_switch' => 'language_switcher_url',
      'url_rewrite' => 'language_url_rewrite_url',
    ),
    'file' => $file,
    'weight' => -8,
    'name' => t('URL'),
403
    'description' => t('Language from the URL (Path prefix or domain).'),
404
405
406
407
408
409
410
411
412
413
414
415
    'config' => 'admin/config/regional/language/detection/url',
  );

  $negotiation_info[LANGUAGE_NEGOTIATION_SESSION] = array(
    'callbacks' => array(
      'negotiation' => 'language_from_session',
      'language_switch' => 'language_switcher_session',
      'url_rewrite' => 'language_url_rewrite_session',
    ),
    'file' => $file,
    'weight' => -6,
    'name' => t('Session'),
416
    'description' => t('Language from a request/session parameter.'),
417
418
419
420
421
422
423
    'config' => 'admin/config/regional/language/detection/session',
  );

  $negotiation_info[LANGUAGE_NEGOTIATION_USER] = array(
    'callbacks' => array('negotiation' => 'language_from_user'),
    'file' => $file,
    'weight' => -4,
424
425
    'name' => t('Account'),
    'description' => t('Account site language setting.'),
426
427
428
429
430
431
432
433
  );

  $negotiation_info[LANGUAGE_NEGOTIATION_BROWSER] = array(
    'callbacks' => array('negotiation' => 'language_from_browser'),
    'file' => $file,
    'weight' => -2,
    'cache' => 0,
    'name' => t('Browser'),
434
    'description' => t("Language from the browser's language settings."),
435
    'config' => 'admin/config/regional/language/detection/browser',
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
  );

  $negotiation_info[LANGUAGE_NEGOTIATION_INTERFACE] = array(
    'types' => array(LANGUAGE_TYPE_CONTENT),
    'callbacks' => array('negotiation' => 'language_from_interface'),
    'file' => $file,
    'weight' => 8,
    'name' => t('Interface'),
    'description' => t('Use the detected interface language.'),
  );

  $negotiation_info[LANGUAGE_NEGOTIATION_URL_FALLBACK] = array(
    'types' => array(LANGUAGE_TYPE_URL),
    'callbacks' => array('negotiation' => 'language_url_fallback'),
    'file' => $file,
    'weight' => 8,
    'name' => t('URL fallback'),
    'description' => t('Use an already detected language for URLs if none is found.'),
  );

456
457
458
459
460
461
462
463
464
  $negotiation_info[LANGUAGE_NEGOTIATION_USER_ADMIN] = array(
    'types' => array(LANGUAGE_TYPE_INTERFACE),
    'callbacks' => array('negotiation' => 'language_from_user_admin'),
    'file' => $file,
    'weight' => 10,
    'name' => t('Account administration pages'),
    'description' => t('Account administration pages language setting.'),
  );

465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
  return $negotiation_info;
}

/**
 * Include negotiation backend functionality.
 */
function language_negotiation_include() {
  include_once DRUPAL_ROOT . '/core/includes/language.inc';
  include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'language') . '/language.negotiation.inc';
}

/**
 * Implements hook_modules_enabled().
 */
function language_modules_enabled($modules) {
  language_negotiation_include();
  language_types_set();
  language_negotiation_purge();
}

/**
 * Implements hook_modules_disabled().
 */
function language_modules_disabled($modules) {
  language_modules_enabled($modules);
}

/**
 * Implements hook_language_insert().
 */
function language_language_insert($language) {
496
497
498
499
  if (!empty($language->locked)) {
    return;
  }

500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
  language_negotiation_include();

  // Add language to the list of language domains.
  $domains = language_negotiation_url_domains();
  $domains[$language->langcode] = '';
  language_negotiation_url_domains_save($domains);
}

/**
 * Implements hook_language_delete().
 */
function language_language_delete($language) {
  language_negotiation_include();

  // Remove language from language prefix list.
  $prefixes = language_negotiation_url_prefixes();
  unset($prefixes[$language->langcode]);
  language_negotiation_url_prefixes_save($prefixes);

  // Remove language from language domain list.
  $domains = language_negotiation_url_domains();
  unset($domains[$language->langcode]);
  language_negotiation_url_domains_save($domains);
}

/**
 * Implements hook_block_info().
 */
function language_block_info() {
  include_once DRUPAL_ROOT . '/core/includes/language.inc';
  $block = array();
  $info = language_types_info();
  foreach (language_types_get_configurable(FALSE) as $type) {
    $block[$type] = array(
      // We do not need to escape the language type name since the block 'info'
      // value is supposed not to be sanitized. It is escaped later, if needed.
      'info' => t('Language switcher (!type)', array('!type' => $info[$type]['name'])),
      // Not worth caching.
      'cache' => DRUPAL_NO_CACHE,
    );
  }
  return $block;
}

/**
 * Implements hook_block_view().
 *
 * Displays a language switcher. Only show if we have at least two languages.
 */
function language_block_view($type) {
  if (language_multilingual()) {
551
    $path = drupal_is_front_page() ? '<front>' : current_path();
552
553
554
555
556
557
558
559
560
561
562
563
564
    $links = language_negotiation_get_switch_links($type, $path);

    if (isset($links->links)) {
      $class = "language-switcher-{$links->method_id}";
      $variables = array('links' => $links->links, 'attributes' => array('class' => array($class)));
      $block['content'] = theme('links__language_block', $variables);
      $block['subject'] = t('Languages');
      return $block;
    }
  }
}

/**
565
 * Implements hook_preprocess_HOOK() for block.tpl.php.
566
567
568
 */
function language_preprocess_block(&$variables) {
  if ($variables['block']->module == 'language') {
569
    $variables['attributes']['role'] = 'navigation';
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
  }
}

/**
 * Implements hook_url_outbound_alter().
 *
 * Rewrite outbound URLs with language based prefixes.
 */
function language_url_outbound_alter(&$path, &$options, $original_path) {
  // Only modify internal URLs.
  if (!$options['external'] && language_multilingual()) {
    static $drupal_static_fast;
    if (!isset($drupal_static_fast)) {
      $drupal_static_fast['callbacks'] = &drupal_static(__FUNCTION__);
    }
    $callbacks = &$drupal_static_fast['callbacks'];

    if (!isset($callbacks)) {
      $callbacks = array();
      include_once DRUPAL_ROOT . '/core/includes/language.inc';

      foreach (language_types_get_configurable() as $type) {
        // Get URL rewriter callbacks only from enabled language methods.
        $negotiation = variable_get("language_negotiation_$type", array());

        foreach ($negotiation as $method_id => $method) {
          if (isset($method['callbacks']['url_rewrite'])) {
            if (isset($method['file'])) {
              require_once DRUPAL_ROOT . '/' . $method['file'];
            }
            // Avoid duplicate callback entries.
            $callbacks[$method['callbacks']['url_rewrite']] = TRUE;
          }
        }
      }

      $callbacks = array_keys($callbacks);
    }

609
610
611
612
613
614
    // No language dependent path allowed in this mode.
    if (empty($callbacks)) {
      unset($options['language']);
      return;
    }

615
616
617
618
619
620
621
    foreach ($callbacks as $callback) {
      if (function_exists($callback)) {
        $callback($path, $options);
      }
    }
  }
}
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649

/**
 * Returns language mappings between browser and Drupal language codes.
 *
 * @return array
 *   An array containing browser language codes as keys with corresponding
 *   Drupal language codes as values.
 */
function language_get_browser_drupal_langcode_mappings() {
  $config = config('language.mappings');
  if ($config->isNew()) {
    return array();
  }
  return $config->get();
}

/**
 * Stores language mappings between browser and Drupal language codes.
 *
 * @param array $mappings
 *   An array containing browser language codes as keys with corresponding
 *   Drupal language codes as values.
 */
function language_set_browser_drupal_langcode_mappings($mappings) {
  $config = config('language.mappings');
  $config->setData($mappings);
  $config->save();
}