browsermt / bergamot-translator

Cross platform C++ library focusing on optimized machine translation on the consumer-grade device.
http://browser.mt
Mozilla Public License 2.0
341 stars 38 forks source link

Enhanced JavaScript module from this repository #330

Closed jerinphilip closed 2 years ago

jerinphilip commented 2 years ago

The current JavaScript "example" for the test page is perhaps not the best provision from here. There are a few common functions that can be abstracted here, potentially tested headless and seen by multiple eyes. Therefore, a better solution is a JavaScript library or module, ideally with an API consistent with the C++ from which it is derived.

The following are ideas of a few downstream applications of a JavaScript library that can do translation and is batteries included:

  1. The extension could be a consumer of this tested library eliminating human errors that come out of manual copying. (We got alignment:true and responseOptions.HTML correct here, but transfer to firefox-translations led to inconsistent config).
  2. https://github.com/jerinphilip/lemonade/issues/56.
  3. A plugin that can be embedded on to sites to provide translation similar to a google offering: https://www.dummies.com/article/technology/notable-websites/google/how-to-install-google-translates-website-translator-plugin-145074

There are parts of this library already existing in sources across a few repositories. At the moment the extra work and duplication is convenient for faster development cycles. But at some point in the future, we should look at consolidating commonly used functionalities here co-located with the bindings and continuously tested. The JavaScript module can be part of the releases from this repository.

This issue is meant to investigate and discuss ideas, weigh the pros and cons of the approach.

jerinphilip commented 2 years ago

OpenCV is a mature C++ library which exposes bindings to JavaScript and has JavaScript tests (https://docs.opencv.org/3.4/d4/da1/tutorial_js_setup.html) which we could potentially draw references/examples from. They also appear to be using WebAssembly SIMD and threads.

They allow automated testing variations of:

  1. Manually in browser
  2. Headless with Puppeteer
  3. Using Node.js.
jerinphilip commented 2 years ago

There appears to be a headless mechanism to test JavaScript via Firefox of which an example can be found in https://github.com/mozilla/firefox-translations/pull/106.

An incremental approach could be doing (1) manually in the browser and deploying to some health status Github page. This will prepare the test primitives and then we can look at the tests running headless.

jerinphilip commented 2 years ago

@jelmervdl has successfully managed to run the WASM module via node.js in https://gist.github.com/jelmervdl/a4c8b6b92ad88a885e1cbd51c6ad4902. This opens up possibilities for headless testing.