Skip to content

Commit d1e4c67

Browse files
committed
Move translations source path to config
1 parent 8eec135 commit d1e4c67

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

web/pandas/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ roadmap:
207207
translations:
208208
url: https://github.com/Scientific-Python-Translations/pandas-translations/archive/refs/heads/main.tar.gz
209209
folder: translations
210+
source_path: pandas-translations-main/web/pandas/
210211
default_language: 'en'
211212
ignore:
212213
- docs/

web/pandas_web.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ def download_and_extract_translations(url: str, dir_name: str):
467467
"""
468468
Download the translations from the GitHub repository.
469469
"""
470+
print(dir_name)
471+
shutil.rmtree(dir_name, ignore_errors=True)
470472
response = requests.get(url)
471473
if response.status_code == 200:
472474
doc = io.BytesIO(response.content)
@@ -480,26 +482,24 @@ def get_languages(source_path: str):
480482
"""
481483
Get the list of languages available in the translations directory.
482484
"""
483-
languages_path = f"{source_path}/pandas-translations-main/web/pandas/"
484-
en_path = f"{languages_path}/en/"
485+
en_path = f"{source_path}/en/"
485486
if os.path.exists(en_path):
486487
shutil.rmtree(en_path)
487488

488-
paths = os.listdir(languages_path)
489-
return [path for path in paths if os.path.isdir(f"{languages_path}/{path}")]
489+
paths = os.listdir(source_path)
490+
return [path for path in paths if os.path.isdir(f"{source_path}/{path}")]
490491

491492

492493
def copy_translations(source_path: str, target_path: str, languages: list[str]):
493494
"""
494495
Copy the translations to the appropriate directory.
495496
"""
496-
languages_path = f"{source_path}/pandas-translations-main/web/pandas/"
497497
for lang in languages:
498498
cmds = [
499499
"rsync",
500500
"-av",
501501
"--delete",
502-
f"{languages_path}/{lang}/",
502+
f"{source_path}/{lang}/",
503503
f"{target_path}/{lang}/",
504504
]
505505
p = Popen(cmds, stdout=PIPE, stderr=PIPE)
@@ -527,9 +527,16 @@ def main(
527527
translations_path = os.path.join(base_folder, f"{config['translations']['folder']}")
528528

529529
sys.stderr.write("Downloading and extracting translations...\n")
530-
download_and_extract_translations(config["translations"]["url"], translations_path)
530+
translations_extract_path = translations_path
531+
translations_source_path = os.path.join(
532+
translations_path, config["translations"]["source_path"]
533+
)
534+
535+
download_and_extract_translations(
536+
config["translations"]["url"], translations_extract_path
537+
)
531538

532-
translated_languages = get_languages(translations_path)
539+
translated_languages = get_languages(translations_source_path)
533540
default_language = config["translations"]["default_language"]
534541
languages = [default_language] + translated_languages
535542

@@ -596,7 +603,6 @@ def main(
596603
shutil.copy(
597604
os.path.join(source_path, fname), os.path.join(target_path, dirname)
598605
)
599-
return 0
600606

601607

602608
if __name__ == "__main__":

0 commit comments

Comments
 (0)