Skip to content

Refactor repository structure to include translations #352

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

Merged
merged 29 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3aec55d
Begin of refactoring for translations
simonsan Apr 5, 2023
57e2316
Begin of refactoring for translations
simonsan Apr 5, 2023
a9ef011
Add third_party directory
simonsan Apr 5, 2023
eb062d4
Fold menu items on lvl 1
simonsan Apr 5, 2023
849e856
Remove hardcoded non-existing translations
simonsan Apr 5, 2023
fcef1ff
Add shell attribute for GH action
simonsan Apr 5, 2023
b9c2b8d
Add comment for translations How to
simonsan Apr 5, 2023
3360a69
Add caching for Rust builds (mdbook)
simonsan Apr 5, 2023
c711aa9
Fix missing version flag
simonsan Apr 5, 2023
39e645c
Fix C&P leftover
simonsan Apr 5, 2023
6bdf8d6
Add links to patterns repository
simonsan Apr 5, 2023
8b91a39
Introduce dprint for fomratting code blocks within markdown
simonsan Apr 6, 2023
9d1877f
Add dprint for markdown linting
simonsan Apr 6, 2023
450ac8a
Add book.js to additional js in book.toml
simonsan Apr 7, 2023
e933c6a
Remove `de` mock translation
simonsan Apr 7, 2023
87ab40f
Updating messages.pot
simonsan Apr 7, 2023
a27e9e4
Format translations.md
simonsan Apr 7, 2023
169f874
Remove gh-pages workflow
simonsan Apr 7, 2023
0276614
Update publish action
simonsan Apr 7, 2023
d16d6eb
Comment out builds for different languages
simonsan Apr 7, 2023
7b7c139
Update publishing action
simonsan Apr 7, 2023
972464d
Update GH actions file
simonsan Apr 7, 2023
23bfb33
Add comment on language
simonsan Apr 7, 2023
9b8cc69
Rename action
simonsan Apr 7, 2023
f0cc616
Update .github/workflows/setup-rust-cache/action.yml
simonsan Apr 7, 2023
8143a55
Remove code sub-blocks in codeblocks to avoid 4 backticks problem
simonsan Apr 7, 2023
39ce9fb
Update messages.pot
simonsan Apr 7, 2023
29df0e4
Revert "Remove code sub-blocks in codeblocks to avoid 4 backticks pro…
simonsan Apr 7, 2023
82b14e7
Update message.pot, Fix line endings
simonsan Apr 7, 2023
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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
MDBOOK_VERSION=0.4.28
MDBOOK_I8N_HELPERS_VERSION=0.1.0
119 changes: 119 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: Test mdbook chapters

on:
pull_request:
push:
branches:
- main

env:
CARGO_TERM_COLOR: always

jobs:
mdbook-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Rust cache
uses: ./.github/workflows/setup-rust-cache

- name: Install mdbook
uses: ./.github/workflows/install-mdbook

- name: Test code snippets
run: mdbook test

# TODO: Activate when first translation is available
# i18n-helpers:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v3

# - name: Install Gettext
# run: sudo apt install gettext

# - name: Setup Rust cache
# uses: ./.github/workflows/setup-rust-cache

# - name: Install mdbook
# uses: ./.github/workflows/install-mdbook

# - name: Generate po/messages.pot
# run: mdbook build -d po
# env:
# MDBOOK_OUTPUT: '{"xgettext": {"pot-file": "messages.pot"}}'

# - name: Test messages.pot
# run: msgfmt --statistics -o /dev/null po/messages.pot

# - name: Expand includes without translation
# run: mdbook build -d expanded
# env:
# MDBOOK_OUTPUT: '{"markdown": {}}'

# - name: Expand includes with no-op translation
# run: mdbook build -d no-op
# env:
# MDBOOK_OUTPUT: '{"markdown": {}}'
# MDBOOK_PREPROCESSOR__GETTEXT__PO_FILE: po/messages.pot

# - name: Compare no translation to no-op translation
# run: diff --color=always --unified --recursive expanded no-op

# find-translations:
# runs-on: ubuntu-latest
# outputs:
# languages: ${{ steps.find-translations.outputs.languages }}
# steps:
# - name: Checkout
# uses: actions/checkout@v3

# - name: Find translations
# id: find-translations
# shell: python
# run: |
# import os, json, pathlib
# languages = [p.stem for p in pathlib.Path("po").iterdir() if p.suffix == ".po"]
# github_output = open(os.environ["GITHUB_OUTPUT"], "a")
# github_output.write("languages=")
# json.dump(sorted(languages), github_output)

# translations:
# runs-on: ubuntu-latest
# needs:
# - find-translations
# strategy:
# matrix:
# language: ${{ fromJSON(needs.find-translations.outputs.languages) }}
# env:
# MDBOOK_BOOK__LANGUAGE: ${{ matrix.language }}
# steps:
# - name: Checkout
# uses: actions/checkout@v3

# - name: Install Gettext
# run: sudo apt install gettext

# - name: Setup Rust cache
# uses: ./.github/workflows/setup-rust-cache

