Skip to content

Commit

Permalink
Add language map and refactor EngineBase::getValidLangs()
Browse files Browse the repository at this point in the history
This also adds the extra non-standard languages offered by Tesseract,
along with their localized names.

The Select2 control on the form now dynamically updates with the
supported languages when the engine is changed.

Bug: T282760
Bug: T281866
Bug: T282073
  • Loading branch information
MusikAnimal authored Jun 4, 2021
1 parent 6191b06 commit 393b7b7
Show file tree
Hide file tree
Showing 15 changed files with 791 additions and 114 deletions.
42 changes: 39 additions & 3 deletions assets/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,55 @@ import './styles/app.css';
import 'select2';

const $ = require('jquery');
const $select2 = $('#lang');

/**
* Populate and re-initialize the Select2 input with languages supported by the given engine.
* @param {String} engine Supported engine ID such as 'google' or 'tesseract'.
*/
function updateSelect2Options(engine)
{
$.getJSON(`/api/available_langs?engine=${engine}`).then(response => {
const langs = response.available_langs;
let data = [];

// Transform to data structure needed by Select2.
Object.keys(langs).forEach(lang => {
data.push({
id: lang,
text: `${lang}${langs[lang]}`,
});
});

// First clear any existing selections and empty all options.
$select2.val(null)
.empty()
.trigger('change');

// Update Select2 with the new options.
data.forEach(datum => {
const option = new Option(datum.text, datum.id, false, false);
$select2.append(option);
});
$select2.trigger({
type: 'select2:select',
params: { data }
});
});
}

$(function () {
// Initiate Select2, which allows dynamic entry of languages.
$('#lang').select2({
$select2.select2({
theme: 'bootstrap',
});

// Show engine-specific options.
// TODO: Update the Select2 options with available languages.
$('#engine').on('change', e => {
updateSelect2Options(e.target.value);
$('.engine-options').addClass('hidden');
$(`#${e.target.value}-options`).removeClass('hidden');
}).trigger('change');
});

// For the result page. Makes the 'Copy' button copy the transcription to the clipboard.
const $copyButton = $('#copy-button');
Expand Down
2 changes: 2 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ services:

# https://symfony.com/doc/current/service_container/parent_services.html
App\Engine\EngineBase:
arguments:
$projectDir: '%kernel.project_dir%'
calls:
- setImageHosts: [ '%env(APP_IMAGE_HOSTS)%' ]

Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="8.5" />
<server name="KERNEL_CLASS" value="App\Kernel" />

<!-- ###+ symfony/mailer ### -->
<!-- MAILER_DSN=smtp://localhost -->
Expand Down
Loading

0 comments on commit 393b7b7

Please sign in to comment.