2023-12-28 00:31:05 +08:00
|
|
|
#!/usr/bin/env python3
|
2023-09-14 02:14:06 +08:00
|
|
|
# This code is a Qiskit project.
|
|
|
|
#
|
|
|
|
# (C) Copyright IBM 2023.
|
|
|
|
#
|
|
|
|
# This code is licensed under the Apache License, Version 2.0. You may
|
|
|
|
# obtain a copy of this license in the LICENSE file in the root directory
|
|
|
|
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
|
|
|
|
#
|
|
|
|
# Any modifications or derivative works of this code must retain this
|
|
|
|
# copyright notice, and modified files need to carry a notice indicating
|
|
|
|
# that they have been altered from the originals.
|
|
|
|
|
2023-12-28 00:31:05 +08:00
|
|
|
import subprocess
|
2024-03-02 03:02:05 +08:00
|
|
|
import sys
|
2023-12-28 00:31:05 +08:00
|
|
|
from pathlib import Path
|
Add Crowdin to set up translations (#541)
Part of https://github.com/Qiskit/documentation/issues/476.
This PR sets up two GitHub actions for interfacing with Crowdin.com, the
website the translation team uses for translations.
1. Upload English sources. We do this on any change to `docs/` (except
API docs), which the translation team so that they can start making
updates sooner. For example:
<img width="346" alt="Screenshot 2023-12-20 at 5 45 05 PM"
src="https://github.com/Qiskit/documentation/assets/14852634/0ed4cbed-45db-45bb-9150-5d90bec7a0f6">
2. Download the translations. This happens once a week, which the
translations team requested. It will open up a pull request like
https://github.com/Eric-Arellano/documentation/pull/10.
## How auth works
We only need to set GitHub Secrets for CROWDIN_PROJECT_ID and
CROWDIN_PERSONAL_TOKEN. GitHub will automatically set GITHUB_TOKEN using
[this
mechanism](https://docs.github.com/en/actions/security-guides/automatic-token-authentication).
## Translations saved at `translations/` folder
This adds a top-level `translations/` folder, rather than nesting the
translations inside the `docs/` folder. For example:
<img width="367" alt="Screenshot 2023-12-20 at 5 48 09 PM"
src="https://github.com/Qiskit/documentation/assets/14852634/42e27fd4-5c67-4ceb-aae3-8f25315f7aae">
This top-level folder is useful because it reduces noise in the `docs/`
folder. It makes it more obvious to the team what is the original source
docs vs. what is translations and should not be modified directly in
this repository.
### How this works with the app
To get docs previews working in this repo, we teach the Docker image to
mount `translations/` as if its contents were in the folder `docs/`,
since the application expects all content to live there.
When we sync the translations from open-source to closed-source for
production, we will copy the contents of `translations/` so that it
actually lives underneath `docs/`. For example,
`translations/es/support.mdx` becomes `docs/es/support.mdx`.
## Locales
As explained in https://github.com/Qiskit/documentation/issues/7, we
generally want to use the two-letter code for languages, like `es` and
`fr`. The only exception is Chinese, where we need to distinguish
between Traditional and Simplified.
This config works with that, so long as in Crowdin.com, the project sets
up this Language Mapping under the Languages settings:
<img width="475" alt="Screenshot 2023-12-20 at 5 59 19 PM"
src="https://github.com/Qiskit/documentation/assets/14852634/adf643d1-716a-435c-9e32-9762c6570956">
## Doesn't yet add `_languages.json`
As explained in https://github.com/Qiskit/documentation/issues/7, we
will probably want a file like `_languages.json` that teaches the docs
app what each language is, such as its name to show in the language
toggle. That schema still needs to be finalized and it can be added in a
follow up.
2023-12-29 23:45:56 +08:00
|
|
|
from typing import Iterator
|
2023-12-28 00:31:05 +08:00
|
|
|
|
|
|
|
PWD = Path(__file__).parent
|
|
|
|
|
|
|
|
|
Add Crowdin to set up translations (#541)
Part of https://github.com/Qiskit/documentation/issues/476.
This PR sets up two GitHub actions for interfacing with Crowdin.com, the
website the translation team uses for translations.
1. Upload English sources. We do this on any change to `docs/` (except
API docs), which the translation team so that they can start making
updates sooner. For example:
<img width="346" alt="Screenshot 2023-12-20 at 5 45 05 PM"
src="https://github.com/Qiskit/documentation/assets/14852634/0ed4cbed-45db-45bb-9150-5d90bec7a0f6">
2. Download the translations. This happens once a week, which the
translations team requested. It will open up a pull request like
https://github.com/Eric-Arellano/documentation/pull/10.
## How auth works
We only need to set GitHub Secrets for CROWDIN_PROJECT_ID and
CROWDIN_PERSONAL_TOKEN. GitHub will automatically set GITHUB_TOKEN using
[this
mechanism](https://docs.github.com/en/actions/security-guides/automatic-token-authentication).
## Translations saved at `translations/` folder
This adds a top-level `translations/` folder, rather than nesting the
translations inside the `docs/` folder. For example:
<img width="367" alt="Screenshot 2023-12-20 at 5 48 09 PM"
src="https://github.com/Qiskit/documentation/assets/14852634/42e27fd4-5c67-4ceb-aae3-8f25315f7aae">
This top-level folder is useful because it reduces noise in the `docs/`
folder. It makes it more obvious to the team what is the original source
docs vs. what is translations and should not be modified directly in
this repository.
### How this works with the app
To get docs previews working in this repo, we teach the Docker image to
mount `translations/` as if its contents were in the folder `docs/`,
since the application expects all content to live there.
When we sync the translations from open-source to closed-source for
production, we will copy the contents of `translations/` so that it
actually lives underneath `docs/`. For example,
`translations/es/support.mdx` becomes `docs/es/support.mdx`.
## Locales
As explained in https://github.com/Qiskit/documentation/issues/7, we
generally want to use the two-letter code for languages, like `es` and
`fr`. The only exception is Chinese, where we need to distinguish
between Traditional and Simplified.
This config works with that, so long as in Crowdin.com, the project sets
up this Language Mapping under the Languages settings:
<img width="475" alt="Screenshot 2023-12-20 at 5 59 19 PM"
src="https://github.com/Qiskit/documentation/assets/14852634/adf643d1-716a-435c-9e32-9762c6570956">
## Doesn't yet add `_languages.json`
As explained in https://github.com/Qiskit/documentation/issues/7, we
will probably want a file like `_languages.json` that teaches the docs
app what each language is, such as its name to show in the language
toggle. That schema still needs to be finalized and it can be added in a
follow up.
2023-12-29 23:45:56 +08:00
|
|
|
def translation_volume_mounts() -> Iterator[str]:
|
|
|
|
"""Return the CLI args to mount each language in the translations/ folder.
|
|
|
|
|
|
|
|
Unlike the root `Dockerfile`, we cannot use `-v $PWD/translations:/home/node/app/docs` because
|
|
|
|
Docker complains that the volume is already mounted when we mount the `/docs` folder. So, instead
|
|
|
|
we need to be more specific to mount each language's folder.
|
|
|
|
"""
|
|
|
|
for folder in PWD.glob("translations/*"):
|
|
|
|
yield from ["-v", f"{folder}:/home/node/app/docs/{folder.name}"]
|
|
|
|
|
|
|
|
|
2023-12-28 00:31:05 +08:00
|
|
|
def main() -> None:
|
2024-03-02 03:02:05 +08:00
|
|
|
print(
|
|
|
|
"Warning: this may be using an outdated version of the app. Run "
|
|
|
|
+ "`docker pull qiskit/documentation` to check for updates.",
|
|
|
|
file=sys.stderr,
|
|
|
|
)
|
2023-12-28 00:31:05 +08:00
|
|
|
subprocess.run(
|
|
|
|
# Keep this aligned with the Dockerfile at the root of the repository.
|
|
|
|
[
|
|
|
|
"docker",
|
|
|
|
"run",
|
|
|
|
"-v",
|
|
|
|
f"{PWD}/docs:/home/node/app/docs",
|
Add Crowdin to set up translations (#541)
Part of https://github.com/Qiskit/documentation/issues/476.
This PR sets up two GitHub actions for interfacing with Crowdin.com, the
website the translation team uses for translations.
1. Upload English sources. We do this on any change to `docs/` (except
API docs), which the translation team so that they can start making
updates sooner. For example:
<img width="346" alt="Screenshot 2023-12-20 at 5 45 05 PM"
src="https://github.com/Qiskit/documentation/assets/14852634/0ed4cbed-45db-45bb-9150-5d90bec7a0f6">
2. Download the translations. This happens once a week, which the
translations team requested. It will open up a pull request like
https://github.com/Eric-Arellano/documentation/pull/10.
## How auth works
We only need to set GitHub Secrets for CROWDIN_PROJECT_ID and
CROWDIN_PERSONAL_TOKEN. GitHub will automatically set GITHUB_TOKEN using
[this
mechanism](https://docs.github.com/en/actions/security-guides/automatic-token-authentication).
## Translations saved at `translations/` folder
This adds a top-level `translations/` folder, rather than nesting the
translations inside the `docs/` folder. For example:
<img width="367" alt="Screenshot 2023-12-20 at 5 48 09 PM"
src="https://github.com/Qiskit/documentation/assets/14852634/42e27fd4-5c67-4ceb-aae3-8f25315f7aae">
This top-level folder is useful because it reduces noise in the `docs/`
folder. It makes it more obvious to the team what is the original source
docs vs. what is translations and should not be modified directly in
this repository.
### How this works with the app
To get docs previews working in this repo, we teach the Docker image to
mount `translations/` as if its contents were in the folder `docs/`,
since the application expects all content to live there.
When we sync the translations from open-source to closed-source for
production, we will copy the contents of `translations/` so that it
actually lives underneath `docs/`. For example,
`translations/es/support.mdx` becomes `docs/es/support.mdx`.
## Locales
As explained in https://github.com/Qiskit/documentation/issues/7, we
generally want to use the two-letter code for languages, like `es` and
`fr`. The only exception is Chinese, where we need to distinguish
between Traditional and Simplified.
This config works with that, so long as in Crowdin.com, the project sets
up this Language Mapping under the Languages settings:
<img width="475" alt="Screenshot 2023-12-20 at 5 59 19 PM"
src="https://github.com/Qiskit/documentation/assets/14852634/adf643d1-716a-435c-9e32-9762c6570956">
## Doesn't yet add `_languages.json`
As explained in https://github.com/Qiskit/documentation/issues/7, we
will probably want a file like `_languages.json` that teaches the docs
app what each language is, such as its name to show in the language
toggle. That schema still needs to be finalized and it can be added in a
follow up.
2023-12-29 23:45:56 +08:00
|
|
|
*translation_volume_mounts(),
|
2023-12-28 00:31:05 +08:00
|
|
|
"-v",
|
2024-01-18 01:13:37 +08:00
|
|
|
f"{PWD}/public:/home/node/app/packages/preview/public",
|
2023-12-28 00:31:05 +08:00
|
|
|
"-p",
|
|
|
|
"3000:3000",
|
|
|
|
"-p",
|
|
|
|
"5001:5001",
|
|
|
|
"qiskit/documentation",
|
|
|
|
],
|
|
|
|
check=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
try:
|
|
|
|
main()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|