Skip to content

Update CI to include Translations from Scientific Python Repo #61380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/docbuild-and-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ jobs:
# https://pytest-qt.readthedocs.io/en/latest/troubleshooting.html#github-actions-azure-pipelines-travis-ci-and-gitlab-ci-cd
run: sudo apt-get update && sudo apt-get install -y libegl1 libopengl0

- name: Download and update translations
run: python web/pandas_translations.py

- name: Test website
run: python -m pytest web/

Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,11 @@ doc/source/savefig/
# Pyodide/WASM related files #
##############################
/.pyodide-xbuildenv-*


# Web & Translations #
##############################
web/pandas-translations.tar.gz
web/translations/
web/pandas/pt/
web/pandas/es/
89 changes: 89 additions & 0 deletions web/pandas_translations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import os
from pathlib import Path
from subprocess import (
PIPE,
Popen,
)
import tarfile

import requests
import yaml


def download_translations(url, fname):
"""
Download the translations from the GitHub repository.
"""
response = requests.get(url)
if response.status_code == 200:
with open(fname, "wb") as f:
f.write(response.content)
else:
raise Exception(f"Failed to download translations: {response.status_code}")


def extract_translations(fpath, dir_name):
"""
Extract the translations from the tar file.
"""
with tarfile.open(fpath, "r:gz") as tar:
tar.extractall(dir_name)
print(f"Translations extracted to '{dir_name}' directory.")


def load_translations_config(path):
"""
Load the translations configuration from the YAML file.
"""
with open(path) as f:
config = yaml.safe_load(f)
return config


def load_status_config(path):
"""
Load the translations configuration from the YAML file.
"""
with open(path) as f:
config = yaml.safe_load(f)
return config


def copy_translations(data, translation_percentage, dir_name, dest_dir):
"""
Copy the translations to the appropriate directory.
"""
for lang, value in data.items():
if value["progress"] >= translation_percentage:
language_code = lang[:2]
src_path = (
f"{dir_name}/pandas-translations-main/web/pandas/{language_code}/"
)
dest_path = f"{dest_dir}/{language_code}/"
cmds = ["rsync", "-av", "--delete", src_path, dest_path]
p = Popen(cmds, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate()
print(stdout.decode())
print(stderr.decode())


if __name__ == "__main__":
os.chdir(Path(__file__).parent.parent)
url = "https://github.com/Scientific-Python-Translations/pandas-translations/archive/refs/heads/main.tar.gz"
fpath = "web/pandas-translations.tar.gz"
dir_name = "web/translations"
dest_dir = "web/pandas"
config_path = (
f"{dir_name}/pandas-translations-main/.github/workflows/sync_translations.yml"
)
status_path = f"{dir_name}/pandas-translations-main/status.yml"

download_translations(url, fpath)
extract_translations(fpath, dir_name)
config = load_translations_config(config_path)
variables = config["jobs"]["sync_translations"]["steps"][0]["with"]
translation_percentage = int(variables["translation-percentage"])
status = load_status_config(status_path)
copy_translations(
status, translation_percentage, dir_name=dir_name, dest_dir=dest_dir
)
Loading