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
bergamot-translator-9271618ebbdc5d21ac4dc4df9e72beb7ce644774.tar.gz(197.7 KiB)
sha256e61644b30be0bd698aabef52f19b48d2951ec7806072345d3725ad1839b363a1
upstream: https://github.com/browsermt/bergamot-translator/archive/9271618ebbdc5d21ac4dc4df9e72beb7ce644774.tar.gz
archive copy: sources-1/ai--bergamot-translator-9271618ebbdc5d21ac4dc4df9e72beb7ce644774.tar.gzintgemm-f7401513da71758dacce52fed1c7855549abee59.tar.gz(187.0 KiB)
sha2568e827c445dbb1b117a9667616bac23b3c945e626da0a3466786cfd058ed2f41d
upstream: https://github.com/kpu/intgemm/archive/f7401513da71758dacce52fed1c7855549abee59.tar.gz
archive copy: sources-1/ai--intgemm-f7401513da71758dacce52fed1c7855549abee59.tar.gzmarian-dev-2781d735d4a10dca876d61be587afdab2726293c.tar.gz(1.5 MiB)
sha25696f3f31a79899f26217b5fa0a78d6e8a6bc5e7a8e4c50de7bde4c3fa2858999d
upstream: https://github.com/browsermt/marian-dev/archive/2781d735d4a10dca876d61be587afdab2726293c.tar.gz
archive copy: sources-1/ai--marian-dev-2781d735d4a10dca876d61be587afdab2726293c.tar.gzsentencepiece-ae41b7740d7006596bb9257e83340b2620db9d00.tar.gz(11.2 MiB)
sha2564d2148ae7e240cd113586004d2cf0102f7ab1bae363b91b2934ee83c5ae3dbbe
upstream: https://github.com/browsermt/sentencepiece/archive/ae41b7740d7006596bb9257e83340b2620db9d00.tar.gz
archive copy: sources-1/ai--sentencepiece-ae41b7740d7006596bb9257e83340b2620db9d00.tar.gzssplit-cpp-a311f9865ade34db1e8e080e6cc146f55dafb067.tar.gz(88.5 KiB)
sha256937ded1229ee69f340772056a4ff6daaede5b899f12c4c7b091c40f430c56fd8
upstream: https://github.com/browsermt/ssplit-cpp/archive/a311f9865ade34db1e8e080e6cc146f55dafb067.tar.gz
archive copy: sources-1/ai--ssplit-cpp-a311f9865ade34db1e8e080e6cc146f55dafb067.tar.gztranslatelocally-0.0.2.20250330.tar.gz(3.3 MiB)
sha256a0c98a54340a194588205d8cbd6db667bb73d6e9acb0fbc790d409287d31c4f6
upstream: https://github.com/XapaJIaMnu/translateLocally/archive/1d0d382cd6c9085cb4b8144c4a8962d74ed609c8.tar.gz
archive copy: sources-1/ai--translatelocally-0.0.2.20250330.tar.gz
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/.
marian-cstdint.patch— Adds#include <cstdint>tosrc/3rd_party/faiss/utils/misc.handsrc/microsoft/quicksand.h, which use the fixed-width integer types without including the header that declares them.marian-honour-flags.patch— Marian setsCMAKE_CXX_FLAGSandCMAKE_C_FLAGSoutright, which drops the exportedCXXFLAGSandCFLAGS. The patch starts each from its existing value, so the tree’s flags reach every compile line, with Marian’s own after them.marian-musl-no-execinfo.patch— Insrc/3rd_party/ExceptionWithCallStack.cpp, includes<execinfo.h>and walks the stack withbacktrace()only when__GLIBC__is defined. musl has neither the header nor the function, so on musl the call-stack dump prints one line saying the C library has nobacktrace().marian-musl-strerror-r.patch— Insrc/3rd_party/zstr/strict_fstream.hpp, takes the XSIstrerror_r()branch (it returns anint) whenever the C library is not glibc. The source picks the GNU branch, which expects achar *back, whenever_GNU_SOURCEis defined, and musl’sstrerror_ris XSI only.marian-no-git.patch— Replaces the custom command insrc/CMakeLists.txtthat writescommon/git_revision.hby runninggit log(and depends on.git/logs/HEAD) with a cache variable,MARIAN_GIT_REVISION, written into that header withfile(CONFIGURE). A source archive has no.git, so the command’s dependency on.git/logs/HEADcannot be met andgit loghas no repository to read.no-werror.patch— Removes-Werrorfrom Marian’sALL_WARNINGSlist and from intgemm’s compile options, so a warning the tree’s compiler raises does not stop the build.
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:
-DBUILD_ARCH=x86-64— The-march=value translateLocally and Marian put on every compile line. Upstream’s default isnative, which compiles for the build machine’s processor, and on that value Marian also probes the machine and adds-mavx2,-mavx512fand the rest. On any other value Marian adds-msse4.1on x86-64 instead, so the program needs a processor with SSE4.1. intgemm reads CPUID when it runs and picks its SSE2, SSSE3, AVX2, AVX-512BW or AVX-512 VNNI kernels then.-DMARIAN_GIT_REVISION="${_marian:0:7}"— The Marian revision compiled into its version string, here the first seven characters of the pinned commit. The option exists only withmarian-no-git.patch.-DCOMPILE_CUDA=OFF— No GPU build; CUDA is not a port.-DUSE_MKL=OFF— Marian’s default is to look for Intel MKL first, which is not a port. Off, it takes the OpenBLAS branch:BLAS_VENDORisOpenBLASand it looks for a CBLAS in openblas.-DUSE_STATIC_LIBS=OFF— translateLocally and bergamot-translator set thisON, which makes Marian link libgcc and libstdc++ statically and search for.afiles only. Off, the program links its libraries shared, found the way CMake finds them by default.-DUSE_DOXYGEN=OFF,-DUSE_CCACHE=OFF— No API documentation from Doxygen (on by default in Marian) and no compiler cache.-DCOMPILE_SERVER=OFF,-DCOMPILE_PYTHON=OFF,-DCOMPILE_TESTS=OFF— Build neithermarian-server, nor bergamot-translator’s Python bindings, nor its tests. All three are off upstream; they are named so a change of default cannot add them.-DBUILD_EXTERNAL_LIBARCHIVE=OFF— Link the system libarchive, which unpacks downloaded models, instead of building a copy as a CMake external project. This is upstream’s default, named so it cannot change.-DSSPLIT_USE_INTERNAL_PCRE2=OFF— ssplit-cpp links the system pcre2 rather than building its own. Also ssplit-cpp’s default, named so it cannot change.-DSSPLIT_PREFER_STATIC_COMPILE=OFF— Upstream’s default isON, which puts.aahead of.soin CMake’s library search. The tree installs no static PCRE2, so the search finds the shared library either way; off, it is not asked to prefer one that is not there.
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.