6 (function ($, Drupal) {
11 * Select the language code of an imported file based on its filename.
13 * This only works if the file name ends with "LANGCODE.po".
15 * @type {Drupal~behavior}
17 * @prop {Drupal~behaviorAttach} attach
18 * Attaches behavior for preselecting language code based on filename.
20 Drupal.behaviors.importLanguageCodeSelector = {
21 attach: function (context, settings) {
22 var $form = $('#locale-translate-import-form').once('autodetect-lang');
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]);