From owner-dev-commits-doc-all@freebsd.org Thu Apr 8 01:03:34 2021 Return-Path: Delivered-To: dev-commits-doc-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9847C5C9F00 for ; Thu, 8 Apr 2021 01:03:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FG3123zYXz3KZ3; Thu, 8 Apr 2021 01:03:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7B53F2940B; Thu, 8 Apr 2021 01:03:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 13813YGJ082314; Thu, 8 Apr 2021 01:03:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 13813YWF082313; Thu, 8 Apr 2021 01:03:34 GMT (envelope-from git) Date: Thu, 8 Apr 2021 01:03:34 GMT Message-Id: <202104080103.13813YWF082313@gitrepo.freebsd.org> To: doc-committers@FreeBSD.org, dev-commits-doc-all@FreeBSD.org From: "Danilo G. Baio" Subject: git: b5f7b600ed - main - Add helper scripts for translations MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dbaio X-Git-Repository: doc X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b5f7b600edd24cd1eca235f8fab631821de98e78 Auto-Submitted: auto-generated X-BeenThere: dev-commits-doc-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the doc repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Apr 2021 01:03:34 -0000 The branch main has been updated by dbaio (ports committer): URL: https://cgit.FreeBSD.org/doc/commit/?id=b5f7b600edd24cd1eca235f8fab631821de98e78 commit b5f7b600edd24cd1eca235f8fab631821de98e78 Author: Danilo G. Baio AuthorDate: 2021-04-08 00:54:11 +0000 Commit: Danilo G. Baio CommitDate: 2021-04-08 00:58:05 +0000 Add helper scripts for translations Already using them on Weblate FreeBSD, https://translate-dev.freebsd.org/. Approved by: bcr, gjb (doceng) Differential Revision: https://reviews.freebsd.org/D29569 --- tools/translate.sh | 78 +++++++++++++++++++++++++++++++ tools/update_translate_template.sh | 94 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+) diff --git a/tools/translate.sh b/tools/translate.sh new file mode 100755 index 0000000000..cb4005611d --- /dev/null +++ b/tools/translate.sh @@ -0,0 +1,78 @@ +#!/bin/sh +# +# Copyright (c) 2021 Danilo G. Baio +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +if [ "$1" = "" ] || [ "$2" = "" ]; then + echo "Need to inform which component and|or language." + echo "$0 documentation|website pt_BR|es" + exit 1 +fi + +COMPONENT="$1" +LANGUAGE="$2" + +# po4a-translate option: -k, --keep +# Minimal threshold for translation percentage to keep (i.e. write) +# the resulting file (default: 80). I.e. by default, files have to be +# translated at least at 80% to get written. +# # KEEP_ENV=10 ./tools/translate.sh documentation pt_BR +KEEP="${KEEP_ENV:-80}" + +if [ "$LANGUAGE" = "en" ]; then + echo "Language 'en' can't be translated." + exit 1 +fi + +if [ ! -d "$COMPONENT/content/$LANGUAGE" ]; then + echo "$COMPONENT/content/$LANGUAGE does not exist." + exit 1 +fi + +for pofile in $(find "$COMPONENT/content/$LANGUAGE/" -name "*.po" ); do + name=$(basename -s .po "$pofile") + if [ "$name" = "chapters-order" ]; then + continue + fi + + dirbase=$(dirname "$pofile") + adoc_lang="$dirbase/$name.adoc" + adoc_orig=$(echo "$adoc_lang" | sed s,$COMPONENT/content/$LANGUAGE,$COMPONENT/content/en,) + + echo "....." + echo "$pofile" + + po4a-translate \ + --format asciidoc \ + --option compat=asciidoctor \ + --option yfm_keys=title,part \ + --master "$adoc_orig" \ + --master-charset "UTF-8" \ + --po "$pofile" \ + --localized "$adoc_lang" \ + --localized-charset "UTF-8" \ + --keep "$KEEP" + +done + diff --git a/tools/update_translate_template.sh b/tools/update_translate_template.sh new file mode 100755 index 0000000000..4bb5699d2e --- /dev/null +++ b/tools/update_translate_template.sh @@ -0,0 +1,94 @@ +#!/bin/sh +# +# Copyright (c) 2021 Danilo G. Baio +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +ALL_COMPONENTS="documentation +website" + +COMPONENTS="${1:-$ALL_COMPONENTS}" + +GIT_IGNORE_FILES="toc-examples.adoc +toc-figures.adoc +toc-tables.adoc +toc.adoc +toc-1.adoc +toc-2.adoc +toc-3.adoc +toc-4.adoc +toc-5.adoc" + +for remove_file in $GIT_IGNORE_FILES; do + find documentation/content/en/ -name "$remove_file" -delete -print || exit 1 +done + +for component in $COMPONENTS; do + + if [ ! -d "$component/content/en" ]; then + echo "Directory '$component/content/en' not found." + exit 1 + fi + + for document in $(find "$component/content/en/" -name "*.adoc" ); do + name=$(basename -s .adoc "$document") + + # Ignore some files + if [ "$name" = "chapters-order" ]; then + continue + fi + + if [ "$document" = "documentation/content/en/books/books.adoc" ]; then + continue + fi + + dirbase=$(dirname "$document") + echo "$document" + + if [ -f "$dirbase/$name.po" ]; then + po4a-updatepo \ + --format asciidoc \ + --option compat=asciidoctor \ + --option yfm_keys=title,part \ + --master "$document" \ + --master-charset "UTF-8" \ + --copyright-holder "The FreeBSD Project" \ + --package-name "FreeBSD Documentation" \ + --po "$dirbase/$name.po" + if [ -f "$dirbase/$name.po~" ]; then + rm -f "$dirbase/$name.po~" + fi + else + po4a-gettextize \ + --format asciidoc \ + --option compat=asciidoctor \ + --option yfm_keys=title,part \ + --master "$document" \ + --master-charset "UTF-8" \ + --copyright-holder "The FreeBSD Project" \ + --package-name "FreeBSD Documentation" \ + --po "$dirbase/$name.po" + fi + done +done +