Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / locale / locale.bulk.js
1 /**
2  * @file
3  * Locale behavior.
4  */
5
6 (function ($, Drupal) {
7
8   'use strict';
9
10   /**
11    * Select the language code of an imported file based on its filename.
12    *
13    * This only works if the file name ends with "LANGCODE.po".
14    *
15    * @type {Drupal~behavior}
16    *
17    * @prop {Drupal~behaviorAttach} attach
18    *   Attaches behavior for preselecting language code based on filename.
19    */
20   Drupal.behaviors.importLanguageCodeSelector = {
21     attach: function (context, settings) {
22       var $form = $('#locale-translate-import-form').once('autodetect-lang');
23       if ($form.length) {
24         var $langcode = $form.find('.langcode-input');
25         $form.find('.file-import-input')
26           .on('change', function () {
27             // If the filename is fully the language code or the filename
28             // ends with a language code, pre-select that one.
29             var matches = $(this).val().match(/([^.][\.]*)([\w-]+)\.po$/);
30             if (matches && $langcode.find('option[value="' + matches[2] + '"]').length) {
31               $langcode.val(matches[2]);
32             }
33           });
34       }
35     }
36   };
37
38 })(jQuery, Drupal);