Unverified Commit c944da85 authored by Izorkin's avatar Izorkin Committed by Sandro Jäckel
Browse files

python3Packages.libretranslate: create static gzip and brotli files

parent 5329805c
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
{
  lib,
  pkgs,
  buildPythonPackage,
  fetchFromGitHub,
  pytestCheckHook,
  runCommand,
  hatchling,
  argostranslate,
  flask,
@@ -15,6 +17,7 @@
  expiringdict,
  langdetect,
  lexilang,
  libretranslate,
  ltpycld2,
  morfessor,
  appdirs,
@@ -26,6 +29,7 @@
  prometheus-client,
  polib,
  python,
  xorg,
}:

buildPythonPackage rec {
@@ -85,6 +89,26 @@ buildPythonPackage rec {

  pythonImportsCheck = [ "libretranslate" ];

  passthru = {
    static-compressed =
      runCommand "libretranslate-data-compressed"
        {
          nativeBuildInputs = [
            pkgs.brotli
            xorg.lndir
          ];
        }
        ''
          mkdir -p $out/share/libretranslate/static
          lndir ${libretranslate}/share/libretranslate/static $out/share/libretranslate/static

          # Create static gzip and brotli files
          find -L $out -type f -regextype posix-extended -iregex '.*\.(css|ico|js|svg|ttf)' \
            -exec gzip --best --keep --force {} ';' \
            -exec brotli --best --keep --no-copy-stat {} ';'
        '';
  };

  meta = with lib; {
    description = "Free and Open Source Machine Translation API. Self-hosted, no limits, no ties to proprietary services";
    homepage = "https://libretranslate.com";