#!/bin/sh1#2# Copyright (c) 2021 Danilo G. Baio <[email protected]>3# Copyright (c) 2021 Fernando Apesteguia <[email protected]>4#5# Redistribution and use in source and binary forms, with or without6# modification, are permitted provided that the following conditions are met:7#8# 1. Redistributions of source code must retain the above copyright notice, this9# list of conditions and the following disclaimer.10#11# 2. Redistributions in binary form must reproduce the above copyright notice,12# this list of conditions and the following disclaimer in the documentation13# and/or other materials provided with the distribution.14#15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED17# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE18# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR21# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER22# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,23# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE24# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2526#########################################################27# This is a temporary fix for po4a-translate command #28# po4a: Fix YAML Front Matter / tags and trademarks #29# https://wiki.freebsd.org/Doc/IdeaList#Translation #30# $1: File to fix #31#########################################################32fixup_lists()33{34sed -i '' -E -e "s/(tags|trademarks).*'\[(.*)]'/\1: [\2]/g" "${1}"35}3637#########################################################38# Fix includes. In a few cases we want to include the #39# master (aka English) version of the includes #40# $1: file to fix #41# $2: language #42#########################################################43fixup_includes()44{45# Replace ...shared/en/... with shared/$LANGUAGE46# content/en with content/$LANGUAGE in includes47sed -i '' -E -e "s,include::(.*)shared/en/,include::\1shared/${2}/," \48-e "s,\{include-path\}(contrib*),content/en/articles/contributors/\1," \49-e "s,include-path: content/en/,include-path: content/${2}/," \50-e "s,(include::.*)contrib-develinmemoriam(.*),include::{include-path}contrib-develinmemoriam\2," \51-e "s,(:chapters-path: |include::)content/en/books,\1content/${2}/books," \52"${1}"53}5455if [ "$1" = "" ] || [ "$2" = "" ]; then56echo "Need to inform component and language:"57echo " $0 documentation es"58echo "A third (optional) argument can be informed to translate only a specific document:"59echo " $0 documentation pt-br articles/bsdl-gpl"60exit 161fi6263COMPONENT="$1"64LANGUAGE="$2"65SEARCH_RESTRICT="$3"6667# po4a-translate option: -k, --keep68# Minimal threshold for translation percentage to keep (i.e. write)69# the resulting file (default: 80). I.e. by default, files have to be70# translated at least at 80% to get written.71# # KEEP_ENV=10 ./tools/translate.sh documentation pt_BR72KEEP="${KEEP_ENV:-80}"7374if [ "$LANGUAGE" = "en" ]; then75echo "Language 'en' can't be translated."76exit 177fi7879if [ ! -d "$COMPONENT/content/$LANGUAGE" ]; then80echo "$COMPONENT/content/$LANGUAGE does not exist."81exit 182fi8384for pofile in $(find "$COMPONENT/content/$LANGUAGE/$SEARCH_RESTRICT" -name "*.po"); do85name=$(basename -s .po "$pofile")86if [ "$name" = "chapters-order" ]; then87continue88fi8990dirbase=$(dirname "$pofile")91adoc_lang="$dirbase/$name.adoc"92adoc_orig=$(echo "$adoc_lang" | sed s,$COMPONENT/content/$LANGUAGE,$COMPONENT/content/en,)9394echo "....."95echo "$pofile"9697po4a-updatepo \98--format asciidoc \99--option compat=asciidoctor \100--option tablecells=1 \101--option yfm_keys=title,part,description \102--master "$adoc_orig" \103--master-charset "UTF-8" \104--copyright-holder "The FreeBSD Project" \105--package-name "FreeBSD Documentation" \106--po "$pofile"107if [ -f "${pofile}~" ]; then108rm -f "${pofile}~"109fi110111po4a-translate \112--format asciidoc \113--option compat=asciidoctor \114--option tablecells=1 \115--option yfm_keys=title,part,description \116--master "$adoc_orig" \117--master-charset "UTF-8" \118--po "$pofile" \119--localized "$adoc_lang" \120--localized-charset "UTF-8" \121--keep "$KEEP"122123fixup_lists "${adoc_lang}"124fixup_includes "${adoc_lang}" "${LANGUAGE}"125done126127128129