Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2b85ad4

Browse filesBrowse files
committed
Add script to import translations
1 parent 2e141aa commit 2b85ad4
Copy full SHA for 2b85ad4

File tree

Expand file treeCollapse file tree

3 files changed

+99
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+99
-0
lines changed

‎.github/workflows/docbuild-and-upload.yml

Copy file name to clipboardExpand all lines: .github/workflows/docbuild-and-upload.yml
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ jobs:
5050
# https://pytest-qt.readthedocs.io/en/latest/troubleshooting.html#github-actions-azure-pipelines-travis-ci-and-gitlab-ci-cd
5151
run: sudo apt-get update && sudo apt-get install -y libegl1 libopengl0
5252

53+
- name: Download and update translations
54+
run: python web/pandas_translations.py
55+
5356
- name: Test website
5457
run: python -m pytest web/
5558

‎.gitignore

Copy file name to clipboardExpand all lines: .gitignore
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,11 @@ doc/source/savefig/
141141
# Pyodide/WASM related files #
142142
##############################
143143
/.pyodide-xbuildenv-*
144+
145+
146+
# Web & Translations #
147+
##############################
148+
web/pandas-translations.tar.gz
149+
web/translations/
150+
web/pandas/pt/
151+
web/pandas/es/

‎web/pandas_translations.py

Copy file name to clipboard
+88Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import os
2+
from pathlib import Path
3+
from subprocess import (
4+
PIPE,
5+
Popen,
6+
)
7+
import tarfile
8+
9+
import requests
10+
import yaml
11+
12+
13+
def download_translations(url, fname):
14+
"""
15+
Download the translations from the GitHub repository.
16+
"""
17+
response = requests.get(url)
18+
if response.status_code == 200:
19+
with open(fname, "wb") as f:
20+
f.write(response.content)
21+
else:
22+
raise Exception(f"Failed to download translations: {response.status_code}")
23+
24+
25+
def extract_translations(fpath, dir_name):
26+
"""
27+
Extract the translations from the tar file.
28+
"""
29+
with tarfile.open(fpath, "r:gz") as tar:
30+
tar.extractall(dir_name)
31+
print(f"Translations extracted to '{dir_name}' directory.")
32+
33+
34+
def load_translations_config(path):
35+
"""
36+
Load the translations configuration from the YAML file.
37+
"""
38+
with open(path) as f:
39+
config = yaml.safe_load(f)
40+
return config
41+
42+
43+
def load_status_config(path):
44+
"""
45+
Load the translations configuration from the YAML file.
46+
"""
47+
with open(path) as f:
48+
config = yaml.safe_load(f)
49+
return config
50+
51+
52+
def copy_translations(data, translation_percentage, dir_name, dest_dir):
53+
"""
54+
Copy the translations to the appropriate directory.
55+
"""
56+
for lang, value in data.items():
57+
if value["progress"] >= translation_percentage:
58+
language_code = lang[:2]
59+
src_path = (
60+
f"{dir_name}/pandas-translations-main/web/pandas/{language_code}/"
61+
)
62+
dest_path = f"{dest_dir}/{language_code}/"
63+
cmds = ["rsync", "-av", "--delete", src_path, dest_path]
64+
p = Popen(cmds, stdout=PIPE, stderr=PIPE)
65+
stdout, stderr = p.communicate()
66+
print(stdout.decode())
67+
print(stderr.decode())
68+
69+
70+
if __name__ == "__main__":
71+
os.chdir(Path(__file__).parent.parent)
72+
url = "https://github.com/Scientific-Python-Translations/pandas-translations/archive/refs/heads/main.tar.gz"
73+
fpath = "web/pandas-translations.tar.gz"
74+
dir_name = "web/translations"
75+
config_path = (
76+
f"{dir_name}/pandas-translations-main/.github/workflows/sync_translations.yml"
77+
)
78+
status_path = f"{dir_name}/pandas-translations-main/status.yml"
79+
80+
download_translations(url, fpath)
81+
extract_translations(fpath, dir_name)
82+
config = load_translations_config(config_path)
83+
variables = config["jobs"]["sync_translations"]["steps"][0]["with"]
84+
translation_percentage = int(variables["translation-percentage"])
85+
status = load_status_config(status_path)
86+
copy_translations(
87+
status, translation_percentage, dir_name=dir_name, dest_dir="web/pandas"
88+
)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.