Building from Source

Building localtranslate from source is a tedious and involved process as most dependencies need to be compiled and installed from source.

If you wish to hit the ground running with translating stuff, please see the quickstart guide.

Note: This document makes use of a mkcd bash function

function mkcd {
    dir="$*";
    echo "mkdir -p $dir && cd $dir";
    mkdir -p "$dir" && cd "$dir";
}

Dependencies

First, begin by creating a directory which will serve as our playground to curl and compile all the dependencies.

  mkdir LocalTranslate_Deps
  cd LocalTranslate_Deps

intgemm

This is a dependency of marian-lite, used for Integer Matrix Multiplications.

from source

curl -LO https://github.com/kroketio/intgemm/archive/refs/tags/0.0.3.tar.gz
tar -xvf 0.0.3.tar.gz  
cd intgemm-0.0.3/
mkcd build
cmake ..
make
make install
sudo make install

pathie-cpp

This is also a dependency of marian-lite, used for cross-platform pathname/filename manipulation.

from source

curl -LO https://github.com/kroketio/pathie-cpp/archive/refs/tags/0.1.3.tar.gz
tar -xvf 0.1.3.tar.gz 
cd pathie-cpp-0.1.3/
mkcd build
cmake ..

CLI-11

Dependency of marian-lite, used for it's own command line parsing in its binaries marian-decoder, marian-scorer etc..

Fedora

sudo dnf install cli11-devel

sqlitecpp

Dependency of marian-lite, looks like marian uses it for storing its training corpus. Maybe we can get rid of this with some flags.

For now,

Fedora

sudo dnf install sqlitecpp-devel

yaml-cpp

Dependency of marian-lite, for parsing yaml config files.

Fedora

sudo dnf install yaml-cpp-devel

openblas

Dependency of marian-lite, for floating point vector and matrix operations.

Fedora

sudo dnf install openblas-devel

protobuf < 22

Dependency of sentencepiece, used for serializing sentencepiece vocab models.

from source

curl -LO https://github.com/protocolbuffers/protobuf/archive/refs/tags/v21.12.tar.gz
tar -xvf v21.12.tar.gz 
cd protobuf-21.12/
mkcd build 
cmake .. -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_ABSL_PROVIDER=package -Dprotobuf_BUILD_SHARED_LIBS=ON -Dprotobuf_BUILD_TESTS=OFF
make -j$(nproc)
sudo make install

sentencepiece (browsermt fork)

Dependency of marian-lite, used for storing vocabularies which are used in tokenization.

from source

curl -LO https://github.com/kroketio/sentencepiece-browsermt/archive/refs/tags/0.2.tar.gz
tar -xvf 0.2.tar.gz 
cd sentencepiece-browsermt-0.2/
mkcd build
cmake .. -DSPM_BUILD_LIBRARY_ONLY=ON
make -j$(nproc)
sudo make install

marian-lite

Dependency of kotki, the lite version of the training and inference framework used in Firefox's Neural Translation Models.

if you installed openblas from dnf or yum, then the header <cblas.h> is inside /usr/include/openblas/cblas.h, so you may need to replace #include <cblas.h> with #include <openblas/cblas.h> in the source code of marian-lite

You can find the offending files by running grep -r "<cblas.h>" in the source directory of marian-lite.

from source

curl -LO https://github.com/terslang/marian-lite/archive/refs/tags/v0.2.9-1.tar.gz
tar -xvf v0.2.9-1.tar.gz
cd marian-lite-0.2.9-1
mkcd build
cmake ..
make -j$(nproc)
sudo make install

rapidjson

Dependency of kotki, for reading the registry.json "Registry file" which is used to get info about all the models available on the disk.

Fedora

sudo dnf install rapidjson-devel

kotki

Dependency of LocalTranslate, the main translation engine used by LocalTranslate.

from source

curl -LO https://github.com/terslang/kotki/archive/refs/tags/v0.6.0-1.tar.gz
tar -xvf v0.6.0-1.tar.gz
cd kotki-0.6.0-1/
mkcd build
cmake ..
make -j$(nproc)
sudo make install

mecab

Dependency of LocalTranslate, used for transliteration of Japanese kana and kanji scripts.

Fedora

sudo dnf install mecab-devel mecab-ipadic

libICU

Dependency of LocalTranslate, used for transliteration of remaining non-latin scripts.

Fedora

sudo dnf install libicu-devel

Firefox Translation Models

curl -LO https://github.com/terslang/LocalTranslate/releases/download/v0.5.0/firefox-models.tar.xz
sudo mkdir -p /usr/share/localtranslate/models
sudo tar -xvf firefox-models.tar.xz -C /usr/share/localtranslate/models

Building LocalTranslate

Once you have all the dependencies installed, get the latest localtranslate source and build it the standard way.

  git clone https://github.com/terslang/LocalTranslate.git
  cd LocalTranslate
  mkcd build
  cmake .. -DCMAKE_PREFIX_PATH=<PATH_TO_YOUR_QT_KIT> # For example ~/Qt/6.9.1/gcc_64/
  make -j$(nproc)

LD_LIBRARY_PATH

Since we have compiled most of the deps from source, they will be installed in /usr/local/ instead of /usr/.

For our app to find it at runtime, you need to add /usr/local/lib64 to the LD_LIBRARY_PATH env variable.

For example, in Qt Creator, you can go to the Projects Tab -> Desktop Qt 6.x.x -> Run -> Environment -> Add

Then add the following

LD_LIBRARY_PATH=/usr/local/lib64:${LD_LIBRARY_PATH}

For command line, write this in the terminal:

export LD_LIBRARY_PATH=/usr/local/lib64:${LD_LIBRARY_PATH}

Running

./localtranslate