2020-10-29 11:17:32 +03:00
# Bergamot Translator
Bergamot translator provides a unified API for ([Marian NMT](https://marian-nmt.github.io/) framework based) neural machine translation functionality in accordance with the [Bergamot ](https://browser.mt/ ) project that focuses on improving client-side machine translation in a web browser.
2020-11-16 15:09:42 +03:00
## Build Instructions
2021-02-12 01:27:16 +03:00
### Build Natively
```bash
2021-02-13 02:25:40 +03:00
git clone --recursive https://github.com/browsermt/bergamot-translator
2021-02-12 01:27:16 +03:00
cd bergamot-translator
mkdir build
cd build
cmake ../
make -j
2020-11-16 15:09:42 +03:00
```
2021-02-12 01:27:16 +03:00
### Build WASM
2021-01-22 14:51:49 +03:00
2021-02-12 01:27:16 +03:00
To compile WASM, first download and Install Emscripten using following instructions:
2021-01-22 14:51:49 +03:00
2021-02-13 02:41:17 +03:00
1. Get the latest sdk: `git clone --recursive https://github.com/emscripten-core/emsdk.git`
2021-02-12 01:27:16 +03:00
2. Enter the cloned directory: `cd emsdk`
3. Install the lastest sdk tools: `./emsdk install latest`
4. Activate the latest sdk tools: `./emsdk activate latest`
5. Activate path variables: `source ./emsdk_env.sh`
2021-01-22 14:51:49 +03:00
2021-02-12 01:27:16 +03:00
After the successful installation of Emscripten, perform these steps:
2021-01-22 14:51:49 +03:00
2021-02-12 01:27:16 +03:00
```bash
git clone https://github.com/browsermt/bergamot-translator
cd bergamot-translator
mkdir build-wasm
cd build-wasm
emcmake cmake -DCOMPILE_WASM=on ../
emmake make -j
```
2021-01-22 14:51:49 +03:00
2021-02-12 01:27:16 +03:00
It should generate the artefacts (.js and .wasm files) in `wasm` folder inside build directory ("build-wasm" in this case).
2021-01-22 14:51:49 +03:00
2021-02-12 01:27:16 +03:00
The build also allows packaging files into wasm binary (i.e. preloading in Emscripten’ s virtual file system) using cmake
option `PACKAGE_DIR` . The compile command below packages all the files in PATH directory into wasm binary.
2021-01-22 14:51:49 +03:00
```bash
2021-02-12 01:27:16 +03:00
emcmake cmake -DCOMPILE_WASM=on -DPACKAGE_DIR=< PATH > ../
```
Files packaged this way are preloaded in the root of the virtual file system.
2021-01-22 14:51:49 +03:00
2021-02-12 01:27:16 +03:00
After Editing Files:
2021-01-22 14:51:49 +03:00
2021-02-12 01:27:16 +03:00
```bash
emmake make -j
```
After Adding/Removing Files:
```bash
emcmake cmake -DCOMPILE_WASM=on ../
emmake make -j
```
2021-01-22 14:51:49 +03:00
2021-02-12 01:27:16 +03:00
### Using Native version
2021-01-22 14:51:49 +03:00
2021-02-12 01:27:16 +03:00
The builds generate library that can be integrated to any project. All the public header files are specified in `src` folder. A short example of how to use the APIs is provided in `app/main.cpp` file
2021-01-22 14:51:49 +03:00
2021-02-12 01:27:16 +03:00
### Using WASM version
2021-01-22 14:51:49 +03:00
2021-02-12 01:27:16 +03:00
Please follow the `README` inside the `wasm` folder of this repository that demonstrates how to use the translator in JavaScript.