Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

343.1. translatelocally-0.0.2.20250330

translateLocally: machine translation on the CPU with Bergamot models, with the text never leaving the machine

Version 0.0.2.20250330, release 1
Shelf ai — Machine learning inference, speech recognition, computer vision and neural translation
Phase 44_apps (Applications), 6 of 422 in build order
Licence MIT AND MPL-2.0 AND Apache-2.0
Homepage https://translatelocally.com/
Build time 59.0 SBU
Installed size 13.0 MiB in 6 files
Recipe ports/core/ai/translatelocally/kpkgbuild

About

translateLocally is a Qt 6 program that translates text between languages on the CPU, with neural models from the Bergamot project, so the text never leaves the machine. It downloads a language pair’s model on request (on the command line, --download-model); the package carries none. Under it are bergamot-translator, the Marian inference engine (marian-dev, the Bergamot fork), intgemm for 8- and 16-bit integer matrix multiplication, a fork of SentencePiece for tokenising, and ssplit-cpp for splitting sentences, all compiled into the program.

Sources

Dependencies

Depends on: cmake, ninja, librsvg, qt6-qtbase, qt6-qttools, qt6-qtsvg, qt6-qtwayland, openblas, pcre2, libarchive, hicolor-icon-theme.

Required by: no port names it.

Patches

build.sh applies these; kpkg applies nothing by itself.

All six patch the vendored Marian under 3rd_party/bergamot-translator/3rd_party/marian-dev/.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/44_apps/phase.env && kpkg install translatelocally'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/ai/translatelocally.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/ai/translatelocally
echo 'e61644b30be0bd698aabef52f19b48d2951ec7806072345d3725ad1839b363a1  bergamot-translator-9271618ebbdc5d21ac4dc4df9e72beb7ce644774.tar.gz' | sha256sum -c -
echo '8e827c445dbb1b117a9667616bac23b3c945e626da0a3466786cfd058ed2f41d  intgemm-f7401513da71758dacce52fed1c7855549abee59.tar.gz' | sha256sum -c -
echo '96f3f31a79899f26217b5fa0a78d6e8a6bc5e7a8e4c50de7bde4c3fa2858999d  marian-dev-2781d735d4a10dca876d61be587afdab2726293c.tar.gz' | sha256sum -c -
echo '4d2148ae7e240cd113586004d2cf0102f7ab1bae363b91b2934ee83c5ae3dbbe  sentencepiece-ae41b7740d7006596bb9257e83340b2620db9d00.tar.gz' | sha256sum -c -
echo '937ded1229ee69f340772056a4ff6daaede5b899f12c4c7b091c40f430c56fd8  ssplit-cpp-a311f9865ade34db1e8e080e6cc146f55dafb067.tar.gz' | sha256sum -c -
echo 'a0c98a54340a194588205d8cbd6db667bb73d6e9acb0fbc790d409287d31c4f6  translatelocally-0.0.2.20250330.tar.gz' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/translatelocally
SRC=$SRC_ROOT/translatelocally-0.0.2.20250330
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf translatelocally-0.0.2.20250330.tar.gz -C "$SRC" --strip-components=1
tar --no-same-permissions --warning=no-unknown-keyword -xf bergamot-translator-9271618ebbdc5d21ac4dc4df9e72beb7ce644774.tar.gz -C "$SRC_ROOT"
tar --no-same-permissions --warning=no-unknown-keyword -xf marian-dev-2781d735d4a10dca876d61be587afdab2726293c.tar.gz -C "$SRC_ROOT"
tar --no-same-permissions --warning=no-unknown-keyword -xf intgemm-f7401513da71758dacce52fed1c7855549abee59.tar.gz -C "$SRC_ROOT"
tar --no-same-permissions --warning=no-unknown-keyword -xf sentencepiece-ae41b7740d7006596bb9257e83340b2620db9d00.tar.gz -C "$SRC_ROOT"
tar --no-same-permissions --warning=no-unknown-keyword -xf ssplit-cpp-a311f9865ade34db1e8e080e6cc146f55dafb067.tar.gz -C "$SRC_ROOT"

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the recipe’s helpers _commit, _bergamot, _marian, _intgemm, _spm, _ssplit and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

_b=3rd_party/bergamot-translator
_m=$_b/3rd_party/marian-dev
cp -a "$SRC_ROOT/bergamot-translator-$_bergamot/." "$_b/"
cp -a "$SRC_ROOT/marian-dev-$_marian/." "$_m/"
cp -a "$SRC_ROOT/ssplit-cpp-$_ssplit/." "$_b/3rd_party/ssplit-cpp/"
cp -a "$SRC_ROOT/intgemm-$_intgemm/." "$_m/src/3rd_party/intgemm/"
cp -a "$SRC_ROOT/sentencepiece-$_spm/." "$_m/src/3rd_party/sentencepiece/"

