PORTNAME=	translate-toolkit
PORTVERSION=	3.19.17
CATEGORIES=	textproc
MASTER_SITES=	PYPI \
		https://github.com/translate/translate/releases/download/${PORTVERSION}/
DISTNAME=	translate_toolkit-${PORTVERSION}

MAINTAINER=	sunpoet@FreeBSD.org
COMMENT=	Tools and API for translation and localization engineering
WWW=		https://toolkit.translatehouse.org/ \
		https://github.com/translate/translate

LICENSE=	GPLv3+
LICENSE_FILE=	${WRKSRC}/COPYING

BUILD_DEPENDS=	${PYTHON_PKGNAMEPREFIX}setuptools>=61:devel/py-setuptools@${PY_FLAVOR} \
		${PYTHON_PKGNAMEPREFIX}wheel>=0:devel/py-wheel@${PY_FLAVOR} \
		${RUN_DEPENDS}
RUN_DEPENDS=	bash:shells/bash \
		msghack:devel/gettext-msghack \
		${PYTHON_PKGNAMEPREFIX}lxml>=6.1.0<7.0:devel/py-lxml@${PY_FLAVOR} \
		${PYTHON_PKGNAMEPREFIX}sqlite3>=0:databases/py-sqlite3@${PY_FLAVOR} \
		${PYTHON_PKGNAMEPREFIX}unicode-segmentation-rs>=0.2.0<0.4:textproc/py-unicode-segmentation-rs@${PY_FLAVOR}

USES=		gettext python:3.11+ shebangfix
USE_PYTHON=	autoplist noflavors pep517

NO_ARCH=	yes

SHEBANG_FILES=	tools/*

MANPAGES=	android2po \
		arb2po \
		asciidoc2po \
		csv2po \
		csv2tbx \
		dtd2po \
		flatxml2po \
		html2po \
		ical2po \
		idml2po \
		ini2po \
		json2po \
		md2po \
		mdx2po \
		moz2po \
		mozlang2po \
		odf2po \
		odf2xliff \
		oo2po \
		oo2xliff \
		php2po \
		po2asciidoc \
		po2csv \
		po2dtd \
		po2flatxml \
		po2html \
		po2ical \
		po2idml \
		po2ini \
		po2json \
		po2md \
		po2mdx \
		po2moz \
		po2mozlang \
		po2odf \
		po2oo \
		po2php \
		po2prop \
		po2rc \
		po2resx \
		po2sub \
		po2symb \
		po2tiki \
		po2tmx \
		po2ts \
		po2txt \
		po2web2py \
		po2wordfast \
		po2wxl \
		po2xliff \
		po2yaml \
		pot2po \
		prop2po \
		rc2po \
		resx2po \
		sub2po \
		symb2po \
		tbx2po \
		tiki2po \
		ts2po \
		txt2po \
		web2py2po \
		wxl2po \
		xliff2odf \
		xliff2oo \
		yaml2po

OPTIONS_DEFINE=	ALL CHARDET FLUENT ICAL INI LEVENSHTEIN MARKDOWN PHP RC SPELLCHECK SUBTITLES TOML YAML
OPTIONS_DEFAULT=ALL CHARDET FLUENT ICAL INI LEVENSHTEIN MARKDOWN PHP RC SPELLCHECK SUBTITLES TOML YAML
OPTIONS_SUB=	yes
ALL_DESC=	All optional dependencies
ALL_IMPLIES=	CHARDET FLUENT ICAL INI LEVENSHTEIN MARKDOWN PHP RC SPELLCHECK SUBTITLES TOML YAML
CHARDET_DESC=	Encoding detection
FLUENT_DESC=	Fluent translation format support
ICAL_DESC=	iCal format support
INI_DESC=	INI format support
LEVENSHTEIN_DESC=	Faster matching using Levenshtein
MARKDOWN_DESC=	Markdown format support
PHP_DESC=	PHP format support
RC_DESC=	Windows Resource (.rc) format support
SPELLCHECK_DESC=Enchant spellchecking system
SUBTITLES_DESC=	Subtitles format support
YAML_DESC=	YAML format support

CHARDET_RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}charset-normalizer>=3.4.0<4.0:textproc/py-charset-normalizer@${PY_FLAVOR}
FLUENT_RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}fluent.syntax>=0.19.0<0.20:textproc/py-fluent.syntax@${PY_FLAVOR}
FLUENT_VARS=		MANPAGES+="fluent2po"
ICAL_RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}vobject>=0.9.6.1:deskutils/py-vobject@${PY_FLAVOR}
ICAL_VARS=		MANPAGES+="ical2po po2ical"
INI_RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}iniparse>=0.5:devel/py-iniparse@${PY_FLAVOR}
INI_VARS=		MANPAGES+="ini2po po2ini"
LEVENSHTEIN_RUN_DEPENDS=${PYTHON_PKGNAMEPREFIX}rapidfuzz>=3.14.0:devel/py-rapidfuzz@${PY_FLAVOR}
MARKDOWN_RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}mistletoe>=1.4.0<1.7.0:textproc/py-mistletoe@${PY_FLAVOR}
MARKDOWN_VARS=		MANPAGES+="md2po po2md"
PHP_RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}phply>=1.2.6<1.3:devel/py-phply@${PY_FLAVOR}
PHP_VARS=		MANPAGES+="php2po po2php"
RC_RUN_DEPENDS=		${PYTHON_PKGNAMEPREFIX}pyparsing>=3.2.0<3.4:devel/py-pyparsing@${PY_FLAVOR}
RC_VARS=		MANPAGES+="po2rc rc2po"
SPELLCHECK_RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}enchant>=3.3.0:textproc/py-enchant@${PY_FLAVOR}
SUBTITLES_RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}aeidon>=1.15<1.17:textproc/py-aeidon@${PY_FLAVOR}
TOML_RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}tomlkit>=0.13.0<0.16.0:textproc/py-tomlkit@${PY_FLAVOR}
TOML_VARS=		MANPAGES+="toml2po po2toml"
YAML_RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}ruamel.yaml>=0.19.1<0.20.0:devel/py-ruamel.yaml@${PY_FLAVOR}
YAML_VARS=		MANPAGES+="po2yaml yaml2po"

.include <bsd.port.options.mk>

post-build:
	@${MKDIR} ${WRKSRC}/manpages
.for manpage in ${MANPAGES}
	cd ${WRKSRC}/build/lib/translate/convert && ${SETENVI} ${WRK_ENV} PYTHONPATH=${WRKSRC}/build/lib ${PYTHON_CMD} ${manpage}.py --man > ${WRKSRC}/manpages/${manpage}.1
.endfor

post-install:
	${INSTALL_MAN} ${WRKSRC}/manpages/* ${STAGEDIR}${PREFIX}/share/man/man1

.include <bsd.port.mk>
