From ed3160524d7050e308f612c67b11ea797fb2013f Mon Sep 17 00:00:00 2001 From: Jelmer Date: Wed, 23 Mar 2022 12:14:51 +0000 Subject: [PATCH 1/4] JS: Update languages & use Intl API for their display names (#379) Got the languages from registry.json, including non-prod models. Code now calls into `Intl.DisplayNames()`[1] to make life easier. [1] (http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames) --- wasm/test_page/js/index.js | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/wasm/test_page/js/index.js b/wasm/test_page/js/index.js index eec834cc8..4eb86764b 100644 --- a/wasm/test_page/js/index.js +++ b/wasm/test_page/js/index.js @@ -7,17 +7,6 @@ const status = message => ($("#status").innerText = message); const langFrom = $("#lang-from"); const langTo = $("#lang-to"); -const langs = [ - ["en", "English"], - ["it", "Italian"], - ["pt", "Portuguese"], - ["ru", "Russian"], - ["cs", "Czech"], - ["de", "German"], - ["es", "Spanish"], - ["et", "Estonian"], -]; - if (window.Worker) { worker = new Worker("js/worker.js"); worker.postMessage(["import"]); @@ -99,11 +88,6 @@ worker.onmessage = function (e) { } }; -langs.forEach(([code, name]) => { - langFrom.innerHTML += ``; - langTo.innerHTML += ``; -}); - const loadModel = () => { const lngFrom = langFrom.value; const lngTo = langTo.value; @@ -140,11 +124,25 @@ $('#output').addEventListener('mouseover', e => { }) function init() { + // Populate langs + const langs = Array.from(new Set(Object.keys(modelRegistry).reduce((acc, key) => acc.concat([key.substr(0, 2), key.substr(2, 2)]), []))); + const langNames = new Intl.DisplayNames(undefined, {type: "language"}); + + // Sort languages by display name + langs.sort((a, b) => langNames.of(a).localeCompare(langNames.of(b))); + + // Populate the dropdowns + langs.forEach(code => { + const name = langNames.of(code); + langFrom.innerHTML += ``; + langTo.innerHTML += ``; + }); + // try to guess input language from user agent let myLang = navigator.language; if (myLang) { myLang = myLang.split("-")[0]; - let langIndex = langs.findIndex(([code]) => code === myLang); + let langIndex = langs.indexOf(myLang); if (langIndex > -1) { console.log("guessing input language is", myLang); langFrom.value = myLang; @@ -152,7 +150,7 @@ function init() { } // find first output lang that *isn't* input language - langTo.value = langs.find(([code]) => code !== langFrom.value)[0]; + langTo.value = langs.find(code => code !== langFrom.value); // load this model loadModel(); } From 46882e7cfe37d8ffe4d6c2053562b18aba003f00 Mon Sep 17 00:00:00 2001 From: Jerin Philip Date: Thu, 24 Mar 2022 15:05:45 +0000 Subject: [PATCH 2/4] JS: Fix swap button on test-page (#388) --- wasm/test_page/js/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasm/test_page/js/index.js b/wasm/test_page/js/index.js index 4eb86764b..b1c308e8b 100644 --- a/wasm/test_page/js/index.js +++ b/wasm/test_page/js/index.js @@ -111,7 +111,7 @@ langTo.addEventListener("change", e => { $(".swap").addEventListener("click", e => { [langFrom.value, langTo.value] = [langTo.value, langFrom.value]; - $("#input").value = $("#output").value; + $("#input").value = $("#output").innerText; loadModel(); }); From 13443352c0abacef33c7e696f2ad2e5eb3a622c1 Mon Sep 17 00:00:00 2001 From: Jerin Philip Date: Thu, 24 Mar 2022 19:26:20 +0000 Subject: [PATCH 3/4] Docs: Pin Jinja2 to last known working version (#389) Fixes the docs workflow which is failing after pip is picking up Jinja 3.20. We only need >=2.3, this one sets it to 3.0.3 builds were successful last. --- doc/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/requirements.txt b/doc/requirements.txt index d95cc684c..778f08914 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -1,5 +1,6 @@ sphinx==2.4.4 breathe==4.13.0 +Jinja2==3.0.3 exhale sphinx_rtd_theme mistune<2.0.0 From d2e3a826220db7d9c37115b890320b196ed124bf Mon Sep 17 00:00:00 2001 From: Abhishek Aggarwal <66322306+abhi-agg@users.noreply.github.com> Date: Mon, 28 Mar 2022 18:03:43 +0200 Subject: [PATCH 4/4] Bump version to 0.4.3 (#392) --- BERGAMOT_VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BERGAMOT_VERSION b/BERGAMOT_VERSION index 0eec13e47..f87d474c4 100644 --- a/BERGAMOT_VERSION +++ b/BERGAMOT_VERSION @@ -1 +1 @@ -v0.4.2 +v0.4.3