Mercurial > hg > isophonics-drupal-site
annotate core/modules/locale/locale.bulk.es6.js @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 129ea1e6d783 |
children |
rev | line source |
---|---|
Chris@0 | 1 /** |
Chris@0 | 2 * @file |
Chris@0 | 3 * Locale behavior. |
Chris@0 | 4 */ |
Chris@0 | 5 |
Chris@17 | 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@17 | 22 $form.find('.file-import-input').on('change', function() { |
Chris@17 | 23 // If the filename is fully the language code or the filename |
Chris@17 | 24 // ends with a language code, pre-select that one. |
Chris@17 | 25 const matches = $(this) |
Chris@17 | 26 .val() |
Chris@17 | 27 .match(/([^.][.]*)([\w-]+)\.po$/); |
Chris@17 | 28 if ( |
Chris@17 | 29 matches && |
Chris@17 | 30 $langcode.find(`option[value="${matches[2]}"]`).length |
Chris@17 | 31 ) { |
Chris@17 | 32 $langcode.val(matches[2]); |
Chris@17 | 33 } |
Chris@17 | 34 }); |
Chris@0 | 35 } |
Chris@0 | 36 }, |
Chris@0 | 37 }; |
Chris@17 | 38 })(jQuery, Drupal); |