Mercurial > hg > isophonics-drupal-site
annotate core/modules/locale/locale.bulk.es6.js @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
rev | line source |
---|---|
Chris@0 | 1 /** |
Chris@0 | 2 * @file |
Chris@0 | 3 * Locale behavior. |
Chris@0 | 4 */ |
Chris@0 | 5 |
Chris@0 | 6 (function ($, Drupal) { |
Chris@0 | 7 /** |
Chris@0 | 8 * Select the language code of an imported file based on its filename. |
Chris@0 | 9 * |
Chris@0 | 10 * This only works if the file name ends with "LANGCODE.po". |
Chris@0 | 11 * |
Chris@0 | 12 * @type {Drupal~behavior} |
Chris@0 | 13 * |
Chris@0 | 14 * @prop {Drupal~behaviorAttach} attach |
Chris@0 | 15 * Attaches behavior for preselecting language code based on filename. |
Chris@0 | 16 */ |
Chris@0 | 17 Drupal.behaviors.importLanguageCodeSelector = { |
Chris@0 | 18 attach(context, settings) { |
Chris@0 | 19 const $form = $('#locale-translate-import-form').once('autodetect-lang'); |
Chris@0 | 20 if ($form.length) { |
Chris@0 | 21 const $langcode = $form.find('.langcode-input'); |
Chris@0 | 22 $form.find('.file-import-input') |
Chris@0 | 23 .on('change', function () { |
Chris@0 | 24 // If the filename is fully the language code or the filename |
Chris@0 | 25 // ends with a language code, pre-select that one. |
Chris@0 | 26 const matches = $(this).val().match(/([^.][\.]*)([\w-]+)\.po$/); |
Chris@0 | 27 if (matches && $langcode.find(`option[value="${matches[2]}"]`).length) { |
Chris@0 | 28 $langcode.val(matches[2]); |
Chris@0 | 29 } |
Chris@0 | 30 }); |
Chris@0 | 31 } |
Chris@0 | 32 }, |
Chris@0 | 33 }; |
Chris@0 | 34 }(jQuery, Drupal)); |