diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index a7c9ae6b4f..1389184d34 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -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 diff --git a/.gitignore b/.gitignore index f744050fb6..7cbcb53e0f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +generated/ public/ resources/ config.yaml diff --git a/Makefile b/Makefile index 772a335ecf..370b5844ff 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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/* diff --git a/content/en/news.md b/content/en/news.md index 90912211ba..8a37cb473a 100644 --- a/content/en/news.md +++ b/content/en/news.md @@ -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 >}} diff --git a/content/ja/news.md b/content/ja/news.md index 8152792994..03869a4992 100644 --- a/content/ja/news.md +++ b/content/ja/news.md @@ -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 >}} diff --git a/content/pt/news.md b/content/pt/news.md index dd7a55e3c8..a422f77d3b 100644 --- a/content/pt/news.md +++ b/content/pt/news.md @@ -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 >}} diff --git a/layouts/shortcodes/releases.html b/layouts/shortcodes/releases.html new file mode 100644 index 0000000000..8b160ead07 --- /dev/null +++ b/layouts/shortcodes/releases.html @@ -0,0 +1,3 @@ +{{ $lang := .Page.Lang }} +{{ $path := printf "generated/releases/%s/releases.md" $lang }} +{{ readFile $path | markdownify }} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000..5500f007d0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +PyYAML diff --git a/scripts/autotranslate/__init__.py b/scripts/autotranslate/__init__.py new file mode 100644 index 0000000000..9ad02fe948 --- /dev/null +++ b/scripts/autotranslate/__init__.py @@ -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) diff --git a/scripts/autotranslate/autotranslate_common.py b/scripts/autotranslate/autotranslate_common.py new file mode 100644 index 0000000000..d936e582de --- /dev/null +++ b/scripts/autotranslate/autotranslate_common.py @@ -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) diff --git a/scripts/autotranslate/data/releases.md b/scripts/autotranslate/data/releases.md new file mode 100644 index 0000000000..2b3f220384 --- /dev/null +++ b/scripts/autotranslate/data/releases.md @@ -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_. diff --git a/scripts/autotranslate/releases.py b/scripts/autotranslate/releases.py new file mode 100644 index 0000000000..8d6dc04ca2 --- /dev/null +++ b/scripts/autotranslate/releases.py @@ -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\d+\.\d+\.\d+) " + r"\(\[release notes\]\((?P.+)\)\) " + r"-- _(?P.+)_\." + ) + 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)