Skip to content
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

Add docs.py script to support localization build (static and live) #313

Merged
merged 30 commits into from
Feb 28, 2024

Conversation

fflorent
Copy link
Collaborator

@fflorent fflorent commented Feb 21, 2024

This PR takes the docs.py script from FastAPI and adapt it to make it work here.

Also just like the previous PR, you may merge it if you approve, it is meant to have no consequence on the resulting website.

Here is what docs.py offers:

$ ./docs.py --help
Usage: docs.py [OPTIONS] COMMAND [ARGS]...

Options:
  --install-completion [bash|zsh|fish|powershell|pwsh]
                                  Install completion for the specified shell.
  --show-completion [bash|zsh|fish|powershell|pwsh]
                                  Show completion for the specified shell, to
                                  copy it or customize the installation.

  --help                          Show this message and exit.

Commands:
  build-all         Build mkdocs site for en, and then build each language...
  build-lang        Build the docs for a language.
  langs-json
  live              Serve with livereload a docs site for a specific...
  new-lang          Generate a new docs translation directory for the...
  serve             A quick server to preview a built site with...
  update-languages  Update the mkdocs.yml file Languages section including...
  verify-config     Verify main mkdocs.yml content to make sure it uses the...

Untranslated page fallback to the English version, with a warning asking for help to translate the content. Also images / screenshots can be localized too! They just have to be put in the ./help/{language}/docs/images folder. If they are missing, the image from ./help/en/docs/images is used. All of this thanks to the mkdocs hooks!

How it looks like

A page with untranslated content looks like this:

screenshot of the untranslated doc page

The language selector

Also implemented the selectbox that switches the language (to make it work, run: ./docs.py build-all and then ./docs.py serve):

recording.mp4

TODO

Old todo list:

  •  Use ./docs.py in build-doc.sh
  • Moar testing (new_lang, build_lang, ...)
  • Rework git commit messages (the first commit is meant to add docs.py without any change)
  • Add missing-translation.md and offer a link to the documentation in English
  • Credit Sebastian Ramirez in README
  • Update README instructions
  • Add assets missing in target language

Copy link

netlify bot commented Feb 21, 2024

Deploy Preview for grist-help-preview ready!

Name Link
🔨 Latest commit 4d7814a
🔍 Latest deploy log https://app.netlify.com/sites/grist-help-preview/deploys/65df55022a95ad00074aeed2
😎 Deploy Preview https://deploy-preview-313--grist-help-preview.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

mkdocs.yml Outdated Show resolved Hide resolved
mkdocs.yml Outdated Show resolved Hide resolved
requirements.txt Show resolved Hide resolved
@fflorent fflorent mentioned this pull request Feb 22, 2024
16 tasks
@fflorent fflorent marked this pull request as ready for review February 23, 2024 17:30
return files


def generate_renamed_section_items(
Copy link
Collaborator Author

@fflorent fflorent Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read again my code after the weekend and found that I missed that part.

This part is meant to localize the section titles and the pages.

Whereas Fastapi handles localizing the sections by having an index.md file per section (for example tutorial in en and in fr), grist-help doesn't. Also it works for the files in FastAPI because they are only described only with their names at the contrary of what is done in grist-help.

I am removing this function and the hook (at least for now), and will try to find a way to translate the sections later.

We'll find a way to translate sections later
@@ -4,7 +4,7 @@ If you are keeping records of who is charged what in Grist, it can be convenient
to generate invoices right there and then beside those records. This tutorial
shows you how to set up a document like this:

![Invoice](/examples/images/2020-08-invoices/final-invoice.png)
![Invoice](../examples/images/2020-08-invoices/final-invoice.png)
Copy link

@CamilleLegeron CamilleLegeron Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are inside /examples folder, why not write ./images/2020-08-invoices/final-invoice.png

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To have same shape with newsletters folder ? Do you know why there is images in examples folder and directly in en/docs

Copy link
Collaborator Author

@fflorent fflorent Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is that it's specific to examples. That being said, probably these images could be moved to ./help/en/docs/images/examples/.

Grist Labs: what do you think of that?

Copy link
Collaborator Author

@fflorent fflorent Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made two distinct successive commits:

  • 85a3874 in which I simply change fix the relative links;
  • c17431e in which I moved the example images in help/docs/en/images/examples

Therefore if the latest one is not what we would want, we may revert it.

@paulfitz paulfitz self-requested a review February 28, 2024 14:39
@fflorent
Copy link
Collaborator Author

I just fixed two little things after having made an internal demo:

  • ✅ The background color of the language selector;
  • ✅ Made possible to translate the warning info box when a page is not translated yet;

screenshot of the language selector background in dark and the translated warning info box in French

Copy link
Member

@paulfitz paulfitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, everything is working for me in testing. Some comments.

In order to build the website with all the languages, run:
```sh
source ./env/bin/activate
./docs.py serve
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That command says Make sure you run the build-all command first, should that be added first?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be fixed in: 10aa15b

docs.py Show resolved Hide resolved
help/en/docs/MISSING-TRANSLATION.md Show resolved Hide resolved
requirements.txt Show resolved Hide resolved
Copy link
Member

@paulfitz paulfitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @fflorent ! I think this is good to land. Thanks for doing this all carefully and incrementally.

help/en/docs/MISSING-TRANSLATION.md Show resolved Hide resolved
@paulfitz paulfitz merged commit ef3359b into gristlabs:master Feb 28, 2024
5 checks passed
@fflorent fflorent deleted the add-localization branch February 28, 2024 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants