-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Implement translations infrastructure #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
base: main
Are you sure you want to change the base?
Changes from all commits
d7f0545
17063a7
8eec135
7666eb3
30efbba
f8e6a02
de291cd
0d2bfff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<html lang="{{ selected_language }}"> | ||
<head> | ||
<script defer data-domain="pandas.pydata.org" src="https://views.scientific-python.org/js/script.js"></script> | ||
<title>pandas - Python Data Analysis Library</title> | ||
|
@@ -15,6 +15,82 @@ | |
href="{{ base_url }}{{ stylesheet }}"> | ||
{% endfor %} | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css"> | ||
<script type="text/javascript"> | ||
window.addEventListener("DOMContentLoaded", function() { | ||
var absBaseUrl = document.baseURI; | ||
var baseUrl = location.protocol + "//" + location.hostname | ||
if (location.port) { | ||
baseUrl = baseUrl + ":" + location.port | ||
} | ||
var currentLanguage = document.documentElement.lang; | ||
var languages = [ | ||
{% for lang, name in translations["languages"].items() -%} | ||
"{{ lang }}", | ||
{% endfor -%} | ||
] | ||
var languageNames = { | ||
{% for lang, name in translations["languages"].items() -%} | ||
{{ lang }}: '{{ name }}', | ||
{% endfor -%} | ||
} | ||
|
||
// Handle preview URLs on github | ||
// If preview URL changes, this regex will need to be updated | ||
var re = /preview\/pandas-dev\/pandas\/(?<pr>[0-9]*)\//g; | ||
var previewUrl = ''; | ||
for (const match of absBaseUrl.matchAll(re)) { | ||
previewUrl = `/preview/pandas-dev/pandas/${match.groups.pr}`; | ||
} | ||
var pathName = location.pathname.replace(previewUrl, '') | ||
|
||
// Create dropdown menu | ||
function makeDropdown(options) { | ||
var dropdown = document.createElement("li"); | ||
dropdown.classList.add("nav-item"); | ||
dropdown.classList.add("dropdown"); | ||
|
||
var link = document.createElement("a"); | ||
link.classList.add("nav-link"); | ||
link.classList.add("dropdown-toggle"); | ||
link.setAttribute("data-bs-toggle", "dropdown"); | ||
link.setAttribute("href", "#"); | ||
link.setAttribute("role", "button"); | ||
link.setAttribute("aria-haspopup", "true"); | ||
link.setAttribute("aria-expanded", "false"); | ||
link.textContent = languageNames[currentLanguage]; | ||
|
||
var dropdownMenu = document.createElement("div"); | ||
dropdownMenu.classList.add("dropdown-menu"); | ||
|
||
options.forEach(function(i) { | ||
var dropdownItem = document.createElement("a"); | ||
dropdownItem.classList.add("dropdown-item"); | ||
dropdownItem.textContent = languageNames[i] || i.toUpperCase(); | ||
dropdownItem.setAttribute("href", "#"); | ||
dropdownItem.addEventListener("click", function() { | ||
var urlLanguage = ''; | ||
if (i !== 'en') { | ||
urlLanguage = '/' + i; | ||
} | ||
pathName = pathName.replace('/' + currentLanguage + '/', '/') | ||
var newUrl = baseUrl + previewUrl + urlLanguage + pathName | ||
window.location.href = newUrl; | ||
}); | ||
dropdownMenu.appendChild(dropdownItem); | ||
}); | ||
|
||
dropdown.appendChild(link); | ||
dropdown.appendChild(dropdownMenu); | ||
return dropdown; | ||
} | ||
|
||
var container = document.getElementById("language-switcher-container"); | ||
if (container) { | ||
var dropdown = makeDropdown(languages); | ||
container.appendChild(dropdown); | ||
} | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<header> | ||
|
@@ -28,7 +104,7 @@ | |
|
||
<div class="collapse navbar-collapse" id="nav-content"> | ||
<ul class="navbar-nav ms-auto"> | ||
{% for item in navbar %} | ||
{% for item in navbar[selected_language] %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it's just me, but I find |
||
{% if not item.has_subitems %} | ||
<li class="nav-item"> | ||
<a class="nav-link" href="{% if not item.target.startswith("http") %}{{ base_url }}{% endif %}{{ item.target }}">{{ item.name }}</a> | ||
|
@@ -50,6 +126,8 @@ | |
</li> | ||
{% endif %} | ||
{% endfor %} | ||
<!-- Language switcher --> | ||
<div id="language-switcher-container"></div> | ||
</ul> | ||
</div> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,39 +25,6 @@ static: | |
css: | ||
- static/css/pandas.css | ||
- static/css/codehilite.css | ||
navbar: | ||
- name: "About us" | ||
target: | ||
- name: "About pandas" | ||
target: about/ | ||
- name: "Project roadmap" | ||
target: about/roadmap.html | ||
- name: "Governance" | ||
target: about/governance.html | ||
- name: "Team" | ||
target: about/team.html | ||
- name: "Sponsors" | ||
target: about/sponsors.html | ||
- name: "Citing and logo" | ||
target: about/citing.html | ||
- name: "Getting started" | ||
target: getting_started.html | ||
- name: "Documentation" | ||
target: docs/ | ||
- name: "Community" | ||
target: | ||
- name: "Blog" | ||
target: community/blog/ | ||
- name: "Ask a question (StackOverflow)" | ||
target: https://stackoverflow.com/questions/tagged/pandas | ||
- name: "Code of conduct" | ||
target: community/coc.html | ||
- name: "Ecosystem" | ||
target: community/ecosystem.html | ||
- name: "Benchmarks" | ||
target: community/benchmarks.html | ||
- name: "Contribute" | ||
target: contribute.html | ||
blog: | ||
num_posts: 50 | ||
posts_path: community/blog | ||
|
@@ -204,3 +171,14 @@ sponsors: | |
kind: partner | ||
roadmap: | ||
pdeps_path: pdeps | ||
translations: | ||
url: https://github.com/Scientific-Python-Translations/pandas-translations/archive/refs/heads/main.tar.gz | ||
folder: translations | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are extracting directly to the final directory, I guess this is not needed anymore. |
||
source_path: pandas-translations-main/web/pandas/ | ||
default_language: 'en' | ||
default_prefix: '' | ||
Comment on lines
+178
to
+179
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel free to disagree, but English will always be the base language, I'd personally hardcode it where needed, and not have a setting for it. Not sure what's the default prefix, is this something we'll ever change? |
||
languages: | ||
en: English | ||
es: Español | ||
pt: Português | ||
# fr: Français |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
navbar: | ||
- name: "About us" | ||
target: | ||
- name: "About pandas" | ||
target: about/ | ||
- name: "Project roadmap" | ||
target: about/roadmap.html | ||
- name: "Governance" | ||
target: about/governance.html | ||
- name: "Team" | ||
target: about/team.html | ||
- name: "Sponsors" | ||
target: about/sponsors.html | ||
- name: "Citing and logo" | ||
target: about/citing.html | ||
- name: "Getting started" | ||
target: getting_started.html | ||
- name: "Documentation" | ||
target: docs/ | ||
translated: false | ||
- name: "Community" | ||
target: | ||
- name: "Blog" | ||
target: community/blog/ | ||
- name: "Ask a question (StackOverflow)" | ||
target: https://stackoverflow.com/questions/tagged/pandas | ||
- name: "Code of conduct" | ||
target: community/coc.html | ||
- name: "Ecosystem" | ||
target: community/ecosystem.html | ||
- name: "Benchmarks" | ||
target: community/benchmarks.html | ||
- name: "Contribute" | ||
target: contribute.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you want to create it with javascript instead of having the html in the template?