Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Generate translated version of qmk.fm/keyboards page #159

Closed
wants to merge 5 commits into from
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
14 changes: 14 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: set variables
id: variables
run: |
echo "QMK_VERSION=$(git -c 'versionsort.suffix=-' ls-remote --refs --sort='version:refname' --tags https://github.com/qmk/qmk_firmware '[0-9]*.*.*' | tail -n 1 | cut -d / -f 3)" >> $GITHUB_ENV
echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "COMMIT_DATE=$(date -d "@$(git show -s --format=%ct)" -u +'%Y-%m-%d %H:%M:%S %z')" >> $GITHUB_ENV
echo "PUBLISH_DATE=$(date -u +'%Y-%m-%d %H:%M:%S %z')" >> $GITHUB_ENV

- name: generate /keyboards pages
run: |
apk add --update --no-cache python3
pip3 install --no-cache --upgrade pip jinja2
python3 _util/generate_keyboard_page.py "$QMK_VERSION" "$SHORT_SHA" "$COMMIT_DATE" "$PUBLISH_DATE"

- name: jekyll build
run: |
gem install bundler:1.14.6
Expand Down
4,434 changes: 2,218 additions & 2,216 deletions _i18n/en/keyboards.md

Large diffs are not rendered by default.

2,243 changes: 2,243 additions & 0 deletions _i18n/es/keyboards.md

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions _util/_i18n/en/keyboards_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: "All Supported Keyboards"
layout: qmk-editable
permalink: /keyboards/
# this page is automatically generated
---
## All Supported Keyboards

This page is automatically generated from keyboards currently in QMK. Default .hex files are up-to-date with the latest version of QMK, and get pushed every build via GitHub Actions.

