aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/mk/doc.commands.mk5
-rw-r--r--share/mk/doc.docbook.mk52
2 files changed, 57 insertions, 0 deletions
diff --git a/share/mk/doc.commands.mk b/share/mk/doc.commands.mk
index cbefc8b3db..c40cce9f2c 100644
--- a/share/mk/doc.commands.mk
+++ b/share/mk/doc.commands.mk
@@ -70,8 +70,13 @@ HTML2PDBOPTS?= -y -d0 -Idef ${HTML2PDBFLAGS}
HTML2TXT?= ${PREFIX}/bin/links
HTML2TXTOPTS?= -dump ${HTML2TXTFLAGS}
+ITSTOOL?= ${PREFIX}/bin/itstool
+
JING?= ${PREFIX}/bin/jing
+MSGFMT?= ${PREFIX}/bin/msgfmt
+MSGMERGE?= ${PREFIX}/bin/msgmerge
+
XMLLINT?= ${PREFIX}/bin/xmllint
XSLTPROC?= ${PREFIX}/bin/xsltproc
diff --git a/share/mk/doc.docbook.mk b/share/mk/doc.docbook.mk
index 1a01928e7e..f794e7a412 100644
--- a/share/mk/doc.docbook.mk
+++ b/share/mk/doc.docbook.mk
@@ -270,6 +270,58 @@ ${DOC}.parsed.xml: ${SRCS} ${XML_INCLUDES}
${SED} 's|@@URL_RELPREFIX@@|http://www.FreeBSD.org|g' < ${.TARGET} > ${DOC}.parsed.print.xml
${SED} -i '' -e 's|@@URL_RELPREFIX@@|../../../..|g' ${.TARGET}
+# translation -------------------------------------------------------
+
+# Master English document
+MASTERDOC_EN?= ${MASTERDOC:S/${LANGCODE}/en_US.ISO8859-1/}
+TRAN_DIR?= ${MASTERDOC:H}
+EN_DIR?= ${TRAN_DIR:S/${LANGCODE}/en_US.ISO8859-1/}
+PO_LANG?= ${LANGCODE:C/\..*$//}
+PO_CHARSET?= ${LANGCODE:tl:C/^.*\.//:S/^iso/iso-/:S/utf-8/UTF-8/}
+CLEANFILES+= ${DOC}.translate.xml ${PO_LANG}.mo ${PO_LANG}.mo
+
+# fix settings in PO file
+POSET_CMD= ${SED} -i '' -e 's,^\(\"Language-Team:.*\\n\"\),\1\${.newline}\"Language: ${PO_LANG}\\n\",' \
+ -e 's,^\"Content-Type: text/plain; charset=.*\\n,\"Content-Type: text/plain; charset=${PO_CHARSET}\\n,'
+
+.if ${.TARGETS:Mpo} || ${.TARGETS:Mtran}
+${DOC}.translate.xml:
+ @if [ "${TRAN_DIR}" == "${EN_DIR}" ]; then \
+ ${ECHO} "build PO file in a non-English dir" ; \
+ exit 1 ; \
+ fi
+ # normalize the English original into a single file
+ @${XMLLINT} --nonet --noent --valid --xinclude ${MASTERDOC_EN} > ${.TARGET}.tmp
+ # remove redundant namespace attributes
+ @${XMLLINT} --nsclean ${.TARGET}.tmp > ${.TARGET}
+ @${RM} ${.TARGET}.tmp
+
+po: ${PO_LANG}.po
+.PHONY: po
+${PO_LANG}.po: ${DOC}.translate.xml
+ @${ITSTOOL} -o ${PO_LANG}.po.tmp ${DOC}.translate.xml
+ @( if [ -f "${PO_LANG}.po" ]; then \
+ echo "${PO_LANG}.po exists, merging" ; \
+ ${MSGMERGE} -o ${PO_LANG}.po.new ${PO_LANG}.po ${PO_LANG}.po.tmp ;\
+ ${MV} ${PO_LANG}.po.new ${PO_LANG}.po ; \
+ ${RM} ${PO_LANG}.po.tmp ; \
+ else \
+ ${ECHO} "${PO_LANG}.po created, please check and correct the settings in the header" ; \
+ ${MV} ${PO_LANG}.po.tmp ${PO_LANG}.po ; \
+ ${POSET_CMD} ${.TARGET} ; \
+ fi )
+
+${PO_LANG}.mo: ${PO_LANG}.po
+ @${MSGFMT} -o ${.TARGET} ${.ALLSRC}
+
+tran ${DOC}.xml: ${DOC}.translate.xml ${PO_LANG}.mo
+ @if [ "${TRAN_DIR}" = "${EN_DIR}" ]; then \
+ ${ECHO} "build translation in a non-English dir" ; \
+ exit 1 ; \
+ fi
+ ${ITSTOOL} -l ${PO_LANG} -m ${PO_LANG}.mo -o ${DOC}.xml ${DOC}.translate.xml
+.endif
+
# XHTML -------------------------------------------------------------
index.html: ${DOC}.parsed.xml ${LOCAL_IMAGES_LIB} ${LOCAL_IMAGES_PNG} \