# - name: Install mdbook
# uses: ./.github/workflows/install-mdbook

# - name: Test ${{ matrix.language }} translation
# run: msgfmt --statistics -o /dev/null po/${{ matrix.language }}.po

# - name: Build book with ${{ matrix.language }} translation
# run: mdbook build

# - name: Upload ${{ matrix.language }} translation
# uses: actions/upload-artifact@v3
# with:
# name: rust-design-patterns-${{ matrix.language }}
# path: book/

# - name: Test code snippets with ${{ matrix.language }} translation
# run: mdbook test
53 changes: 0 additions & 53 deletions .github/workflows/ci.yml

This file was deleted.

31 changes: 0 additions & 31 deletions .github/workflows/gh-pages.yml

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/install-mdbook/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Install mdbook and dependencies

description: Install the mdbook with the dependencies we need.

runs:
using: composite
steps:
- name: Read mdbook version from .env
id: mdbook-version
run: |
. ./.env
echo "::set-output name=MDBOOK_VERSION::${MDBOOK_VERSION}"
shell: bash

- name: Read mdbook-i8n-helpers version from .env
id: mdbook-i8n-helpers-version
run: |
. ./.env
echo "::set-output name=MDBOOK_I8N_HELPERS_VERSION::${MDBOOK_I8N_HELPERS_VERSION}"
shell: bash

# The --locked flag is important for reproducible builds.
- name: Install mdbook
run: cargo install mdbook --locked --version '${{ steps.mdbook-version.outputs.MDBOOK_VERSION }}'
shell: bash

- name: Install i18n-helpers
run: cargo install mdbook-i18n-helpers --locked --version '${{ steps.mdbook-i8n-helpers-version.outputs.MDBOOK_I8N_HELPERS_VERSION }}'
shell: bash
14 changes: 14 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Lint Markdown

on:
push:
branches: [main]
pull_request:

jobs:
style:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: dprint/[email protected]
67 changes: 67 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Deploy mdBook sites to GH Pages

on:
push:
branches: ["main"]
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always
# TODO: Update the language picker in index.hbs to link new languages.
# TODO: As long as https://github.com/google/mdbook-i18n-helpers/issues/12 is not implemented, yet.
# TODO: Activate when first translation is available
# These are the languages in addition to 'en', which is the main language
# LANGUAGES: xx

jobs:
publish:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Rust cache
uses: ./.github/workflows/setup-rust-cache

- name: Install mdbook
uses: ./.github/workflows/install-mdbook

- name: Build course in English
run: mdbook build -d book

# TODO: Activate when first translation is available
# - name: Build all translations
# run: |
# for po_lang in ${{ env.LANGUAGES }}; do
# echo "::group::Building $po_lang translation"
# MDBOOK_BOOK__LANGUAGE=$po_lang \
# MDBOOK_OUTPUT__HTML__SITE_URL=/patterns/$po_lang/ \
# mdbook build -d book/$po_lang
# echo "::endgroup::"
# done

- name: Setup Pages
id: pages
uses: actions/configure-pages@v3

- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: ./book

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
11 changes: 11 additions & 0 deletions .github/workflows/setup-rust-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Setup Rust cache

description: Configure the rust-cache workflow.

runs:
using: composite
steps:
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: v1
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ idioms and other explanations. It is a compilation of collective (sometimes
implicit) knowledge as well as experiences that have emerged through
collaborative work.

The patterns described here are __not rules__, but should be taken as
The patterns described here are **not rules**, but should be taken as
guidelines for writing idiomatic code in Rust. We are collecting Rust patterns
in this book so people can learn the tradeoffs between Rust idioms and use them
properly in their own code.
Expand Down
16 changes: 15 additions & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,33 @@ authors = ["the rust-unofficial authors"]
description = "A catalogue of Rust design patterns, anti-patterns and idioms"
language = "en"
multilingual = false
src = "."
src = "src"

[build]
create-missing = false
extra-watch-dirs = ["po", "third_party"]

[preprocessor.gettext]
after = ["links"]

[rust]
edition = "2018"

[output.html]
curly-quotes = true
default-theme = "rust"
site-url = "/patterns/"
git-repository-url = "https://github.com/rust-unofficial/patterns"
git-repository-icon = "fa-github"
edit-url-template = "https://github.com/rust-unofficial/patterns/edit/main/{path}"
additional-css = ["./language-picker.css"]
additional-js = ["./third_party/mdbook/book.js"]

[output.html.fold]
enable = true
level = 1

[output.html.playground]
editable = false

# [output.linkcheck] # enable the "mdbook-linkcheck" renderer, disabled due to gh-actions
11 changes: 11 additions & 0 deletions dprint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"lineWidth": 80,
"markdown": {},
"includes": [
"**/*.{md}"
],
"excludes": [],
"plugins": [
"https://plugins.dprint.dev/markdown-0.15.2.wasm"
]
}
8 changes: 8 additions & 0 deletions language-picker.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#language-list {
left: auto;
right: 10px;
}

#language-list a {
color: inherit;
}
Loading