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