Want a qmk.fm page? [Create a `<keyboard>.md` file for it here](https://github.com/qmk/qmk.fm/tree/gh-pages/_pages/keyboards)! (use others as examples/templates)

Currently .hex, .bin, and .uf2 files are provided - some listed here may not be what's needed to flash the keyboard. If this is the case, [please open an issue](https://github.com/qmk/qmk.fm/issues)!

| | |
| :------------------: | :---- |
| QMK Version (commit) | {{version}} ({{commit}}) |
| Commit Date | {{commit_date}} |
| Published | {{publish_date}} |

<style>
.fa.psi-icon {
font-size: 14px;
font-family: sans-serif;
}
</style>

| QMK Folder | default firmware | qmk.fm page |
| --- | --- | --- |
{% for keyboard in keyboards -%}
| <i class='fa fa-github' aria-hidden='true'></i> [{{keyboard['pathname']}}](https://github.com/qmk/qmk_firmware/tree/master/keyboards/{{keyboard['pathname']}}) | [<i class='fa fa-download' aria-hidden='true'></i>](https://qmk.fm/compiled/{{keyboard['filename']}} "{{keyboard['pathname']}}'s latest default QMK firmware")[<span class='fa-stack fa-lg'><i class='fa fa-circle fa-stack-1x'></i><i class='fa fa-inverse fa-stack-1x psi-icon'>&Psi;</i></span>](qmk:https://qmk.fm/{{keyboard['filename']}} \"Open in QMK Toolbox\") | {% if keyboard['readme'] %} [{{keyboard['name']}}](http://qmk.fm/keyboards/{{keyboard['pathname']}}/) {% endif %}|
{% endfor -%}
33 changes: 33 additions & 0 deletions _util/_i18n/es/keyboards_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: "Todos los teclados con soporte"
layout: qmk-editable
permalink: /es/keyboards/
lang: es
# esta página se genera automáticamente
---
## Todos los teclados con soporte

Esta página se genera automáticamente de los teclados actualmente en QMK. Los archivos .hex predeterminados están actualizados con la última version de QMK, y se publica con cada compilación via Github Actions.

¿Quieres una página de QMK? [Crea un archivo `<keyboard>.md` aquí](https://github.com/qmk/qmk.fm/tree/gh-pages/_pages/keyboards)! (usa otros como ejemplos/patrones)

Actualmente se proveen archivos .hex, .bin, y .uf2 - algunos de los enumerados aquí tal vez no sean lo que se necesita para flashear el teclado. Si es así, [por favor abre una propuesta](https://github.com/qmk/qmk.fm/issues)!

| | |
| :------------------: | :---- |
| Versión de QMK (commit) | {{version}} ({{commit}}) |
| Fecha de commit | {{commit_date}} |
| Publicado | {{publish_date}} |

<style>
.fa.psi-icon {
font-size: 14px;
font-family: sans-serif;
}
</style>

| Carpeta de QMK | firmware predeterminado | página de qmk.fm |
| --- | --- | --- |
{% for keyboard in keyboards -%}
| <i class='fa fa-github' aria-hidden='true'></i> [{{keyboard['pathname']}}](https://github.com/qmk/qmk_firmware/tree/master/keyboards/{{keyboard['pathname']}}) | [<i class='fa fa-download' aria-hidden='true'></i>](https://qmk.fm/compiled/{{keyboard['filename']}} "último firmware predeterminado de QMK para {{keyboard['pathname']}}")[<span class='fa-stack fa-lg'><i class='fa fa-circle fa-stack-1x'></i><i class='fa fa-inverse fa-stack-1x psi-icon'>&Psi;</i></span>](qmk:https://qmk.fm/{{keyboard['filename']}} \"Abrir en QMK Toolbox\") | {% if keyboard['readme'] %} [{{keyboard['name']}}](http://qmk.fm/es/keyboards/{{keyboard['pathname']}}/) {% endif %}|
{% endfor -%}
110 changes: 52 additions & 58 deletions _util/generate_keyboard_page.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,62 @@
#!/usr/bin/env python3

import os

import sys
from jinja2 import Template

pagetext = """
---
title: "All Supported Keyboards"
layout: qmk-editable
permalink: /keyboards/
# this page is automatically generated
---
## All Supported Keyboards

This page is automatically generated from keyboards currently in QMK. Default .hex files are up-to-date with the latest version of QMK, and get pushed every build via Travis.

Want a qmk.fm page? [Create a `<keyboard>.md` file for it here](https://github.com/qmk/qmk.fm/tree/gh-pages/_pages/keyboards)! (use others as examples/templates)

Currently only .hex files are provided - some listed here may not be what's needed to flash the keyboard. If this is the case, [please open an issue](https://github.com/qmk/qmk.fm/issues)!

<style>
.fa.psi-icon {
font-size: 14px;
font-family: sans-serif;
}
</style>
print('Generating /keyboards...')

| QMK Folder | default firmware | qmk.fm page |
| --- | --- | --- |
{% for keyboard in keyboards -%}
| <i class='fa fa-github' aria-hidden='true'></i> [{{keyboard['pathname']}}](https://github.com/qmk/qmk_firmware/tree/master/keyboards/{{keyboard['pathname']}}) | [<i class='fa fa-download' aria-hidden='true'></i>](https://qmk.fm/{{keyboard['filename']}} "{{keyboard['pathname']}}'s latest default QMK firmware")[<span class='fa-stack fa-lg'><i class='fa fa-circle fa-stack-1x'></i><i class='fa fa-inverse fa-stack-1x psi-icon'>&Psi;</i></span>](qmk:https://qmk.fm/{{keyboard['filename']}} \"Open in QMK Toolbox\") | {% if keyboard['readme'] %} [{{keyboard['name']}}](http://qmk.fm/keyboards/{{keyboard['pathname']}}/) {% endif %}|
{% endfor -%}
"""
# Gather variables for templates
version, short_sha, commit_date, publish_date = sys.argv[1:]

with open('.keyboards', 'r') as fd:
keyboards = fd.readlines()

keyboard_entries = []
for keyboard in keyboards:
keyboard = keyboard.strip()
keyboard_name = keyboard.replace('/', '_')
format = None
readme = None

if os.path.exists('compiled/%s_default.bin' % keyboard_name):
format = 'bin'
elif os.path.exists('compiled/%s_default.hex' % keyboard_name):
format = 'hex'

if os.path.exists('_i18n/en/keyboards/%s.md' % keyboard.split('/')[0]):
readme = '_i18n/en/keyboards/%s.md' % keyboard.split('/')[0]

if format:
keyboard_entries.append({
'pathname': keyboard,
'name': keyboard_name,
'filename': 'compiled/%s_default.%s' % (keyboard_name, format),
'readme': readme,
})

# Write out the generated template
if os.path.exists('_i18n/en/keyboards.md'):
os.remove('_i18n/en/keyboards.md')

with open('_i18n/en/keyboards.md', 'w') as fd:
t = Template(pagetext)
fd.write(t.render(keyboards=keyboard_entries))
# loop through each language here
languages = [item for item in os.listdir('_util/_i18n')]

for language in languages:
keyboard_entries = []
for keyboard in keyboards:
keyboard = keyboard.strip()
keyboard_base = keyboard.split('/')[0]
keyboard_name = keyboard.replace('/', '_')
format = None
readme = None

if os.path.exists(f'compiled/{keyboard_name}_default.bin'):
format = 'bin'
elif os.path.exists(f'compiled/{keyboard_name}_default.hex'):
format = 'hex'
elif os.path.exists(f'compiled/{keyboard_name}_default.uf2'):
format = 'uf2'

if os.path.exists(f'_i18n/{language}/keyboards/{keyboard_base}.md'):
readme = f'_i18n/{language}/keyboards/{keyboard_base}.md'

if format:
keyboard_entries.append({
'pathname': keyboard,
'name': keyboard_name,
'filename': f'compiled/{keyboard_name}_default.{format}',
'readme': readme,
})

# Write out the generated template
if os.path.exists(f'_i18n/{language}/keyboards.md'):
os.remove(f'_i18n/{language}/keyboards.md')

with open(f'_util/_i18n/{language}/keyboards_template.md', 'r') as fd:
pagetext = fd.read()

with open(f'_i18n/{language}/keyboards.md', 'w') as fd:
t = Template(pagetext)
fd.write(t.render(
keyboards=keyboard_entries,
version=version,
commit=short_sha,
commit_date=commit_date,
publish_date=publish_date
))

print(f'/keyboards pages generated for the following languages: {languages}')
42 changes: 0 additions & 42 deletions _util/generate_keyboard_page.sh

This file was deleted.

23 changes: 0 additions & 23 deletions _util/keyboards_template.md

This file was deleted.

2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ The `_data/strings.yml` file also needs to have an entry for the language:
qmk_firmware: "QMK固件"

The `<<: *DEFAULT_EN` allows `zh-cn` to inherit all values from the English entry, and the keys following it override those. It's recommended to translate all entries for full coverage.

A template file must be created for the auto-generated keyboards page - `_util/i18n/en/keyboard_template.md` should be used as the base template.