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 7666eb3

Browse filesBrowse files
committed
Move translations source path to config
1 parent 8eec135 commit 7666eb3
Copy full SHA for 7666eb3

File tree

Expand file treeCollapse file tree

4 files changed

+37
-26
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+37
-26
lines changed

‎.gitignore

Copy file name to clipboardExpand all lines: .gitignore
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,6 @@ doc/source/savefig/
146146
# Web & Translations #
147147
##############################
148148
web/translations/
149-
web/pandas/pt/
150149
web/pandas/es/
150+
web/pandas/pt/
151+
web/pandas/fr/

‎web/pandas/config.yml

Copy file name to clipboardExpand all lines: web/pandas/config.yml
+1Lines 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/static/js/language_switcher.js

Copy file name to clipboardExpand all lines: web/pandas/static/js/language_switcher.js
+13-12Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
window.addEventListener("DOMContentLoaded", function() {
2-
var BASE_URL = location.protocol + "//" + location.hostname + ":" + location.port
3-
var CURRENT_LANGUAGE = document.documentElement.lang;
4-
var PATHNAME = location.pathname.replace('/' + CURRENT_LANGUAGE + '/', '')
2+
var baseUrl = location.protocol + "//" + location.hostname
3+
if (location.port) {
4+
baseUrl = baseUrl + ":" + location.port
5+
}
6+
var currentLanguage = document.documentElement.lang;
57
var languages = JSON.parse(document.getElementById("languages").getAttribute('data-lang').replace(/'/g, '"'));
6-
const language_names = {
8+
const languageNames = {
79
'en': 'English',
810
'es': 'Español',
911
'fr': 'Français',
@@ -24,24 +26,23 @@ window.addEventListener("DOMContentLoaded", function() {
2426
link.setAttribute("role", "button");
2527
link.setAttribute("aria-haspopup", "true");
2628
link.setAttribute("aria-expanded", "false");
27-
link.textContent = language_names[CURRENT_LANGUAGE];
29+
link.textContent = languageNames[currentLanguage];
2830

2931
var dropdownMenu = document.createElement("div");
3032
dropdownMenu.classList.add("dropdown-menu");
3133

3234
options.forEach(function(i) {
3335
var dropdownItem = document.createElement("a");
3436
dropdownItem.classList.add("dropdown-item");
35-
dropdownItem.textContent = language_names[i] || i.toUpperCase();
37+
dropdownItem.textContent = languageNames[i] || i.toUpperCase();
3638
dropdownItem.setAttribute("href", "#");
3739
dropdownItem.addEventListener("click", function() {
38-
if (i == 'en') {
39-
URL_LANGUAGE = '';
40-
} else {
41-
URL_LANGUAGE = '/' + i;
40+
var urlLanguage = '';
41+
if (i !== 'en') {
42+
urlLanguage = '/' + i;
4243
}
43-
var PATHNAME = location.pathname.replace('/' + CURRENT_LANGUAGE + '/', '/')
44-
var newUrl = BASE_URL + URL_LANGUAGE + PATHNAME
44+
var pathName = location.pathname.replace('/' + currentLanguage + '/', '/')
45+
var newUrl = baseUrl + urlLanguage + pathName
4546
window.location.href = newUrl;
4647
});
4748
dropdownMenu.appendChild(dropdownItem);

‎web/pandas_web.py

Copy file name to clipboardExpand all lines: web/pandas_web.py
+21-13Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ def download_and_extract_translations(url: str, dir_name: str):
467467
"""
468468
Download the translations from the GitHub repository.
469469
"""
470+
shutil.rmtree(dir_name, ignore_errors=True)
470471
response = requests.get(url)
471472
if response.status_code == 200:
472473
doc = io.BytesIO(response.content)
@@ -480,30 +481,31 @@ def get_languages(source_path: str):
480481
"""
481482
Get the list of languages available in the translations directory.
482483
"""
483-
languages_path = f"{source_path}/pandas-translations-main/web/pandas/"
484-
en_path = f"{languages_path}/en/"
484+
en_path = f"{source_path}/en/"
485485
if os.path.exists(en_path):
486486
shutil.rmtree(en_path)
487487

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

491491

492492
def copy_translations(source_path: str, target_path: str, languages: list[str]):
493493
"""
494494
Copy the translations to the appropriate directory.
495495
"""
496-
languages_path = f"{source_path}/pandas-translations-main/web/pandas/"
497496
for lang in languages:
497+
dest = f"{target_path}/{lang}/"
498+
shutil.rmtree(dest, ignore_errors=True)
498499
cmds = [
499500
"rsync",
500501
"-av",
501502
"--delete",
502-
f"{languages_path}/{lang}/",
503-
f"{target_path}/{lang}/",
503+
f"{source_path}/{lang}/",
504+
dest,
504505
]
505506
p = Popen(cmds, stdout=PIPE, stderr=PIPE)
506507
stdout, stderr = p.communicate()
508+
sys.stderr.write(f"\nCopying: {lang}...\n\n")
507509
sys.stderr.write(stdout.decode())
508510
sys.stderr.write(stderr.decode())
509511

@@ -526,15 +528,22 @@ def main(
526528
config = get_config(base_config_fname)
527529
translations_path = os.path.join(base_folder, f"{config['translations']['folder']}")
528530

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

532-
translated_languages = get_languages(translations_path)
541+
translated_languages = get_languages(translations_source_path)
533542
default_language = config["translations"]["default_language"]
534543
languages = [default_language] + translated_languages
535544

536-
sys.stderr.write("Copying translations...\n")
537-
copy_translations(translations_path, source_path, translated_languages)
545+
sys.stderr.write("\nCopying translations...\n")
546+
copy_translations(translations_source_path, source_path, translated_languages)
538547

539548
for language in languages:
540549
sys.stderr.write(f"\nProcessing language: {language}...\n\n")
@@ -596,7 +605,6 @@ def main(
596605
shutil.copy(
597606
os.path.join(source_path, fname), os.path.join(target_path, dirname)
598607
)
599-
return 0
600608

601609

602610
if __name__ == "__main__":

0 commit comments

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