patch -p1 -i "$PORT_SRC/marian-musl-no-execinfo.patch"
patch -p1 -i "$PORT_SRC/marian-musl-strerror-r.patch"
patch -p1 -i "$PORT_SRC/marian-cstdint.patch"
patch -p1 -i "$PORT_SRC/no-werror.patch"
patch -p1 -i "$PORT_SRC/marian-honour-flags.patch"
patch -p1 -i "$PORT_SRC/marian-no-git.patch"

cmake -S . -B build -G Ninja \
	-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
	-DCMAKE_BUILD_TYPE=Release \
	-DCMAKE_INSTALL_PREFIX=/usr \
	-DCMAKE_INSTALL_LIBDIR=lib \
	-DBUILD_ARCH=x86-64 \
	-DMARIAN_GIT_REVISION="${_marian:0:7}" \
	-DCOMPILE_CUDA=OFF \
	-DUSE_MKL=OFF \
	-DUSE_STATIC_LIBS=OFF \
	-DUSE_DOXYGEN=OFF \
	-DUSE_CCACHE=OFF \
	-DCOMPILE_SERVER=OFF \
	-DCOMPILE_PYTHON=OFF \
	-DCOMPILE_TESTS=OFF \
	-DBUILD_EXTERNAL_LIBARCHIVE=OFF \
	-DSSPLIT_USE_INTERNAL_PCRE2=OFF \
	-DSSPLIT_PREFER_STATIC_COMPILE=OFF
grep -q '^cblas_openblas_WORKS:INTERNAL=1$' build/CMakeCache.txt ||
	{ echo "translatelocally: OpenBLAS not found at configure" >&2; exit 1; }
cmake --build build
DESTDIR=$PKG cmake --install build
rm -f "$PKG"/usr/share/icons/translateLocally_logo.png \
	"$PKG"/usr/share/icons/translateLocally_logo.svg \
	"$PKG"/usr/share/applications/translateLocally.desktop

for s in 48 128 256; do
	install -d "$PKG/usr/share/icons/hicolor/${s}x${s}/apps"
	rsvg-convert -w $s -h $s logo/translateLocally_logo.svg \
		-o "$PKG/usr/share/icons/hicolor/${s}x${s}/apps/translateLocally.png"
done

cat > "$PKG/usr/share/applications/translateLocally.desktop" <<'DESKTOP'
[Desktop Entry]
Type=Application
Name=translateLocally
GenericName=Translator
Comment=Translate text between languages on this machine, with no network
Exec=translateLocally
Icon=translateLocally
Terminal=false
StartupWMClass=translateLocally
Categories=Qt;Office;Education;Languages;
Keywords=translate;translation;language;bergamot;marian;offline;
DESKTOP
chmod 644 "$PKG/usr/share/applications/translateLocally.desktop"

The switches, and why each is set:

The common switches of each build system are explained in the Flag glossary.

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/translatelocally, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf translatelocally-0.0.2.20250330-1.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/translatelocally, and runs the triggers its paths call for.

Contents

Installed programs: translateLocally.

Installed directories: /usr/share/licenses/translatelocally.

Notes

GitHub’s archive of a commit does not carry its git submodules, so the recipe fetches each of the five the build compiles as its own source, pinned by the commit in its helper (_bergamot, _marian, _intgemm, _spm, _ssplit), and build.sh copies each into the directory the submodule occupies before any patch is applied. The other submodules stay empty, because this x86-64 configuration compiles none of them. Bumping translateLocally means reading the submodule commits of the new revision and moving every helper with it; a submodule left behind builds a mismatched engine.

After the configure, build.sh fails the build unless CMakeCache.txt records cblas_openblas_WORKS:INTERNAL=1. Marian’s BLAS search does not stop the configure when it finds no working CBLAS; it only leaves BLAS_FOUND undefined.

Upstream installs its logo as /usr/share/icons/translateLocally_logo.png and .svg, and its desktop entry names Icon=translateLocally_logo. Neither file is in hicolor’s apps/ directory, where the desktop looks for an application’s icon (see desktop entries), so build.sh deletes all three and rasterises the SVG with rsvg-convert to 48, 128 and 256 pixel PNGs under hicolor/<size>/apps/translateLocally.png, then writes an entry that names that icon.