Skip to content

Commit

Permalink
Feature/add i18n support&zh-cn Translation init. (#133)
Browse files Browse the repository at this point in the history
* Update: Add i18n support.

* Update: Fix github action.

* Fix install mdbook action.

* Update: Add zh-cn.po

* Update: Add translation tutorial to Readme.
  • Loading branch information
cryptonerdcn authored Dec 4, 2023
1 parent 92c8301 commit c965ae1
Show file tree
Hide file tree
Showing 17 changed files with 8,187 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/install-mdbook/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ runs:
- name: Install mdbook-last-changed
run: cargo install mdbook-last-changed --locked --version 0.1.4
shell: bash

- name: Install mdbook-i18n-helpers
run: cargo install mdbook-i18n-helpers --locked --version 0.1.0
shell: bash
11 changes: 10 additions & 1 deletion .github/workflows/mdbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,18 @@ jobs:
- name: Install mdbook
uses: ./.github/workflows/install-mdbook

- name: Build book
- name: Build book (English)
run: mdbook build -d book

- name: Build all translations
run: |
for po_lang in $(cat ./LANGUAGES); do
echo "::group::Building $po_lang translation"
MDBOOK_BOOK__LANGUAGE=$po_lang \
mdbook build -d book/$po_lang
echo "::endgroup::"
done
- name: Setup Pages
uses: actions/configure-pages@v3

Expand Down
1 change: 1 addition & 0 deletions LANGUAGES
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zh-cn
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ All the Markdown files **MUST** be edited in english. To work locally in english

- Open a PR with your changes.

##### Work locally (translations)

To work with translations, those are the steps to update the translated content:

- Run a local server for the language you want to edit: `./translations.sh zh-cn` for instance. If no language is provided, the script will only extract translations from english.

- Open the translation file you are interested in `po/zh-cn.po` for instance. You can also use editors like [poedit](https://poedit.net/) to help you on this task.

- When you are done, you should only have changes into the `po/xx.po` file. Commit them and open a PR.
The PR must stars with `i18n` to let the maintainers know that the PR is only changing translation.

The translation work is inspired from [Comprehensive Rust repository](https://github.com/google/comprehensive-rust/blob/main/TRANSLATIONS.md).

##### Initiate a new translation for your language

If you wish to initiate a new translation for your language without running a local server, consider the following tips:

- Execute the command `./translations.sh new xx` (replace `xx` with your language code). This method can generate the `xx.po` file of your language for you.
- To update your `xx.po` file, execute the command `./translations.sh xx` (replace `xx` with your language code), as mentioned in the previous chapter.
- If the `xx.po` file already exists (which means you are not initiating a new translation), you should not run this command.

#### Cairo programs

The current book has script that verifies the compilation of all Cairo programs in the book.
Expand Down
2 changes: 1 addition & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ src = "src"
title = "Starknet by Example"

[build]
extra-watch-dirs = ["listings"]
extra-watch-dirs = ["listings", "po"]

[preprocessor.gettext]
after = ["links"]
Expand Down
Loading

0 comments on commit c965ae1

Please sign in to comment.