#5 Docs' internalization FAD
Merged 5 years ago by jibecfed. Opened 5 years ago by jibecfed.

cleanup
Jibec • 5 years ago  
fix doublepath
Jibec • 5 years ago  
file modified
+2 -1
@@ -1,2 +1,3 @@ 

  l10n/

- sources/ 

\ No newline at end of file

+ sources/

+ translated-sources/ 

\ No newline at end of file

file modified
+25 -52
@@ -1,12 +1,13 @@ 

- # Docs Translation Prototype

+ # Fedora Docs internatialization

  

- This is a prototype of a multi-language Fedora Docs build pipeline. Work is tracked in [https://taiga.fedorainfracloud.org/project/asamalik-antora-for-docs/epic/1](https://taiga.fedorainfracloud.org/project/asamalik-antora-for-docs/epic/1).

+ This is a prototype of a multi-language Fedora Docs build pipeline. Work is tracked in [https://fedoraproject.org/wiki/User:Jibecfed/fedoradoc-antora-localization](https://fedoraproject.org/wiki/User:Jibecfed/fedoradoc-antora-localization).

  

- These scripts work with:

+ The internatialization work with:

  

- * Fedora Docs sources — sources of the docs in an adoc format.

- * Translation repos — [pagure.io/projects/fedora-l10n/*](https://pagure.io/projects/fedora-l10n/%2A) — repositories holding POT and PO files, acting as a bridge between the Fedora Docs site and translators. This way, translators can choose any workflow with a translation engine of their choice. The only requirement is that they need to work with POT and PO files.

- * Translated sources - [pagure.io/fedora-docs/translated-sources/](https://pagure.io/fedora-docs/translated-sources/) — all translated adoc files used to build the translated site.

+ * Fedora Docs sources — sources of the docs in an adoc format. For full list of these, see [https://pagure.io/fedora-docs/docs-fp-o](site.yml in docs-fp-o).

+ * Translation scripts — [https://pagure.io/fedora-docs/translations-scripts/](https://pagure.io/fedora-docs/translations-scripts/) — scripts to convert from adoc to pot and from pot to adoc. 

+ * Translation repos — [https://pagure.io/projects/fedora-l10n/*](https://pagure.io/projects/fedora-l10n/%2A) — repositories holding POT and PO files, acting as a bridge between the Fedora Docs site and translators. This way, translators can choose any workflow with a translation engine of their choice. The only requirement is that they need to work with POT and PO files.

+ * Translated sources — [https://pagure.io/fedora-docs/translated-sources/](https://pagure.io/fedora-docs/translated-sources/) — all translated adoc files used to build the translated site.

  

  ## How to run

  
@@ -18,61 +19,33 @@ 

  

  ### Submitting sources for translation

  

- The `all-src-to-pot.sh` holds a list of repositories to be translated.

+ The `buid.py` script will find list of repositories to be translated in the file site.yml from the the docs-fp-o repo.

  It clones all of the specified source repositories, all of the matching translation repos,

  and converts the English sources into POT files. The output of this script are local copies of the translation repos, updated with the newly generated POT files.

  

- It takes one argument — an absolute path to an empty directory to store the output.

+ It takes the following arguments :

+   --clone_sources {true,false}

+                         Should we clone/update sources or use local content?

+   --commit_l10n {true,false}

+                         Should we commit changes on l10n repos?

+   --commit_tsources {true,false}

+                         Should we commit translated sources?

+   --component COMPONENT

+                         Antora component to convert, all if unset

  

- First, create an empty directory for the output and run the script:

+ The `buid.py` script will create three folders:

  

- ```

- $ mkdir translation-repos

- $ ./all-src-to-pot.sh $(pwd)/translation-repos

- ```

- 

- Now you have local copies of the translation repos under `./translation-repos`, with the updated POT files. The next step is to push the changes to each repo. Go to the directory, and list all the repos:

- 

- ```

- $ cd translation-repos

- $ ls

- docs  fedora  fedora-install-guide  fedora-release-notes

- ```

- 

- Then go to each repo, and push the changes. For example:

- 

- ```

- $ cd docs

- $ git add .

- $ git commit -m "refresh POT files"

- $ git push

- $ cd ..

- ```

- 

- Repeat this for each repo. And you're done.

- 

- ### Retrieving the translated sources

- 

- The `$ ./all-po-to-src.sh` holds a list of repositories to be translated and a list of target languages.

- The output is a local copy of the translated sources repo, updated with the newly generated adoc files.

- 

- [See the structure of the translated sources](https://pagure.io/fedora-docs/design-documents/blob/master/f/po-pot-repo-structure.md).

- 

- First, create a directory for the output and run the script:

- 

- ```

- $ mkdir translated-sources

- $ ./all-po-to-src.sh $(pwd)/translated-sources

- ```

+ * $(pwd)/sources — Fedora Docs sources

+ * $(pwd)/l10n — Translation repos

+ * $(pwd)/translated-sources — Translated sources

  

- Now you have a local copy of the translated sources repo, right in `./translated-sources`. To push the changes:

+ ### Publish translated sources

  

  ```

  $ cd translated-sources

- $ git add .

- $ git commit -m "update translated source"

+ $ git add.

+ $ git commit -m "automatic update of translated content"

  $ git push

- $ cd ..

  ```

  

  ### Rebuilding the translated website
@@ -89,5 +62,5 @@ 

  $ ./preview.sh

  ```

  

- Now you should be able to see, for example, the French site, on [http://localhost:8080/fr-FR/](http://localhost:8080/fr-FR/).

+ Now you should be able to see, for example, the French site, on [http://localhost:8080/fr/](http://localhost:8080/fr/).

  

file removed
-92
@@ -1,92 +0,0 @@ 

- #!/bin/bash

- 

- usage() {

-     echo "Calls './po-to-src.sh' for all source repos (hardcoded in this script)"

-     echo ""

-     echo "Usage"

-     echo "$0 TARGET_DIR"

-     echo ""

-     echo "TARGET_DIR   Output directory"

- }

- 

- # Need TARGET_DIR

- if [ "$1" != "" ]; then

-     output_dir="$1"

- else

-     usage

-     echo "Please specify TARGET_DIR"

-     exit 1

- fi

- 

- # TARGET_DIR need to exist

- if [ -d "$output_dir" ]; then

-     pushd $output_dir > /dev/null

-     output_dir=$(pwd)

-     popd > /dev/null

- else

-     echo "Error. The specified output directory doesn't exist"

-     exit 1

- fi

- 

- if ! git clone \

-             --config "remote.origin.pushurl=ssh://git@pagure.io/fedora-docs/translated-sources.git" \

-             "https://pagure.io/fedora-docs/translated-sources.git" $output_dir ; then

-     echo "Error cloning the translated sources repository."

-     exit 1

- fi

- 

- # cmd="./po-to-src.sh"

- # container

- cmd="podman run --rm -it -v $output_dir:/output:z -v $(pwd)/po-to-src.sh:/scripts/po-to-src.sh:z asamalik/fedora-docs-translations /scripts/po-to-src.sh "

- output_dir="/output"

- 

- 

- for language in "cs" "fr" "jp"; do 

-     # Convert the homepage

-     $cmd \

-         --src-basedir "pages/homepage" \

-         $language \

-         https://pagure.io/fedora-docs/docs-fp-o.git \

-         $output_dir

- 

-     # Convert the main page of the user guide

-     # that's pointing to the install guide,

-     # the release notes, and the sysadmin guide

-     $cmd \

-         --src-branch "f28" \

-         $language \

-         https://pagure.io/fedora-docs/release-docs-home.git \

-         $output_dir

- 

-     $cmd \

-         --src-branch "f29" \

-         $language \

-         https://pagure.io/fedora-docs/release-docs-home.git \

-         $output_dir

- 

-     # Convert the install guide

-     $cmd \

-         --src-branch "f28" \

-         $language \

-         https://pagure.io/fedora-docs/install-guide.git \

-         $output_dir

- 

-     $cmd \

-         --src-branch "f29" \

-         $language \

-         https://pagure.io/fedora-docs/install-guide.git \

-         $output_dir

- 

-     # Convert the release notes

-     $cmd \

-         --src-branch "f28" \

-         $language \

-         https://pagure.io/fedora-docs/release-notes.git \

-         $output_dir

- 

-     $cmd \

-         --src-branch "f29" \

-         $language \

-         https://pagure.io/fedora-docs/release-notes.git \

-         $output_dir

- done

file removed
-180
@@ -1,180 +0,0 @@ 

- #!/usr/bin/env python3

- """Calls `./po-to-src.sh` for all source repos"""

- 

- import argparse

- import os

- import urllib.request

- import subprocess

- import shlex

- import yaml

- 

- 

- def main():

-     """Handle params"""

-     parser = argparse.ArgumentParser(

-         description="Calls `./po-to-src.sh` for all source repos")

-     parser.add_argument("output_dir", help="Output directory")

-     args = parser.parse_args()

- 

-     output_dir = args.output_dir

-     source_dir = os.path.dirname(os.path.abspath(__file__)) + "/sources/"

- 

-     os.makedirs(output_dir, exist_ok=True)

-     os.makedirs(source_dir, exist_ok=True)

- 

-     output_dir = os.path.abspath(output_dir)

-     parse_yml(output_dir)

-     make_component_lists()

- 

- def call_podman_and_src_to_po(output_dir, doc):

-     command = "podman run --rm -it -v {o}:/output:z ".format(o=output_dir)

-     command += "-v {c}/src-to-pot.sh:/scripts/src-to-pot.sh:z ".format(c=os.getcwd())

-     command += "asamalik/fedora-docs-translations /scripts/src-to-pot.sh {d}".format(d=doc)

-     # print(command)

-     # args = shlex.split(command)

-     # subprocess.run(args, check=True)

- 

- def clone_source(url, branch = "master"):

-     repo_name = url.rsplit('/', 1)[-1].replace('.git', '')

-     dir = os.path.dirname(os.path.abspath(__file__)) + "/sources/" + repo_name

- 

-     if os.path.exists(dir):

-         subprocess.run(['git', 'fetch'], check=True, cwd = dir)

-         subprocess.run(['git', 'checkout', branch], check=True, cwd = dir)

-         subprocess.run(['git', 'pull'], check=True, cwd = dir)

-     else:

-         command = "git clone -b {b} {u} {d}".format(b = branch, u=url, d=dir)

-         print(command)

-         args = shlex.split(command)

-         subprocess.run(args, check=True)

- 

- def clone_l10n(url):

-     repo_name = url.rsplit('/', 1)[-1].replace('.git', '')

-     dir = os.path.dirname(os.path.abspath(__file__)) + "/l10n/" + repo_name

- 

-     if os.path.exists(dir):

-         subprocess.run(['git', 'pull'], check=True, cwd = dir)

-     else:

-         command = "git clone {u} {d}".format(u=url, d=dir)

-         print(command)

-         args = shlex.split(command)

-         subprocess.run(args, check=True)

- 

- def clone_sources():

-     """List repositories to convert to pot from antora yaml file"""

- 

-     # download site.yml

-     urllib.request.urlretrieve(

-         "https://pagure.io/fedora-docs/docs-fp-o/raw/master/f/site.yml", "site.yml"

-     )

- 

-     # Read site.yml

-     with open("site.yml", 'r') as stream:

-         data_loaded = yaml.load(stream, Loader=yaml.SafeLoader)

- 

-     # Parse site.yml

-     for source in data_loaded['content']['sources']:

-         url = source['url']

- 

-         if 'start_path' in source:

-             clone_source(url)

- 

-         elif 'branches' in source:

-             for branch in source['branches']:

-                 clone_source(url, branch)

-         else:

-             clone_source(url)

- 

- 

-     # Remove site.yml

-     os.remove("site.yml")

- 

- def get_component(dir, branch = 'master'):

-     subprocess.run(['git', 'fetch'], check=True, cwd = dir)

-     subprocess.run(['git', 'checkout', branch], check=True, cwd = dir)

- 

-     with open(dir + "/antora.yml", 'r') as stream:

-         data_loaded = yaml.load(stream, Loader=yaml.SafeLoader)

- 

-     component = data_loaded['name']

-     version = data_loaded['version']

- 

-     f = []

-     for (dirpath, dirnames, filenames) in os.walk(dir + "/modules"):

-         f.extend(dirnames)

-         break

- 

-     for module in f:

-         if module == "ROOT":

-             target_repo_name = component

-         else:

-             target_repo_name = component + "-" + module

-         clone_l10n("https://pagure.io/fedora-l10n/"+target_repo_name)

- 

- def make_component_lists():

-     """List repositories to convert to pot from antora yaml file"""

- 

-     # download site.yml

-     urllib.request.urlretrieve(

-         "https://pagure.io/fedora-docs/docs-fp-o/raw/master/f/site.yml", "site.yml"

-     )

- 

-     # Read site.yml

-     with open("site.yml", 'r') as stream:

-         data_loaded = yaml.load(stream, Loader=yaml.SafeLoader)

- 

-     # Parse site.yml

-     for source in data_loaded['content']['sources']:

-         url = source['url']

-         repo_name = url.rsplit('/', 1)[-1].replace('.git', '')

-         dir = os.path.dirname(os.path.abspath(__file__)) + "/sources/" + repo_name

- 

-         if 'start_path' in source:

-             get_component(dir+"/"+source['start_path'])

- 

-         elif 'branches' in source:

-             for branch in source['branches']:

-                 get_component(dir, branch)

-         else:

-             get_component(dir)

- 

-     # Remove site.yml

-     os.remove("site.yml")

- 

- def parse_yml(output_dir):

-     """List repositories to convert to pot from antora yaml file"""

- 

-     # download site.yml

-     urllib.request.urlretrieve(

-         "https://pagure.io/fedora-docs/docs-fp-o/raw/master/f/site.yml", "site.yml"

-     )

- 

-     # Read site.yml

-     with open("site.yml", 'r') as stream:

-         data_loaded = yaml.load(stream, Loader=yaml.SafeLoader)

- 

-     # Parse site.yml

-     for source in data_loaded['content']['sources']:

-         url = source['url']

- 

-         if 'start_path' in source:

-             src_basedir = source['start_path']

-             doc = "--clone-target-repo --src-basedir \"{bd}\" {url} /output".format(

-                 bd=src_basedir, url=url)

- 

-         elif 'branches' in source:

-             for branch in source['branches']:

-                 src_branch = branch

-                 doc = "--clone-target-repo --src-branch \"{br}\" {url} /output".format(

-                     br=src_branch, url=url)

-         else:

-             doc = "--clone-target-repo {url} /output".format(url=url)

- 

-         call_podman_and_src_to_po(output_dir, doc)

- 

-     # Remove site.yml

-     os.remove("site.yml")

- 

- 

- if __name__ == '__main__':

-     main()

file removed
-89
@@ -1,89 +0,0 @@ 

- #!/bin/bash

- 

- usage() {

-     echo "Calls './src-to-pot.sh' for all source repos (hardcoded in this script)"

-     echo ""

-     echo "Usage"

-     echo "$0 TARGET_DIR"

-     echo ""

-     echo "TARGET_DIR   Output directory"

- }

- 

- # Need TARGET_DIR

- if [ "$1" != "" ]; then

-     output_dir="$1"

- else

-     usage

-     echo "Please specify TARGET_DIR"

-     exit 1

- fi

- 

- # TARGET_DIR need to exist

- if [ -d "$output_dir" ]; then

-     pushd $output_dir > /dev/null

-     output_dir=$(pwd)

-     popd > /dev/null

- else

-     echo "Error. The specified output directory doesn't exist. Please create it first."

-     exit 1

- fi

- 

- # TARGET_DIR need to exist

- if [ -e "$output_dir/log.txt" ]; then

-     rm "$output_dir/log.txt"

- fi

- 

- 

- # container

- cmd="podman run --rm -it -v $output_dir:/output:z -v $(pwd)/src-to-pot.sh:/scripts/src-to-pot.sh:z asamalik/fedora-docs-translations /scripts/src-to-pot.sh "

- output_dir="/output"

- 

- 

- ### === Repository List === ###

- # The following is a "configuration" of which repos this script should work with.

- # 

- # Note: Some repos might be listed multiple times, once per branch. In that case,

- #       only the first entry should include the "--clone-target-repo" option.

- 

- # Convert the homepage

- $cmd \

-     --clone-target-repo \

-     --src-basedir "pages/homepage" \

-     https://pagure.io/fedora-docs/docs-fp-o.git \

-     $output_dir

- 

- # Convert the "release docs home" page

- $cmd \

-     --clone-target-repo \

-     --src-branch "f28" \

-     https://pagure.io/fedora-docs/release-docs-home.git \

-     $output_dir

- 

- $cmd \

-     --src-branch "f29" \

-     https://pagure.io/fedora-docs/release-docs-home.git \

-     $output_dir

- 

- # Convert the install guide

- $cmd \

-     --clone-target-repo \

-     --src-branch "f28" \

-     https://pagure.io/fedora-docs/install-guide.git \

-     $output_dir

- 

- $cmd \

-     --src-branch "f29" \

-     https://pagure.io/fedora-docs/install-guide.git \

-     $output_dir

- 

- # Convert the release notes

- $cmd \

-     --clone-target-repo \

-     --src-branch "f28" \

-     https://pagure.io/fedora-docs/release-notes.git \

-     $output_dir

- 

- $cmd \

-     --src-branch "f29" \

-     https://pagure.io/fedora-docs/release-notes.git \

-     $output_dir

file added
+241
@@ -0,0 +1,241 @@ 

+ #!/usr/bin/env python3

+ """Calls `./src-to-pot.sh` and `./po-to-src.sh` for all source repos"""

+ 

+ import argparse

+ import os

+ import urllib.request

+ import subprocess

+ 

+ from urllib.parse import urlparse

+ 

+ import yaml

+ 

+ SELECTED_COMPONENT = None

+ 

+ def main():

+     """Handle params"""

+     global SELECTED_COMPONENT

+ 

+     parser = argparse.ArgumentParser(

+         description="Calls `./src-to-pot.sh` and `./po-to-src.sh` for all source repos")

+     parser.add_argument("--clone_sources", choices=['true', 'false'], required=True,

+                         help="Should we clone/update sources or use local content?")

+     parser.add_argument("--commit_l10n", choices=['true', 'false'], required=True,

+                         help="Should we commit changes on l10n repos?")

+     parser.add_argument("--commit_tsources", choices=['true', 'false'], required=True,

+                         help="Should we commit translated sources?")

+     parser.add_argument("--component", required=False,

+                         help="Antora component to convert, all if unset")

+     args = parser.parse_args()

+ 

+     SELECTED_COMPONENT = args.component

+ 

+     source_dir = os.path.dirname(os.path.abspath(__file__)) + "/sources/"

+     trans_source_dir = os.path.dirname(os.path.abspath(__file__)) + "/translated-sources/"

+     l10n_dir = os.path.dirname(os.path.abspath(__file__)) + "/l10n/"

+ 

+     os.makedirs(source_dir, exist_ok=True)

+     os.makedirs(trans_source_dir, exist_ok=True)

+     os.makedirs(l10n_dir, exist_ok=True)

+ 

+     if args.clone_sources == "true":

+         clone_sources()

+ 

+     clone_translated_source()

+     make_component_lists()

+ 

+     if args.commit_l10n == "true":

+         commit_l10n_repos()

+ 

+     if args.commit_tsources == "true":

+         commit_translated_sources()

+ 

+ def call_src_to_pot(url, branch='master', basedir='/', module="ROOT"):

+     """Call src-to-ot.sh to convert english source (adoc) content to pot files"""

+     print("call_src_to_pot: "+url +" b:"+ branch +" bd:"+ basedir +" m:"+ module)

+     output = os.path.dirname(os.path.abspath(__file__)) + "/l10n/"

+ 

+     subprocess.run(['./src-to-pot.sh', "--src-branch", branch,

+                     "--src-basedir", basedir, "--module", module, url, output], check=True)

+ 

+ def call_po_to_src(url, branch='master', basedir='/', module="ROOT"):

+     """Call po-to-src.sh to convert po files to translated sources (adoc)"""

+     print("call_po_to_src: "+url +" b:"+ branch +" bd:"+ basedir +" m:"+ module)

+     output = os.path.dirname(os.path.abspath(__file__)) + "/translated-sources/"

+ 

+     subprocess.run(['./po-to-src.sh', "--src-branch", branch,

+                     "--src-basedir", basedir, "--module", module, url,

+                     output], check=True)

+ 

+ def clone_source(doc_url, branch="master"):

+     """Clone english sources in sources folder (update content if existing)"""

+     repo_name = urlparse(doc_url).hostname+urlparse(doc_url).path[1:].replace('.git', '')

+     repo_dir = os.path.dirname(os.path.abspath(__file__)) + "/sources/" + repo_name

+ 

+     if os.path.exists(repo_dir):

+         subprocess.run(['git', 'fetch'], check=True, cwd=repo_dir)

+         subprocess.run(['git', 'checkout', branch], check=True, cwd=repo_dir)

+         subprocess.run(['git', 'pull'], check=True, cwd=repo_dir)

+     else:

+         subprocess.run(["git", "clone", "-b", branch, doc_url, repo_dir], check=True)

+ 

+ def clone_l10n(repo_name):

+     """Clone localization repos in l10n folder (update content if existing)"""

+     print("* clone_l10n: " + repo_name)

+ 

+     url = "https://pagure.io/fedora-l10n/" + repo_name

+     repo_dir = os.path.dirname(os.path.abspath(__file__)) + "/l10n/" + repo_name

+ 

+     if os.path.exists(repo_dir):

+         subprocess.run(['git', 'pull'], check=True, cwd=repo_dir)

+     else:

+         subprocess.run(["git", "clone", url, repo_dir, "--config",

+                         "remote.origin.pushurl=ssh://git@pagure.io/fedora-l10n/{r}.git".format(r=repo_name)],

+                        check=True)

+ 

+ def clone_translated_source():

+     """Clone translated sources (update content if existing)"""

+     print("* clone_translated_source")

+     repo_dir = os.path.dirname(os.path.abspath(__file__)) + "/translated-sources/"

+ 

+     url = "ssh://git@pagure.io/fedora-docs/translated-sources.git"

+ 

+     if os.path.exists(repo_dir):

+         subprocess.run(['git', 'pull'], check=True, cwd=repo_dir)

+     else:

+         subprocess.run(["git", "clone", url, repo_dir], check=True)

+ 

+ def commit_translated_source():

+     """Commit translated sources"""

+     print("* commit_translated_source")

+     repo_dir = os.path.dirname(os.path.abspath(__file__)) + "/translated-sources/"

+ 

+     subprocess.run(['git', 'add', '.'], check=True, cwd=repo_dir)

+ 

+     subprocess.run(["git", "commit", "-m", "automatic update of translated content"],

+                    check=True, cwd=repo_dir)

+ 

+     subprocess.run(['git', 'push'], check=True, cwd=repo_dir)

+ 

+ 

+ def commit_l10n_repos():

+     """Commit and push changes of localization repositories"""

+ 

+     print("* commit_l10n_repos")

+     repo_dir = os.path.dirname(os.path.abspath(__file__)) + "/l10n/"

+ 

+     # commit each folders of the l10n path

+     [commit_l10n(r) for r in next(os.walk(repo_dir))[1]]

+ 

+ 

+ def commit_l10n(repo_name):

+     """Commit and push changes of a localization repo"""

+ 

+     print("* commit_l10n: " + repo_name)

+ 

+     url = "https://pagure.io/fedora-l10n/" + repo_name

+     repo_dir = os.path.dirname(os.path.abspath(__file__)) + "/l10n/" + repo_name

+ 

+     subprocess.run(['git', 'add', '.'], check=True, cwd=repo_dir)

+ 

+     subprocess.run(["git", "commit", "-m", "automatic update of pot/po files"],

+                    check=True, cwd=repo_dir)

+ 

+     subprocess.run(['git', 'push'], check=True, cwd=repo_dir)

+ 

+ def clone_sources():

+     """List sources repositories from antora yaml file"""

+     print("* clone_sources:")

+ 

+     # download site.yml

+     urllib.request.urlretrieve(

+         "https://pagure.io/fedora-docs/docs-fp-o/raw/master/f/site.yml", "site.yml"

+     )

+ 

+     # Read site.yml

+     with open("site.yml", 'r') as stream:

+         data_loaded = yaml.load(stream, Loader=yaml.SafeLoader)

+ 

+     # Parse site.yml

+     for source in data_loaded['content']['sources']:

+         doc_url = source['url']

+ 

+         if 'start_path' in source:

+             clone_source(doc_url)

+ 

+         elif 'branches' in source:

+             for branch in source['branches']:

+                 clone_source(doc_url, branch)

+         else:

+             clone_source(doc_url)

+ 

+ 

+     # Remove site.yml

+     os.remove("site.yml")

+ 

+ def get_component(comp_dir, basedir='/', branch='master'):

+     """Run actions on the component (clone repos, run scripts, commit changes)"""

+     print("\n\nget_component: "+ comp_dir + "/" + basedir + " " + branch)

+     subprocess.run(['git', 'fetch'], check=True, cwd=comp_dir)

+     subprocess.run(['git', 'checkout', branch], check=True, cwd=comp_dir)

+     subprocess.run(['git', 'pull'], check=True, cwd=comp_dir)

+ 

+     with open(comp_dir +"/"+ basedir + "/antora.yml", 'r') as stream:

+         data_loaded = yaml.load(stream, Loader=yaml.SafeLoader)

+ 

+     component = data_loaded['name']

+     version = data_loaded['version']

+ 

+     if SELECTED_COMPONENT not in (None, component):

+         print("--component was set to {s}, ignoring {c}".format(s=SELECTED_COMPONENT, c=component))

+         return

+ 

+     modules = []

+     for (dirpath, dirnames, filenames) in os.walk(comp_dir + "/" + basedir + "/modules"):

+         modules.extend(dirnames)

+         break

+ 

+     if not modules:

+         raise ValueError('There should be at least one module!')

+ 

+     for module in modules:

+         if module == "ROOT":

+             target_repo_name = component

+         else:

+             target_repo_name = component + "-" + module

+         clone_l10n(target_repo_name)

+         call_src_to_pot(url=comp_dir, basedir=basedir, branch=branch, module=module)

+         call_po_to_src(url=comp_dir, basedir=basedir, branch=branch, module=module)

+ 

+ def make_component_lists():

+     """Deduct the component name from site.yml (l10n repos are per component)"""

+ 

+     # download site.yml

+     urllib.request.urlretrieve(

+         "https://pagure.io/fedora-docs/docs-fp-o/raw/master/f/site.yml", "site.yml"

+     )

+ 

+     # Read site.yml

+     with open("site.yml", 'r') as stream:

+         data_loaded = yaml.load(stream, Loader=yaml.SafeLoader)

+ 

+     # Parse site.yml

+     for source in data_loaded['content']['sources']:

+         doc_url = source['url']

+         repo_name = urlparse(doc_url).hostname+urlparse(doc_url).path[1:].replace('.git', '')

+         repo_dir = os.path.dirname(os.path.abspath(__file__)) + "/sources/" + repo_name

+ 

+         if 'start_path' in source:

+             get_component(repo_dir, basedir=source['start_path'])

+ 

+         elif 'branches' in source:

+             for branch in source['branches']:

+                 get_component(repo_dir, branch=branch)

+         else:

+             get_component(repo_dir)

+ 

+     # Remove site.yml

+     os.remove("site.yml")

+ 

+ if __name__ == '__main__':

+     main()

file modified
+95 -98
@@ -9,7 +9,6 @@ 

      echo "Arguments:"

      echo "  REPO_URL        Source repository URL."

      echo "  OUTPUT_DIR      Path to an output directory."

-     echo "  LOCALE          What language to work with. Such as 'fr-FR'."

      echo ""

      echo "Parametres:"

      echo "  Generic:"
@@ -51,16 +50,6 @@ 

      esac

  done

  

- # Need LOCALE

- if [ "$1" != "" ]; then

-     language=$1

-     shift

- else

-     usage

-     echo "Please specify LOCALE, REPO_URL and TARGET_DIR"

-     exit 1

- fi

- 

  # Need REPO_URL

  if [ "$1" != "" ]; then

      src_repo=$1
@@ -82,9 +71,9 @@ 

  

  # TARGET_DIR need to exist

  if [ -d "$output_dir" ]; then

-     pushd $output_dir > /dev/null

+     pushd "$output_dir" > /dev/null || exit

      output_dir=$(pwd)

-     popd > /dev/null

+     popd > /dev/null || exit

  else

      echo "Error. The specified output directory doesn't exist"

      exit 1
@@ -98,15 +87,17 @@ 

      src_basedir=""

  fi

  

+ echo "*****************"

+ echo "* po-to-src"

+ echo "*****************"

+ 

  tmp_english_src=$(mktemp -d)

- tmp_po_pot=$(mktemp -d)

  

  delete_tmp() {

      rm -rf "$tmp_english_src"

-     rm -rf "$tmp_po_pot"

  }

  

- if ! git clone -b $src_branch $src_repo $tmp_english_src ; then

+ if ! git clone -b "$src_branch" "$src_repo" "$tmp_english_src" ; then

      echo ""

      echo "Error cloning the specified git repository."

      delete_tmp
@@ -131,7 +122,7 @@ 

  

  

  

- pushd "$tmp_english_src/$src_basedir" > /dev/null

+ pushd "$tmp_english_src/$src_basedir" > /dev/null || exit

  

  # Get component name from the antora.yml

  component=$(sed -n 's/^name: *\"*\([[:alnum:]_-]*\).*/\1/p' antora.yml)
@@ -144,7 +135,7 @@ 

  #   2) the user specified it using --module MODULE and it exists

  # In case there are multiple modules under ./modules/

  # and the user hasn't specified one, throw an error.

- if [ ! $(ls -1 ./modules | wc -l) = 1 ] && [ -z $module ]; then

+ if [ ! $(ls -1 ./modules | wc -l) = 1 ] && [ -z "$module" ]; then

      echo ""

      echo "Error. This repository contains multiple antora modules,"

      echo "and the script doesn't know which one to choose."
@@ -157,7 +148,7 @@ 

      exit 1

  fi

  

- if [ -z $module ]; then

+ if [ -z "$module" ]; then

      module=$(ls ./modules)

  fi

  
@@ -173,23 +164,24 @@ 

      exit 1

  fi

  

- popd > /dev/null

+ popd > /dev/null || exit

  

- if [ $module = "ROOT" ]; then

+ if [ "$module" = "ROOT" ]; then

      po_pot_repo_name="$component"

  else

      po_pot_repo_name="$component-$module"

  fi

  

+ tmp_po_pot="/home/jean-baptiste/Projects/fedora-l10n/translations-scripts/l10n/$po_pot_repo_name"

  

- if ! git clone "https://pagure.io/fedora-l10n/$po_pot_repo_name.git" "$tmp_po_pot" ; then

-     echo ""

-     echo "Error cloning the PO/POT repository."

-     echo "It might not exist. It should be here:"

-     echo "https://pagure.io/fedora-l10n/$po_pot_repo_name"

-     delete_tmp

-     exit 1

- fi

+ # if ! git clone "https://pagure.io/fedora-l10n/$po_pot_repo_name.git" "$tmp_po_pot" ; then

+ #     echo ""

+ #     echo "Error cloning the PO/POT repository."

+ #     echo "It might not exist. It should be here:"

+ #     echo "https://pagure.io/fedora-l10n/$po_pot_repo_name"

+ #     delete_tmp

+ #     exit 1

+ # fi

      

  

  
@@ -205,78 +197,83 @@ 

  # Missing po for .adoc: the .adoc just get s copied

  #

  # TODO: stretch idea: if the translations don't exist, I could just copy

- # the english sources over... this could simplify automation 

- 

- #po_pot_module_dir="$output_dir/$po_pot_repo_name/pot/$version"

- po_pot_module_dir="$tmp_po_pot/po/$language/$version"

- output_module_dir="$output_dir/$language/$component/$version/modules/$module"

- 

- # Make sure the language exists in the PO/POT repo

- if [ ! -d "$tmp_po_pot/po/$language" ] ; then

-     echo "Error. Locale $language doesn't exist in the PO/POT repo."

-     delete_tmp

-     exit 1

- fi

+ # the english sources over... this could simplify automation

+ 

+ for lang_folder in "$tmp_po_pot/po/"* ; do

+     [[ -d "$lang_folder" ]] || break # if no result

+ 

+     language=$(basename $lang_folder)

+     echo "*****************"

+     echo "* LANG: $language"

+     echo "*****************"

+     #po_pot_module_dir="$output_dir/$po_pot_repo_name/pot/$version"

+     po_pot_module_dir="$tmp_po_pot/po/$language/$version"

+     output_module_dir="$output_dir/$language/$component/$version/modules/$module"

+ 

+     # Confert all .adoc files to .pot

+     pushd "$tmp_english_src/$src_basedir/modules/$module" > /dev/null || exit

+ 

+     for source_adoc_file in $(find . -name '*.adoc'); do

+         po_file="$po_pot_module_dir/$(dirname "$source_adoc_file")/$(basename -s .adoc "$source_adoc_file").po"

+         target_adoc_file="$output_module_dir/$(dirname "$source_adoc_file")/$(basename -s .adoc "$source_adoc_file").adoc"

+ 

+         format="asciidoc"

+         # nav.adoc is a bullet point list, it isn't really asciidoc

+         if [ "$(basename -s .adoc "$source_adoc_file")" = "nav" ] ; then

+             format="text"

+         fi

  

- # Confert all .adoc files to .pot

- pushd "$tmp_english_src/$src_basedir/modules/$module" > /dev/null

- 

- for source_adoc_file in $(find . -name '*.adoc'); do

-     po_file="$po_pot_module_dir/$(dirname $source_adoc_file)/$(basename -s .adoc $source_adoc_file).po"

-     target_adoc_file="$output_module_dir/$(dirname $source_adoc_file)/$(basename -s .adoc $source_adoc_file).adoc"

-     if [ -f "$po_file" ] ; then

-         # TODO: convert file

-         if ! po4a-translate \

-             --format asciidoc \

-             --option debug split_attributelist \

-             --master "$source_adoc_file" \

-             --master-charset "UTF-8" \

-             --po "$po_file" \

-             --localized "$target_adoc_file" \

-             --localized-charset "UTF-8" \

-             --keep 0

-         then

-             echo "Error converting a PO file: $po_file"

-             delete_tmp

-             exit 1

+         if [ -f "$po_file" ] ; then

+             # TODO: convert file

+             if ! po4a-translate \

+                 --format "$format" \

+                 --master "$source_adoc_file" \

+                 --master-charset "UTF-8" \

+                 --po "$po_file" \

+                 --localized "$target_adoc_file" \

+                 --localized-charset "UTF-8" \

+                 --keep 0

+             then

+                 echo "Error converting a PO file: $po_file"

+                 delete_tmp

+                 exit 1

+             fi

+         else

+             # "Warning: The following file is in the source, but not in the translations repo:"

+             mkdir -p "$(dirname "$target_adoc_file")"

+             cp "$source_adoc_file" "$target_adoc_file"

+         fi

+     done

+ 

+     popd > /dev/null || exit

+ 

+ 

+     # Convert the antora.yml to antora.yml.pot

+     # if this is the main module

+     if [ "$module" = "ROOT" ]; then

+         pushd "$tmp_english_src/$src_basedir" > /dev/null || exit

+ 

+         source_antora_yml="$tmp_english_src/$src_basedir/antora.yml"

+         po_antora_yml="$tmp_po_pot/po/$language/$version/antora.yml.po"

+         target_antora_yml="$output_dir/$language/$component/$version/antora.yml"

+ 

+         if [ -f "$po_antora_yml" ] ; then

+             po4a-translate \

+                 --format yaml \

+                 --option keys="title" \

+                 --master "$source_antora_yml" \

+                 --master-charset "UTF-8" \

+                 --po "$po_antora_yml" \

+                 --localized "$target_antora_yml" \

+                 --localized-charset "UTF-8" \

+                 --keep 0

+         else

+             # "Warning: There should be an antora.yml.po, but there isn't."

+             mkdir -p "$(dirname "$target_antora_yml")"

+             cp "$source_antora_yml" "$target_antora_yml"

          fi

-     else

-         echo "Warning: The following file is in the source, but not in the translations repo:"

-         echo "         $source_adoc_file"

-         echo "         Copying the original over. You might need to update the PO/POT repo."

-         cp "$source_adoc_file" "$target_adoc_file"

+         popd > /dev/null || exit

      fi

  done

  

- popd > /dev/null

- 

- 

- # Convert the antora.yml to antora.yml.pot

- # if this is the main module

- if [ $module = "ROOT" ]; then

-     pushd "$tmp_english_src/$src_basedir" > /dev/null

- 

-     source_antora_yml="$tmp_english_src/$src_basedir/antora.yml"

-     po_antora_yml="$tmp_po_pot/po/$language/$version/antora.yml.po"

-     target_antora_yml="$output_dir/$language/$component/$version/antora.yml"

- 

-     if [ -f "$po_antora_yml" ] ; then

-         po4a-translate \

-             --format yaml \

-             --option keys="title" \

-             --master "$source_antora_yml" \

-             --master-charset "UTF-8" \

-             --po "$po_antora_yml" \

-             --localized "$target_antora_yml" \

-             --localized-charset "UTF-8" \

-             --keep 0

-     else

-         echo "Warning: There should be an antora.yml.po, but there isn't."

-         echo "         Copying it from the original source."

-         cp "$source_antora_yml" "$target_antora_yml"

-     fi

-     popd > /dev/null

- fi

- 

- 

  delete_tmp

file modified
+114 -46
@@ -80,9 +80,9 @@ 

  

  # TARGET_DIR need to exist

  if [ -d "$output_dir" ]; then

-     pushd $output_dir > /dev/null

+     pushd "$output_dir" > /dev/null || exit

      output_dir=$(pwd)

-     popd > /dev/null

+     popd > /dev/null || exit

  else

      echo "Error. The specified output directory doesn't exist"

      exit 1
@@ -98,7 +98,7 @@ 

  

  tmp_english_src=$(mktemp -d)

  

- if ! git clone -b $src_branch $src_repo $tmp_english_src ; then

+ if ! git clone -b $src_branch "$src_repo" "$tmp_english_src" ; then

      echo ""

      echo "Error cloning the specified git repository."

      rm -rf "$tmp_english_src"
@@ -123,7 +123,7 @@ 

  

  

  

- pushd "$tmp_english_src/$src_basedir" > /dev/null

+ pushd "$tmp_english_src/$src_basedir" > /dev/null || exit

  

  # Get component name from the antora.yml

  component=$(sed -n 's/^name: *\"*\([[:alnum:]_-]*\).*/\1/p' antora.yml)
@@ -136,7 +136,7 @@ 

  #   2) the user specified it using --module MODULE and it exists

  # In case there are multiple modules under ./modules/

  # and the user hasn't specified one, throw an error.

- if [ ! $(ls -1 ./modules | wc -l) = 1 ] && [ -z $module ]; then

+ if [ ! $(ls -1 ./modules | wc -l) = 1 ] && [ -z "$module" ]; then

      echo ""

      echo "Error. This repository contains multiple antora modules,"

      echo "and the script doesn't know which one to choose."
@@ -149,7 +149,7 @@ 

      exit 1

  fi

  

- if [ -z $module ]; then

+ if [ -z "$module" ]; then

      module=$(ls ./modules)

  fi

  
@@ -165,15 +165,15 @@ 

      exit 1

  fi

  

- popd > /dev/null

+ popd > /dev/null || exit

  

- if [ $module = "ROOT" ]; then

+ if [ "$module" = "ROOT" ]; then

      target_repo_name="$component"

  else

      target_repo_name="$component-$module"

  fi

  

- if [ "$clone_target_repo_name" ]; then

+ if [ "$clone_target_repo_name" = true ]; then

      if [ -d "$output_dir/$target_repo_name" ]; then

          echo ""

          echo "Error. You chose to clone the target repo,"
@@ -203,18 +203,26 @@ 

  

  module_dir="$output_dir/$target_repo_name/pot/$version"

  

+ echo "*************************"

+ echo "* convert .adoc to .pot"

+ echo "*************************"

  

  # Confert all .adoc files to .pot

- pushd "$tmp_english_src/$src_basedir/modules/$module" > /dev/null

+ pushd "$tmp_english_src/$src_basedir/modules/$module" > /dev/null || exit

  

- for adoc_file in $(find . -name '*.adoc'); do

-     pot_file="$module_dir/$(dirname $adoc_file)/$(basename -s .adoc $adoc_file).pot"

+ while IFS= read -r -d '' adoc_file

+ do

+     pot_file="$module_dir/$(dirname "$adoc_file")/$(basename -s .adoc "$adoc_file").pot"

  

+     format="asciidoc"

+     # nav.adoc is a bullet point list, it isn't really asciidoc

+     if [ "$(basename -s .adoc "$adoc_file")" = "nav" ] ; then

+         format="text"

+     fi

      # generate new POT files

  

      if ! po4a-gettextize \

-                 --format asciidoc \

-                 --option debug split_attributelist \

+                 --format "$format" \

                  --master "$adoc_file" \

                  --master-charset "UTF-8" \

                  --localized-charset "UTF-8" \
@@ -224,43 +232,70 @@ 

          rm -rf "$tmp_english_src"

          exit 1

      fi

+ done <   <(find . -name '*.adoc' -print0)

  

-     # Update existing PO files

- 

-     if [ -d "$output_dir/$target_repo_name/po" ] ; then

- 

-         for lang in $(ls "$output_dir/$target_repo_name/po"); do

- 

-             po_file="$output_dir/$target_repo_name/po/$lang/$version/$(dirname $adoc_file)/$(basename -s .adoc $adoc_file).po"

+ echo "*************************"

+ echo "* update po files"

+ echo "*************************"

  

-             # po4a-updatepo would be angry otherwise

-             sed -i 's/Content-Type: text\/plain; charset=CHARSET/Content-Type: text\/plain; charset=UTF-8/g' $po_file

- 

-             if ! po4a-updatepo \

-                         --format asciidoc \

-                         --option debug split_attributelist \

-                         --master "$adoc_file" \

-                         --master-charset "UTF-8" \

-                         --po "$po_file" ; then

-                 echo ""

-                 echo "Error updating $lang PO file for: $adoc_file"

-                 #rm -rf "$tmp_english_src"

-                 #exit 1

+ while IFS= read -r -d '' adoc_file

+ do

+     pot_file="$module_dir/$(dirname "$adoc_file")/$(basename -s .adoc "$adoc_file").pot"

+     # Update existing PO files

+     # Make sure there is a po folder

+     mkdir -p "$output_dir/$target_repo_name/po"

+ 

+     echo " * $output_dir/$target_repo_name/po/"

+     for lang in "$output_dir/$target_repo_name/po/"* ; do

+         if [[ ! -d "$output_dir/$target_repo_name/po/$lang" ]] ; then

+             # because weblate needs at least one lang folder to detect files

+             mkdir -p "$output_dir/$target_repo_name/po/fr/"

+             lang="fr"

+         fi

+ 

+         po_file="$output_dir/$target_repo_name/po/$lang/$version/$(dirname "$adoc_file")/$(basename -s .adoc "$adoc_file").po"

+ 

+         if [ ! -e "$po_file" ] ; then

+             # because weblate needs at least one po file to detect files

+             if [ "$lang" = "fr" ] ; then

+                 mkdir -p "$(dirname "$po_file")"

+                 cp "$pot_file" "$po_file"

              fi

-         done

-     fi

- done

- 

- popd > /dev/null

- 

+             # the po file don't exist, of if we just created it don't update it"

+             break

+         fi

+         # po4a-updatepo would be angry otherwise

+         sed -i 's/Content-Type: text\/plain; charset=CHARSET/Content-Type: text\/plain; charset=UTF-8/g' "$po_file"

+ 

+         format="asciidoc"

+         # nav.adoc is a bullet point list, it isn't really asciidoc

+         if [ "$(basename -s .adoc "$adoc_file")" = "nav" ] ; then

+             format="text"

+         fi

+ 

+         if ! po4a-updatepo \

+                     --format "$format" \

+                     --master "$adoc_file" \

+                     --master-charset "UTF-8" \

+                     --po "$po_file" ; then

+             echo ""

+             echo "Error updating $lang PO file for: $adoc_file"

+         fi

+     done

+ done <   <(find . -name '*.adoc' -print0)

+ 

+ popd > /dev/null || exit

+ 

+ echo "*************************"

+ echo "* convert antora.yml to .pot"

+ echo "*************************"

  

  # Convert the antora.yml to antora.yml.pot

  # if this is the main module

- if [ $module = "ROOT" ]; then

-     pushd "$tmp_english_src/$src_basedir" > /dev/null

+ if [ "$module" = "ROOT" ]; then

+     pushd "$tmp_english_src/$src_basedir" > /dev/null || exit

      if ! po4a-gettextize \

-                 --format asciidoc \

-                 --option debug split_attributelist \

+                 --format yaml \

                  --master "antora.yml" \

                  --master-charset "UTF-8" \

                  --po "$module_dir/antora.yml.pot" ; then
@@ -269,10 +304,43 @@ 

          rm -rf "$tmp_english_src"

          exit 1

      fi

-     popd > /dev/null

+     popd > /dev/null || exit

  fi

  

+ echo "*************************"

+ echo "* update po file"

+ echo "*************************"

+ 

+ if [ "$module" = "ROOT" ]; then

+     pushd "$tmp_english_src/$src_basedir" > /dev/null || exit

+     pot_file="$module_dir/antora.yml.pot"

+ 

+     for lang in "$output_dir/$target_repo_name/po/"* ; do

+         po_file="$output_dir/$target_repo_name/po/$lang/$version/antora.yml.po"

+ 

+         if [ ! -e "$po_file" ] ; then

+             # because weblate needs at least one po file to detect files

+             if [ "$lang" = "fr" ] ; then

+                 cp "$pot_file" "$po_file"

+             fi

+             # the po file don't exist, of if we just created it don't update it"

+             break

+         fi

+         # po4a-updatepo would be angry otherwise

+         sed -i 's/Content-Type: text\/plain; charset=CHARSET/Content-Type: text\/plain; charset=UTF-8/g' "$po_file"

+ 

+         if ! po4a-updatepo \

+                     --format asciidoc \

+                     --master "antora.yml" \

+                     --master-charset "UTF-8" \

+                     --po "$po_file" ; then

+             echo ""

+             echo "Error updating $lang PO file for: $adoc_file"

+         fi

+     done

+     popd > /dev/null || exit

+ fi

  

- rm -rf $tmp_english_src

+ rm -rf "$tmp_english_src"

  

  echo -ne "Source: $src_repo basedir:$src_basedir branch:$src_branch is using this repository for pot/po files:https://pagure.io/fedora-l10n/$target_repo_name\n" >> "$output_dir/log.txt" 

\ No newline at end of file

here is the work we did together.

we rewrote all-po-to-src.sh and all-src-to-pot.sh in a build.py script

4 new commits added

  • fix navigation issue
  • make po-to-src language agnostic
  • add translated-sources commit and moved commit_l10n
  • update README and help messages
5 years ago

Pull-Request has been merged by jibecfed

5 years ago