-
-
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
Open
goanpeca
wants to merge
9
commits into
pandas-dev:main
Choose a base branch
from
goanpeca:translations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+174
−52
Open
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d7f0545
Add script to import translations
goanpeca 17063a7
Update scripts to handle tranlsations
goanpeca 8eec135
Merge branch 'main' of github.com:pandas-dev/pandas into translations
goanpeca 7666eb3
Move translations source path to config
goanpeca 30efbba
Fix language switcher to handle previews
goanpeca f8e6a02
Simplify scripts and logic
goanpeca de291cd
Process all languages in a single step
goanpeca 0d2bfff
Simplify code and move download and extract to pandas_web
goanpeca ac0b8f0
Create preprocessor and fix review comments
goanpeca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
goanpeca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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] %} | ||
goanpeca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{% 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> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not sure if the two first items are relevant anymore. Also, since the languages will keep changing, not sure if I'd delete all these ignores, so we don't need to maintain them here too. But up to you.