Skip to content

Commit fa19e60

Browse files
authored
Add a translated, themed mkdocs configuration. (#1)
1 parent 91f47a7 commit fa19e60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2112
-29
lines changed

.github/dependabot.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
version: 2
3+
updates:
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
# Check for updates on Sunday, 8PM UTC
8+
interval: "weekly"
9+
day: "sunday"
10+
time: "20:00"
11+
12+
- package-ecosystem: "pip"
13+
directory: "/"
14+
schedule:
15+
# Check for updates on Sunday, 8PM UTC
16+
interval: "weekly"
17+
day: "sunday"
18+
time: "20:00"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Update pre-commit
2+
3+
on:
4+
schedule:
5+
- cron: "0 20 * * SUN" # Sunday @ 2000 UTC
6+
workflow_dispatch:
7+
8+
jobs:
9+
pre-commit-update:
10+
name: Update pre-commit
11+
uses: beeware/.github/.github/workflows/pre-commit-update.yml@main
12+
secrets: inherit
13+
with:
14+
pre-commit-source: pre-commit
15+
create-changenote: false

.github/workflows/translate.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Update Translations
2+
on:
3+
push:
4+
branches:
5+
main
6+
7+
# Cancel active CI runs for a PR before starting another run
8+
concurrency:
9+
group: translate-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
defaults:
13+
run:
14+
shell: bash # https://github.com/beeware/briefcase/pull/912
15+
16+
env:
17+
FORCE_COLOR: "1"
18+
19+
jobs:
20+
update-translations:
21+
name: Update Translations
22+
if: github.actor != 'brutusthebee'
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4.2.2
27+
with:
28+
fetch-depth: 1
29+
token: ${{ secrets.BRUTUS_PAT_TOKEN }}
30+
31+
- name: Set up Python
32+
uses: actions/setup-python@v5.6.0
33+
with:
34+
python-version: "3.X"
35+
cache: pip
36+
cache-dependency-path: |
37+
requirements.dev.txt
38+
requirements.docs.txt
39+
.pre-commit-config.yaml
40+
41+
- name: Update pip
42+
run: python -m pip install -U pip
43+
44+
- name: Install tox
45+
run: python -m pip install -r requirements.dev.txt
46+
47+
- name: Configure git
48+
run: |
49+
git config --local user.email "$(git log --pretty='%ae' -1)"
50+
git config --local user.name "brutusthebee[bot]"
51+
52+
- name: Regenerate PO files
53+
run: |
54+
tox -e docs-translate
55+
56+
- name: Update Needed?
57+
id: updated
58+
run: |
59+
if [[ $(git status --porcelain) ]]; then
60+
echo "updated=true" >> ${GITHUB_OUTPUT}
61+
else
62+
echo "updated=false" >> ${GITHUB_OUTPUT}
63+
fi
64+
65+
- name: Commit updated translations
66+
if: steps.updated.outputs.updated == 'true'
67+
env:
68+
GITHUB_TOKEN: ${{ github.token }}
69+
run: |
70+
# Commit the updated PO files.
71+
git add docs/locales
72+
git commit -m "Update translations to $(git rev-parse --short HEAD)."
73+
git push origin

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# MkDocs
2+
_build
3+
14
# Byte-compiled / optimized / DLL files
25
__pycache__/
36
*.py[codz]
@@ -182,9 +185,9 @@ cython_debug/
182185
.abstra/
183186

184187
# Visual Studio Code
185-
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
188+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186189
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187-
# and can be added to the global gitignore or merged into this file. However, if you prefer,
190+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
188191
# you could uncomment the following to ignore the entire vscode folder
189192
# .vscode/
190193

.pyspelling.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ matrix:
1414
- markdown.extensions.attr_list
1515
- pymdownx.superfences
1616
- pymdownx.blocks.admonition
17-
- pymdownx.caret
1817
- pymdownx.blocks.caption
1918
- pymdownx.blocks.tab
2019
- pyspelling.filters.html:

README.md

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,65 @@
1-
# beeware-docs-tools
2-
Tools for building BeeWare's documentation with a common theme and translations
1+
# BeeWare Docs Tools
2+
3+
Tools for building BeeWare's documentation with a common theme and translations.
4+
5+
## Adding a new language
6+
7+
Weblate is able to generate a new language, however, adding a new language
8+
also requires a few changes to the documentation repository.
9+
10+
Once a new language is generated, you'll need to add a new
11+
`mkdocs.<language-code>.yml` file and update the `tox.ini` file.
12+
13+
The following example outlines how you would go about adding German to
14+
this repo. The concepts are the same for any language in any of the docs
15+
repos.
16+
17+
### The new MkDocs configuration file
18+
19+
The first thing to do is create a new file named `mkdocs.de.yml` in the
20+
`docs` directory, with the following content:
21+
22+
```yaml
23+
INHERIT: config.yml
24+
site_name: BeeWare Demo zu Docs Tools
25+
site_url: https://tutorial.beeware.org/de
26+
docs_dir: de
27+
28+
theme:
29+
language: de
30+
31+
extra:
32+
translation_type: machine
33+
```
34+
35+
Here's what is going on in this file:
36+
37+
* This file inherits the configuration content from `config.yml`.
38+
* The `site_name` value is translated.
39+
* The `site_url` value is the project site URL, followed by the language
40+
code.
41+
* The `docs_dir` should be the language code.
42+
* The `theme: language:` value should be the language code, as specified by the
43+
MkDocs Material theme. The list can be found
44+
[here](https://squidfunk.github.io/mkdocs-material/setup/changing-the-language/).
45+
For most languages, this will be the same as the `docs_dir` language code; but
46+
for some (in particular languages with locale variants like `zh_CN`), there are
47+
differences.
48+
* The `extra: translation_type:` should be `machine` until the translation reaches
49+
100% for the first time, at which point it should be `human`. It will revert to
50+
`machine` from `human` if it regresses to below 90%.
51+
52+
### The update to `tox.ini`
53+
54+
You'll need to make several changes to this file.
55+
56+
You'll need to add the following:
57+
58+
* The language code environment flag to the header line which begins `[testenv:docs`,
59+
preceded by a `-`, with no spaces included.
60+
* The language code exclusion to the first command, which begins with `!lint`,
61+
preceded by `-!`, with no spaces included.
62+
* The language code to the end of the second line beginning with `translate :`.
63+
* The language code to the end of the line beginning with `all :`.
64+
* A new line at the end that matches the other language-specific lines with the
65+
new language code.

docs/config.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ theme:
2626
name: material
2727
language: en
2828
logo: assets/images/brutus-256.png
29+
favicon: assets/images/brutus-256.png
2930
features:
3031
- content.tabs.link
3132
- toc.follow
@@ -34,7 +35,7 @@ theme:
3435
- search.suggest
3536
- search.highlight
3637
- search.share
37-
# custom_dir: overrides
38+
custom_dir: overrides
3839
palette:
3940
# Palette toggle for automatic mode
4041
- media: "(prefers-color-scheme)"
@@ -57,11 +58,9 @@ theme:
5758
name: Switch to system preference
5859

5960
markdown_extensions:
60-
pymdownx.highlight:
61-
anchor_linenums: true
61+
pymdownx.highlight: {}
6262
pymdownx.superfences: {}
6363
pymdownx.blocks.admonition: {}
64-
pymdownx.caret: {}
6564
pymdownx.blocks.caption: {}
6665
pymdownx.blocks.tab:
6766
alternate_style: true

docs/en/SUMMARY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- BeeWare Docs Tools Demo Section One
2+
- [BeeWare Docs Tools Demo Section One](section_one/index.md)
3+
- [Section One - Page Two](section_one/page_two.md)
4+
- [Section Two](section_two/index.md)

docs/en/index.md

Lines changed: 157 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,157 @@
1-
# BeeWare Test Page
1+
# BeeWare Docs Tools Demo
2+
3+
## Theme checklist
4+
5+
Things to manually check:
6+
7+
### Titlebar
8+
9+
A medium-gray titlebar is on the page. This the theme template
10+
has been applied.
11+
12+
### Header and logo icons
13+
14+
The header icon top-left has been rendered. This confirms the template
15+
can reference external resources.
16+
17+
The logo icon in the left sidebar has been rendered. This confirms the
18+
sidebar will render properly on the target sites.
19+
20+
### Heading font
21+
22+
Headings are rendered in Cutive. This confirms the BeeWare custom CSS
23+
theme has been applied.
24+
25+
### Inline Code
26+
27+
Inline code is rendered in the same color as the surrounding font. This
28+
confirms that the theme has not caused any undesired changes.
29+
30+
This is text with `inline code` here and `inline code` here.
31+
32+
### Tabbed Content Code
33+
34+
Code is in a contrasting color to the background. Copy button should
35+
copy only the commands; the prompt should not be included.
36+
37+
This confirms that the theme has not caused any undesired changes,
38+
as well as whether the copy button is working as expected.
39+
40+
/// tab | macOS
41+
42+
``` console
43+
$ git clone https://github.com/beeware/beeware-theme.git
44+
```
45+
46+
///
47+
48+
/// tab | Linux
49+
50+
``` console
51+
$ git clone https://github.com/beeware/beeware-theme.git
52+
```
53+
54+
///
55+
56+
/// tab | Windows
57+
58+
``` doscon
59+
C:\...>git clone https://github.com/beeware/beeware-theme.git
60+
```
61+
62+
///
63+
64+
### Code copy button behavior
65+
66+
The copy button on the following codeblock should result in `from pathlib
67+
import Path` being copied to the clipboard.
68+
69+
```python
70+
from pathlib import Path
71+
```
72+
73+
The copy button on the following codeblock should result in `ls
74+
beeware-docs-tools` being copied to the clipboard. The shell prompt and
75+
the output should not be included.
76+
77+
```console
78+
(venv) $ ls beeware-docs-tools
79+
_build locales requirements.dev.txt tox.ini
80+
docs pyproject.toml requirements.docs.txt
81+
LICENSE README.md src
82+
```
83+
84+
### Sidebar links
85+
86+
Sidebar links exist, and point to the `beeware-docs-tools` repo. This
87+
confirms that the sidebar content has been loaded, and the `project-name`
88+
has been set in the MkDocs configuration file.
89+
90+
### Link colors
91+
92+
This link to [the main BeeWare website](https://beeware.org) should be blue
93+
in *both* light mode and dark mode.
94+
95+
The links in the left and right sidebars should also be blue in both modes.
96+
97+
When scrolling down the page, the active header link in the right sidebar
98+
should be light blue in dark mode, and darker blue in light mode.
99+
100+
### Translation Admonition
101+
102+
The English-language version of this document should show the "Translations
103+
are available" admonition below. The French translation should show the "This is
104+
a machine translation!" admonition. The German translation should show the
105+
"This is a translation!" admonition for human translations.
106+
107+
{% if config.extra.translation_type == "original" %}
108+
109+
/// admonition | Translations are available
110+
111+
If you're not comfortable with English, translations of the Docs Tools
112+
are available in Français and Deutsch.
113+
114+
///
115+
116+
{% endif %}
117+
118+
{% if config.extra.translation_type == "machine" %}
119+
120+
/// admonition | This is a machine translation!
121+
122+
This version of the tutorial has been generated by machine translation.
123+
We know this isn't ideal, but we felt that a bad translation was better
124+
than no translation at all.
125+
126+
///
127+
128+
{% endif %}
129+
130+
{% if config.extra.translation_type == "human" %}
131+
132+
/// admonition | This is a translation!
133+
134+
This document is a translation of the English version. The translation
135+
has been reviewed by humans, but newer sections may be generated by
136+
machine translation, or not translated at all.
137+
138+
///
139+
140+
{% endif %}
141+
142+
### Custom 404 page
143+
144+
Add `nopage` to the end of the URL in your browser to verify the 404
145+
page contains two flying bees, and the text "Brutus can't find what
146+
you're looking for" below.
147+
148+
*MkDocs builds fail with unrecognized internal links, so you need to
149+
manually verify this check by modifying the URL in your browser.*
150+
151+
### Next Checks
152+
153+
The following link should take you to BeeWare Docs Tools Demo Section
154+
One. It is included to verify cross-page linking.
155+
156+
Navigate to [BeeWare Docs Tools Demo Section One](section_one/index.md) for the
157+
next checks.

0 commit comments

Comments
 (0)