Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ jobs:
submodules: recursive
- name: Setup Python
uses: actions/setup-python@v4
- name: Install python dependencies
run: |
python -m pip install --upgrade pip
pip install pyyaml
- name: Generate config.yaml
run: python gen_config.py
- name: Publish Site
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
generated/
public/
resources/
config.yaml
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ help: ## show this help
prepare:
git submodule update --init
python gen_config.py
python scripts/autotranslate/releases.py

TEAMS_DIR = static/gallery
TEAMS = emeritus-maintainers maintainers docs-team triage-team survey-team web-team
Expand All @@ -43,4 +44,5 @@ html: prepare ## build the website in ./public

clean: ## remove the build artifacts, mainly the "public" directory
rm -rf public
rm -rf generated/*

33 changes: 1 addition & 32 deletions content/en/news.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,35 +319,4 @@ Here is a list of NumPy releases, with links to release notes. Bugfix
releases (only the `z` changes in the `x.y.z` version number) have no new
features; minor releases (the `y` increases) do.

- NumPy 1.25.1 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.25.1)) -- _8 Jul 2023_.
- NumPy 1.24.4 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.24.4)) -- _26 Jun 2023_.
- NumPy 1.25.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.25.0)) -- _17 Jun 2023_.
- NumPy 1.24.3 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.24.3)) -- _22 Apr 2023_.
- NumPy 1.24.2 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.24.2)) -- _5 Feb 2023_.
- NumPy 1.24.1 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.24.1)) -- _26 Dec 2022_.
- NumPy 1.24.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.24.0)) -- _18 Dec 2022_.
- NumPy 1.23.5 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.23.5)) -- _19 Nov 2022_.
- NumPy 1.23.4 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.23.4)) -- _12 Oct 2022_.
- NumPy 1.23.3 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.23.3)) -- _9 Sep 2022_.
- NumPy 1.23.2 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.23.2)) -- _14 Aug 2022_.
- NumPy 1.23.1 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.23.1)) -- _8 Jul 2022_.
- NumPy 1.23.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.23.0)) -- _22 Jun 2022_.
- NumPy 1.22.4 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.22.4)) -- _20 May 2022_.
- NumPy 1.21.6 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.21.6)) -- _12 Apr 2022_.
- NumPy 1.22.3 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.22.3)) -- _7 Mar 2022_.
- NumPy 1.22.2 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.22.2)) -- _3 Feb 2022_.
- NumPy 1.22.1 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.22.1)) -- _14 Jan 2022_.
- NumPy 1.22.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.22.0)) -- _31 Dec 2021_.
- NumPy 1.21.5 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.21.5)) -- _19 Dec 2021_.
- NumPy 1.21.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.21.0)) -- _22 Jun 2021_.
- NumPy 1.20.3 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.20.3)) -- _10 May 2021_.
- NumPy 1.20.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.20.0)) -- _30 Jan 2021_.
- NumPy 1.19.5 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.19.5)) -- _5 Jan 2021_.
- NumPy 1.19.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.19.0)) -- _20 Jun 2020_.
- NumPy 1.18.4 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.18.4)) -- _3 May 2020_.
- NumPy 1.17.5 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.17.5)) -- _1 Jan 2020_.
- NumPy 1.18.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.18.0)) -- _22 Dec 2019_.
- NumPy 1.17.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.17.0)) -- _26 Jul 2019_.
- NumPy 1.16.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.16.0)) -- _14 Jan 2019_.
- NumPy 1.15.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.15.0)) -- _23 Jul 2018_.
- NumPy 1.14.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.14.0)) -- _7 Jan 2018_.
{{< releases >}}
12 changes: 1 addition & 11 deletions content/ja/news.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,4 @@ _2019年11月15日_ -- NumPyと、NumPyの重要な依存関係の1つであるO

こちらがより過去のNumPy リリースのリストで、各リリースノートへのリンクが記載されています。 全てのバグフィックスリリース(バージョン番号`x.y.z` の`z`だけが変更されたもの)は新しい機能追加はされず、マイナーリリース (`y` が増えたもの)は、新しい機能追加されています。

- NumPy 1.18.4 ([リリースノート](https://github.com/numpy/numpy/releases/tag/v1.18.4)) -- _2020年5月3日_.
- NumPy 1.18.4 ([リリースノート](https://github.com/numpy/numpy/releases/tag/v1.18.4)) -- _2020年4月19日_.
- NumPy 1.18.2 ([リリースノート](https://github.com/numpy/numpy/releases/tag/v1.18.2)) -- _2020年3月17日_.
- NumPy 1.18.1 ([リリースノート](https://github.com/numpy/numpy/releases/tag/v1.18.1)) -- _2020年1月6日_.
- NumPy 1.17.5 ([リリースノート](https://github.com/numpy/numpy/releases/tag/v1.17.5)) -- _2020年1月1日_.
- NumPy 1.18.0 ([リリースノート](https://github.com/numpy/numpy/releases/tag/v1.18.0)) -- _2019年12月22日_.
- NumPy 1.17.4 ([リリースノート](https://github.com/numpy/numpy/releases/tag/v1.17.4)) -- _2019年10月11日_.
- NumPy 1.17.0 ([リリースノート](https://github.com/numpy/numpy/releases/tag/v1.17.0)) -- _2019年7月26日_.
- NumPy 1.16.0 ([リリースノート](https://github.com/numpy/numpy/releases/tag/v1.16.0)) -- _2019年1月14日_.
- NumPy 1.15.0 ([リリースノート](https://github.com/numpy/numpy/releases/tag/v1.15.0)) -- _2018年7月23日_.
- NumPy 1.14.0 ([リリースノート](https://github.com/numpy/numpy/releases/tag/v1.14.0)) -- _2018年1月7日_.
{{< releases >}}
12 changes: 1 addition & 11 deletions content/pt/news.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,4 @@ Mais detalhes sobre nossas propostas e resultados esperados podem ser encontrado

Aqui está uma lista de versões do NumPy, com links para notas de lançamento. Todos os lançamentos de bugfix (apenas o `z` muda no formato `x.y.z` do número da versão) não tem novos recursos; versões menores (o `y` aumenta) contém novos recursos.

- NumPy 1.18.4 ([notas de lançamento](https://github.com/numpy/numpy/releases/tag/v1.18.4)) -- _3 de maio de 2020_.
- NumPy 1.18.3 ([notas de lançamento](https://github.com/numpy/numpy/releases/tag/v1.18.3)) -- _19 de abril de 2020_.
- NumPy 1.18.2 ([notas de lançamento](https://github.com/numpy/numpy/releases/tag/v1.18.2)) -- _17 de março de 2020_.
- NumPy 1.18.1 ([notas de lançamento](https://github.com/numpy/numpy/releases/tag/v1.18.1)) -- _6 de janeiro de 2020_.
- NumPy 1.17.5 ([notas de lançamento](https://github.com/numpy/numpy/releases/tag/v1.17.5)) -- _1 de janeiro de 2020_.
- NumPy 1.18.0 ([notas de lançamento](https://github.com/numpy/numpy/releases/tag/v1.18.0)) -- _22 de dezembro de 2019_.
- NumPy 1.17.4 ([notas de lançamento](https://github.com/numpy/numpy/releases/tag/v1.17.4)) -- _11 de novembro de 2019_.
- NumPy 1.17.0 ([notas de lançamento](https://github.com/numpy/numpy/releases/tag/v1.17.0)) -- _26 de julho de 2019_.
- NumPy 1.16.0 ([notas de lançamento](https://github.com/numpy/numpy/releases/tag/v1.16.0)) -- _14 de janeiro de 2019_.
- NumPy 1.15.0 ([notas de lançamento](https://github.com/numpy/numpy/releases/tag/v1.15.0)) -- _23 de julho de 2018_.
- NumPy 1.14.0 ([notas de lançamento](https://github.com/numpy/numpy/releases/tag/v1.14.0)) -- _7 de janeiro de 2018_.
{{< releases >}}
3 changes: 3 additions & 0 deletions layouts/shortcodes/releases.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ $lang := .Page.Lang }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to use one of the existing shortcodes provided by the theme:

https://theme.scientific-python.org/shortcodes/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we could also just use the include-md short-code and in the news.md for each language, hard code the path to the releases.md for that particular language. Figuring out the language in the shortcode and generating the path dynamically might be too clever for its own good. Do you think the first option I mentioned with just include-md is better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a simpler option is to generate a JSON data file, and to then use a language-specific template to generate the release lines:

https://gohugo.io/templates/data-templates/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, cool. Thanks @stefanv, I didn't know about this stuff! It looks like I've re-implemented something Hugo is already pretty good at. Data-templates does seem like the way to go.

{{ $path := printf "generated/releases/%s/releases.md" $lang }}
{{ readFile $path | markdownify }}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PyYAML
40 changes: 40 additions & 0 deletions scripts/autotranslate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import yaml

from pathlib import Path

def get_languages():
"""Get languages that are currently active on website."""
current_dir = Path(__file__)
toplevel_dir = current_dir.parent.parent.parent
config_path = toplevel_dir / "config.yaml"
with open(config_path) as f:
data = yaml.safe_load(f)
return list(data["languages"])


def translate_file(
input_filepath: str, output_filepath: str, translation_func: callable
) -> None:
"""Apply translation function to text in a file and save to new location.

Parameters
----------
input_filepath : str
Path to file to be translated
output_filepath : str
Path where translated file will be saved.
translation_func : callable
Function from str to str which translates input.

Returns
-------
None
"""
with open(input_filepath, 'r') as input_file:
data = input_file.read()

transformed_data = translation_func(data)

with open(output_filepath, 'w') as output_file:
output_file.write(transformed_data)
47 changes: 47 additions & 0 deletions scripts/autotranslate/autotranslate_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
import yaml

from pathlib import Path

def get_languages():
"""Get languages that are currently active on website."""
current_dir = Path(__file__)
toplevel_dir = current_dir.parent.parent.parent
config_path = toplevel_dir / "config.yaml"
with open(config_path) as f:
data = yaml.safe_load(f)
return list(data["languages"])


def translate_file(
input_filepath: str, output_filepath: str, translation_func: callable
) -> None:
"""Apply translation function each line in a file and save to new location.

Parameters
----------
input_filepath : str
Path to file to be translated
output_filepath : str
Path where translated file will be saved.
translation_func : callable
Function from str to str which translates one line of input.

Returns
-------
None
"""
with open(input_filepath, 'r') as input_file:
lines = input_file.readlines()
output = []
for i, line in enumerate(lines):
line = line.strip()
if not line:
continue
try:
output.append(translation_func(line))
except ValueError as e:
print(f"Problem with input line {i+t}, {line}")
output = "\n".join(output) + "\n"
with open(output_filepath, 'w') as output_file:
output_file.write(output)
32 changes: 32 additions & 0 deletions scripts/autotranslate/data/releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
- NumPy 1.25.1 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.25.1)) -- _8 Jul 2023_.
- NumPy 1.24.4 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.24.4)) -- _26 Jun 2023_.
- NumPy 1.25.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.25.0)) -- _17 Jun 2023_.
- NumPy 1.24.3 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.24.3)) -- _22 Apr 2023_.
- NumPy 1.24.2 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.24.2)) -- _5 Feb 2023_.
- NumPy 1.24.1 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.24.1)) -- _26 Dec 2022_.
- NumPy 1.24.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.24.0)) -- _18 Dec 2022_.
- NumPy 1.23.5 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.23.5)) -- _19 Nov 2022_.
- NumPy 1.23.4 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.23.4)) -- _12 Oct 2022_.
- NumPy 1.23.3 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.23.3)) -- _9 Sep 2022_.
- NumPy 1.23.2 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.23.2)) -- _14 Aug 2022_.
- NumPy 1.23.1 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.23.1)) -- _8 Jul 2022_.
- NumPy 1.23.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.23.0)) -- _22 Jun 2022_.
- NumPy 1.22.4 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.22.4)) -- _20 May 2022_.
- NumPy 1.21.6 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.21.6)) -- _12 Apr 2022_.
- NumPy 1.22.3 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.22.3)) -- _7 Mar 2022_.
- NumPy 1.22.2 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.22.2)) -- _3 Feb 2022_.
- NumPy 1.22.1 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.22.1)) -- _14 Jan 2022_.
- NumPy 1.22.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.22.0)) -- _31 Dec 2021_.
- NumPy 1.21.5 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.21.5)) -- _19 Dec 2021_.
- NumPy 1.21.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.21.0)) -- _22 Jun 2021_.
- NumPy 1.20.3 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.20.3)) -- _10 May 2021_.
- NumPy 1.20.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.20.0)) -- _30 Jan 2021_.
- NumPy 1.19.5 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.19.5)) -- _5 Jan 2021_.
- NumPy 1.19.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.19.0)) -- _20 Jun 2020_.
- NumPy 1.18.4 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.18.4)) -- _3 May 2020_.
- NumPy 1.17.5 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.17.5)) -- _1 Jan 2020_.
- NumPy 1.18.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.18.0)) -- _22 Dec 2019_.
- NumPy 1.17.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.17.0)) -- _26 Jul 2019_.
- NumPy 1.16.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.16.0)) -- _14 Jan 2019_.
- NumPy 1.15.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.15.0)) -- _23 Jul 2018_.
- NumPy 1.14.0 ([release notes](https://github.com/numpy/numpy/releases/tag/v1.14.0)) -- _7 Jan 2018_.
107 changes: 107 additions & 0 deletions scripts/autotranslate/releases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
"""Automatic translation of list of releases.

To add a new language:

First add a function that translates an English datestring of the form "%d %b
%Y" to the corresponding string in the target language to the dictionary
``translate_date_funcs``, keyed by the associated two letter language code.

Second, add a translation for the English phrase "release notes" to the
``release_notes`` dictionary, keyed by the associated two letter language
code.

At build time, the releases.md file at

``"scripts/autotranslate/data/releases.md"``

will be translated and translations will be added to

``"generated/releases/xx/releases.md"``

for language codes xx corresponding to languages for which translations will
be published.
"""


import functools
import os
import re
import yaml

from datetime import datetime
from pathlib import Path

from autotranslate_common import get_languages, translate_file


month_names_pt = [
"janeiro", "fevereiro", "março", "abril", "maio", "junho",
"julho", "agosto", "setembro", "outubro", "novembro", "dezembro"
]


def translate_date_en_ja(date_string: str) -> str:
date_object = datetime.strptime(date_string, "%d %b %Y")
output = date_object.strftime("%Y年%m月%d日")
# Remove zero padding if needed before return
return output.replace("年0", "年").replace("月0", "月")


def translate_date_en_pt(date_string: str) -> str:
date_object = datetime.strptime(date_string, "%d %b %Y")
return (
f"{date_object.day} de {month_names_pt[date_object.month - 1]}"
f" de {date_object.year}"
)


translate_date_funcs = {
"pt": translate_date_en_pt,
"ja": translate_date_en_ja,
}


def translate_date(date_string, language_code):
return translate_date_funcs[language_code](date_string)


release_notes = {
"pt": "notas de versão",
"ja": "リリースノート",
}


def _translate_release_line(release_line: str, language_code: str) -> str:
"""Translate a single line from releases file."""
if language_code not in release_notes:
# Fall back to no translation if language is unsupported.
return release_line
pattern = (
r"- NumPy (?P<version>\d+\.\d+\.\d+) "
r"\(\[release notes\]\((?P<url>.+)\)\) "
r"-- _(?P<date>.+)_\."
)
match = re.search(pattern, release_line)
if not match:
raise ValueError(f"Invalid input for release_line, {release_line}")
version = match.group("version")
url = match.group("url")
date = match.group("date")
return (
f"- NumPy {version} ([{release_notes[language_code]}]({url})) --"
f" _{translate_date(date, language_code)}_."
)


if __name__ == "__main__":
current_dir = Path(__file__).parent
toplevel_dir = current_dir.parent.parent
releases_path = current_dir / "data" / "releases.md"
for language_code in get_languages():
destination_dir = toplevel_dir / "generated" / "releases" / language_code
os.makedirs(destination_dir, exist_ok=True)
outpath = destination_dir / "releases.md"
translate_func = functools.partial(
_translate_release_line, language_code=language_code
)
translate_file(releases_path, outpath, translate_func)