-
Notifications
You must be signed in to change notification settings - Fork 0
chore/delete #6
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
chore/delete #6
Conversation
|
Blar frog is jumping into review mode for 'chore/delete'. Let's see if this bug zapper works or if we need to fix our bug catching skills. Starting the review now! |
|
This PR appears to focus primarily on cleaning up code related to FastAPI's encoding and exception handling. It deletes a substantial portion of the 'jsonable_encoder' function in 'encoders.py', including the removal of complex JSON encoding logic. Additionally, it modifies a dictionary mapping in the same file, likely affecting how certain types are serialized. In 'exception_handlers.py', it enhances the HTTP exception handler to properly serialize JSON responses when exception details are dictionaries. Moreover, it removes the 'WebSocketRequestValidationError' class from 'exceptions.py'. Overall, these changes aim to streamline or refactor encoding and exception handling behavior in the FastAPI codebase. Pull Request Impact: 73 🔄 File Changes Overview
📊 Impact SummaryThis tables shows the impact of the changes in the codebase
📜 Blar InstructionsBlar Commands
Tags Explanation
|
| Skip to content | ||
| Follow FastAPI on LinkedIn to stay updated | ||
| logo | ||
| FastAPI | ||
| Development - Contributing | ||
|
|
||
| en - English | ||
| az - azərbaycan dili | ||
| bn - বাংলা | ||
| de - Deutsch | ||
| es - español | ||
| fa - فارسی | ||
| fr - français | ||
| he - עברית | ||
| hu - magyar | ||
| id - Bahasa Indonesia | ||
| it - italiano | ||
| ja - 日本語 | ||
| ko - 한국어 | ||
| nl - Nederlands | ||
| pl - Polski | ||
| pt - português | ||
| ru - русский язык | ||
| tr - Türkçe | ||
| uk - українська мова | ||
| ur - اردو | ||
| vi - Tiếng Việt | ||
| yo - Yorùbá | ||
| zh - 简体中文 | ||
| zh-hant - 繁體中文 | ||
| 😉 | ||
|
|
||
| Type to start searching | ||
| fastapi/fastapi | ||
|
|
||
| 0.115.12 | ||
| 84.4k | ||
| 7.3k | ||
|
|
||
| FastAPI | ||
| Features | ||
| Learn | ||
| Reference | ||
| FastAPI People | ||
| Resources | ||
| About | ||
| Release Notes | ||
|
|
||
| Resources | ||
| Help FastAPI - Get Help | ||
| Development - Contributing | ||
| Full Stack FastAPI Template | ||
| External Links and Articles | ||
| FastAPI and friends newsletter | ||
| Repository Management Tasks | ||
|
|
||
| Table of contents | ||
|
|
||
| Developing | ||
| Virtual environment | ||
| Install requirements using pip | ||
| Using your local FastAPI | ||
| Format the code | ||
| Tests | ||
| Docs | ||
| Docs live | ||
| Typer CLI (optional) | ||
| Docs Structure | ||
| Docs for tests | ||
| Apps and docs at the same time | ||
| Translations | ||
| Tips and guidelines | ||
| Existing language | ||
| Don't Translate these Pages | ||
| New Language | ||
| Preview the result | ||
| Translation specific tips and guidelines | ||
|
|
||
| FastAPI | ||
| Resources | ||
|
|
||
| Development - Contributing¶ | ||
|
|
||
| First, you might want to see the basic ways to help FastAPI and get help. | ||
| Developing¶ | ||
|
|
||
| If you already cloned the fastapi repository and you want to deep dive in the code, here are some guidelines to set up your environment. | ||
| Virtual environment¶ | ||
|
|
||
| Follow the instructions to create and activate a virtual environment for the internal code of fastapi. | ||
| Install requirements using pip¶ | ||
|
|
||
| After activating the environment, install the required packages: | ||
|
|
||
| pip install -r requirements.txt | ||
| ████████████████████████████████████████ 100% | ||
| restart ↻ | ||
|
|
||
| It will install all the dependencies and your local FastAPI in your local environment. | ||
| Using your local FastAPI¶ | ||
|
|
||
| If you create a Python file that imports and uses FastAPI, and run it with the Python from your local environment, it will use your cloned local FastAPI source code. | ||
|
|
||
| And if you update that local FastAPI source code when you run that Python file again, it will use the fresh version of FastAPI you just edited. | ||
|
|
||
| That way, you don't have to "install" your local version to be able to test every change. | ||
|
|
||
| Technical Details | ||
|
|
||
| This only happens when you install using this included requirements.txt instead of running pip install fastapi directly. | ||
|
|
||
| That is because inside the requirements.txt file, the local version of FastAPI is marked to be installed in "editable" mode, with the -e option. | ||
| Format the code¶ | ||
|
|
||
| There is a script that you can run that will format and clean all your code: | ||
|
|
||
| bash scripts/format.sh | ||
| restart ↻ | ||
|
|
||
| It will also auto-sort all your imports. | ||
| Tests¶ | ||
|
|
||
| There is a script that you can run locally to test all the code and generate coverage reports in HTML: | ||
|
|
||
| bash scripts/test-cov-html.sh | ||
| restart ↻ | ||
|
|
||
| This command generates a directory ./htmlcov/, if you open the file ./htmlcov/index.html in your browser, you can explore interactively the regions of code that are covered by the tests, and notice if there is any region missing. | ||
| Docs¶ | ||
|
|
||
| First, make sure you set up your environment as described above, that will install all the requirements. | ||
| Docs live¶ | ||
|
|
||
| During local development, there is a script that builds the site and checks for any changes, live-reloading: | ||
|
|
||
| python ./scripts/docs.py live | ||
| [INFO] Serving on http://127.0.0.1:8008 | ||
| [INFO] Start watching changes | ||
| [INFO] Start detecting changes | ||
|
|
||
| restart ↻ | ||
|
|
||
| It will serve the documentation on http://127.0.0.1:8008. | ||
|
|
||
| That way, you can edit the documentation/source files and see the changes live. | ||
|
|
||
| Tip | ||
|
|
||
| Alternatively, you can perform the same steps that scripts does manually. | ||
|
|
||
| Go into the language directory, for the main docs in English it's at docs/en/: | ||
|
|
||
| $ cd docs/en/ | ||
|
|
||
| Then run mkdocs in that directory: | ||
|
|
||
| $ mkdocs serve --dev-addr 127.0.0.1:8008 | ||
|
|
||
| Typer CLI (optional)¶ | ||
|
|
||
| The instructions here show you how to use the script at ./scripts/docs.py with the python program directly. | ||
|
|
||
| But you can also use Typer CLI, and you will get autocompletion in your terminal for the commands after installing completion. | ||
|
|
||
| If you install Typer CLI, you can install completion with: | ||
|
|
||
| typer --install-completion | ||
| zsh completion installed in /home/user/.bashrc. | ||
| Completion will take effect once you restart the terminal. | ||
|
|
||
| restart ↻ | ||
|
|
||
| Docs Structure¶ | ||
|
|
||
| The documentation uses MkDocs. | ||
|
|
||
| And there are extra tools/scripts in place to handle translations in ./scripts/docs.py. | ||
|
|
||
| Tip | ||
|
|
||
| You don't need to see the code in ./scripts/docs.py, you just use it in the command line. | ||
|
|
||
| All the documentation is in Markdown format in the directory ./docs/en/. | ||
|
|
||
| Many of the tutorials have blocks of code. | ||
|
|
||
| In most of the cases, these blocks of code are actual complete applications that can be run as is. | ||
|
|
||
| In fact, those blocks of code are not written inside the Markdown, they are Python files in the ./docs_src/ directory. | ||
|
|
||
| And those Python files are included/injected in the documentation when generating the site. | ||
| Docs for tests¶ | ||
|
|
||
| Most of the tests actually run against the example source files in the documentation. | ||
|
|
||
| This helps to make sure that: | ||
|
|
||
| The documentation is up-to-date. | ||
| The documentation examples can be run as is. | ||
| Most of the features are covered by the documentation, ensured by test coverage. | ||
|
|
||
| Apps and docs at the same time¶ | ||
|
|
||
| If you run the examples with, e.g.: | ||
|
|
||
| fastapi dev tutorial001.py | ||
| INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) | ||
|
|
||
| restart ↻ | ||
|
|
||
| as Uvicorn by default will use the port 8000, the documentation on port 8008 won't clash. | ||
| Translations¶ | ||
|
|
||
| Help with translations is VERY MUCH appreciated! And it can't be done without the help from the community. 🌎 🚀 | ||
|
|
||
| Here are the steps to help with translations. | ||
| Tips and guidelines¶ | ||
|
|
||
| Check the currently existing pull requests for your language. You can filter the pull requests by the ones with the label for your language. For example, for Spanish, the label is lang-es. | ||
|
|
||
| Review those pull requests, requesting changes or approving them. For the languages I don't speak, I'll wait for several others to review the translation before merging. | ||
|
|
||
| Tip | ||
|
|
||
| You can add comments with change suggestions to existing pull requests. | ||
|
|
||
| Check the docs about adding a pull request review to approve it or request changes. | ||
|
|
||
| Check if there's a GitHub Discussion to coordinate translations for your language. You can subscribe to it, and when there's a new pull request to review, an automatic comment will be added to the discussion. | ||
|
|
||
| If you translate pages, add a single pull request per page translated. That will make it much easier for others to review it. | ||
|
|
||
| To check the 2-letter code for the language you want to translate, you can use the table List of ISO 639-1 codes. | ||
|
|
||
| Existing language¶ | ||
|
|
||
| Let's say you want to translate a page for a language that already has translations for some pages, like Spanish. | ||
|
|
||
| In the case of Spanish, the 2-letter code is es. So, the directory for Spanish translations is located at docs/es/. | ||
|
|
||
| Tip | ||
|
|
||
| The main ("official") language is English, located at docs/en/. | ||
|
|
||
| Now run the live server for the docs in Spanish: | ||
|
|
||
| fast → | ||
| 💬 Use the command "live" and pass the language code as a CLI argumentpython ./scripts/docs.py live es | ||
|
|
||
| Tip | ||
|
|
||
| Alternatively, you can perform the same steps that scripts does manually. | ||
|
|
||
| Go into the language directory, for the Spanish translations it's at docs/es/: | ||
|
|
||
| $ cd docs/es/ | ||
|
|
||
| Then run mkdocs in that directory: | ||
|
|
||
| $ mkdocs serve --dev-addr 127.0.0.1:8008 | ||
|
|
||
| Now you can go to http://127.0.0.1:8008 and see your changes live. | ||
|
|
||
| You will see that every language has all the pages. But some pages are not translated and have an info box at the top, about the missing translation. | ||
|
|
||
| Now let's say that you want to add a translation for the section Features. | ||
|
|
||
| Copy the file at: | ||
|
|
||
| docs/en/docs/features.md | ||
|
|
||
| Paste it in exactly the same location but for the language you want to translate, e.g.: | ||
|
|
||
| docs/es/docs/features.md | ||
|
|
||
| Tip | ||
|
|
||
| Notice that the only change in the path and file name is the language code, from en to es. | ||
|
|
||
| If you go to your browser you will see that now the docs show your new section (the info box at the top is gone). 🎉 | ||
|
|
||
| Now you can translate it all and see how it looks as you save the file. | ||
| Don't Translate these Pages¶ | ||
|
|
||
| 🚨 Don't translate: | ||
|
|
||
| Files under reference/ | ||
| release-notes.md | ||
| fastapi-people.md | ||
| external-links.md | ||
| newsletter.md | ||
| management-tasks.md | ||
| management.md | ||
| contributing.md | ||
|
|
||
| Some of these files are updated very frequently and a translation would always be behind, or they include the main content from English source files, etc. | ||
| New Language¶ | ||
|
|
||
| Let's say that you want to add translations for a language that is not yet translated, not even some pages. | ||
|
|
||
| Let's say you want to add translations for Creole, and it's not yet there in the docs. | ||
|
|
||
| Checking the link from above, the code for "Creole" is ht. | ||
|
|
||
| The next step is to run the script to generate a new translation directory: | ||
|
|
||
|
|
||
|
|
||
|
|
||
| Now you can check in your code editor the newly created directory docs/ht/. | ||
|
|
||
| That command created a file docs/ht/mkdocs.yml with a simple config that inherits everything from the en version: | ||
|
|
||
| INHERIT: ../en/mkdocs.yml | ||
|
|
||
| Tip | ||
|
|
||
| You could also simply create that file with those contents manually. | ||
|
|
||
| That command also created a dummy file docs/ht/index.md for the main page, you can start by translating that one. | ||
|
|
||
| You can continue with the previous instructions for an "Existing Language" for that process. | ||
|
|
||
| You can make the first pull request with those two files, docs/ht/mkdocs.yml and docs/ht/index.md. 🎉 | ||
| Preview the result¶ | ||
|
|
||
| As already mentioned above, you can use the ./scripts/docs.py with the live command to preview the results (or mkdocs serve). | ||
|
|
||
| Once you are done, you can also test it all as it would look online, including all the other languages. | ||
|
|
||
| To do that, first build all the docs: | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| This builds all those independent MkDocs sites for each language, combines them, and generates the final output at ./site/. | ||
|
|
||
| Then you can serve that with the command serve: | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| Translation specific tips and guidelines¶ | ||
|
|
||
| Translate only the Markdown documents (.md). Do not translate the code examples at ./docs_src. | ||
|
|
||
| In code blocks within the Markdown document, translate comments (# a comment), but leave the rest unchanged. | ||
|
|
||
| Do not change anything enclosed in "``" (inline code). | ||
|
|
||
| In lines starting with /// translate only the text part after |. Leave the rest unchanged. | ||
|
|
||
| You can translate info boxes like /// warning with for example /// warning | Achtung. But do not change the word immediately after the ///, it determines the color of the info box. | ||
|
|
||
| Do not change the paths in links to images, code files, Markdown documents. | ||
|
|
||
| However, when a Markdown document is translated, the #hash-parts in links to its headings may change. Update these links if possible. | ||
| Search for such links in the translated document using the regex #[^# ]. | ||
| Search in all documents already translated into your language for your-translated-document.md. For example VS Code has an option "Edit" -> "Find in Files". | ||
| When translating a document, do not "pre-translate" #hash-parts that link to headings in untranslated documents. | ||
|
|
||
| Was this page helpful? | ||
| Previous |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 Warning 🎨 Design Pattern Issue
Specific guidelines for translating FastAPI docs
This PR is completely off‐track—you're pasting hundreds of lines of rendered docs into a Python source file. Per our translation guidelines, only .md files under docs/<lang>/ get edited (and inside code blocks you only translate comments). Revert these changes, restore the original encoders.py, and move any translation work into the proper Markdown files.
We used the following considerations to provide context for this review — see them here
Reply if you have any questions or let me know if I missed something.
Don't forget to react with a 👍 or 👎 to the comments made by Blar to help us improve.
| Skip to content | ||
| Follow FastAPI on LinkedIn to stay updated | ||
| logo | ||
| FastAPI | ||
| Development - Contributing | ||
|
|
||
| en - English | ||
| az - azərbaycan dili | ||
| bn - বাংলা | ||
| de - Deutsch | ||
| es - español | ||
| fa - فارسی | ||
| fr - français | ||
| he - עברית | ||
| hu - magyar | ||
| id - Bahasa Indonesia | ||
| it - italiano | ||
| ja - 日本語 | ||
| ko - 한국어 | ||
| nl - Nederlands | ||
| pl - Polski | ||
| pt - português | ||
| ru - русский язык | ||
| tr - Türkçe | ||
| uk - українська мова | ||
| ur - اردو | ||
| vi - Tiếng Việt | ||
| yo - Yorùbá | ||
| zh - 简体中文 | ||
| zh-hant - 繁體中文 | ||
| 😉 | ||
|
|
||
| Type to start searching | ||
| fastapi/fastapi | ||
|
|
||
| 0.115.12 | ||
| 84.4k | ||
| 7.3k | ||
|
|
||
| FastAPI | ||
| Features | ||
| Learn | ||
| Reference | ||
| FastAPI People | ||
| Resources | ||
| About | ||
| Release Notes | ||
|
|
||
| Resources | ||
| Help FastAPI - Get Help | ||
| Development - Contributing | ||
| Full Stack FastAPI Template | ||
| External Links and Articles | ||
| FastAPI and friends newsletter | ||
| Repository Management Tasks | ||
|
|
||
| Table of contents | ||
|
|
||
| Developing | ||
| Virtual environment | ||
| Install requirements using pip | ||
| Using your local FastAPI | ||
| Format the code | ||
| Tests | ||
| Docs | ||
| Docs live | ||
| Typer CLI (optional) | ||
| Docs Structure | ||
| Docs for tests | ||
| Apps and docs at the same time | ||
| Translations | ||
| Tips and guidelines | ||
| Existing language | ||
| Don't Translate these Pages | ||
| New Language | ||
| Preview the result | ||
| Translation specific tips and guidelines | ||
|
|
||
| FastAPI | ||
| Resources | ||
|
|
||
| Development - Contributing¶ | ||
|
|
||
| First, you might want to see the basic ways to help FastAPI and get help. | ||
| Developing¶ | ||
|
|
||
| If you already cloned the fastapi repository and you want to deep dive in the code, here are some guidelines to set up your environment. | ||
| Virtual environment¶ | ||
|
|
||
| Follow the instructions to create and activate a virtual environment for the internal code of fastapi. | ||
| Install requirements using pip¶ | ||
|
|
||
| After activating the environment, install the required packages: | ||
|
|
||
| pip install -r requirements.txt | ||
| ████████████████████████████████████████ 100% | ||
| restart ↻ | ||
|
|
||
| It will install all the dependencies and your local FastAPI in your local environment. | ||
| Using your local FastAPI¶ | ||
|
|
||
| If you create a Python file that imports and uses FastAPI, and run it with the Python from your local environment, it will use your cloned local FastAPI source code. | ||
|
|
||
| And if you update that local FastAPI source code when you run that Python file again, it will use the fresh version of FastAPI you just edited. | ||
|
|
||
| That way, you don't have to "install" your local version to be able to test every change. | ||
|
|
||
| Technical Details | ||
|
|
||
| This only happens when you install using this included requirements.txt instead of running pip install fastapi directly. | ||
|
|
||
| That is because inside the requirements.txt file, the local version of FastAPI is marked to be installed in "editable" mode, with the -e option. | ||
| Format the code¶ | ||
|
|
||
| There is a script that you can run that will format and clean all your code: | ||
|
|
||
| bash scripts/format.sh | ||
| restart ↻ | ||
|
|
||
| It will also auto-sort all your imports. | ||
| Tests¶ | ||
|
|
||
| There is a script that you can run locally to test all the code and generate coverage reports in HTML: | ||
|
|
||
| bash scripts/test-cov-html.sh | ||
| restart ↻ | ||
|
|
||
| This command generates a directory ./htmlcov/, if you open the file ./htmlcov/index.html in your browser, you can explore interactively the regions of code that are covered by the tests, and notice if there is any region missing. | ||
| Docs¶ | ||
|
|
||
| First, make sure you set up your environment as described above, that will install all the requirements. | ||
| Docs live¶ | ||
|
|
||
| During local development, there is a script that builds the site and checks for any changes, live-reloading: | ||
|
|
||
| python ./scripts/docs.py live | ||
| [INFO] Serving on http://127.0.0.1:8008 | ||
| [INFO] Start watching changes | ||
| [INFO] Start detecting changes | ||
|
|
||
| restart ↻ | ||
|
|
||
| It will serve the documentation on http://127.0.0.1:8008. | ||
|
|
||
| That way, you can edit the documentation/source files and see the changes live. | ||
|
|
||
| Tip | ||
|
|
||
| Alternatively, you can perform the same steps that scripts does manually. | ||
|
|
||
| Go into the language directory, for the main docs in English it's at docs/en/: | ||
|
|
||
| $ cd docs/en/ | ||
|
|
||
| Then run mkdocs in that directory: | ||
|
|
||
| $ mkdocs serve --dev-addr 127.0.0.1:8008 | ||
|
|
||
| Typer CLI (optional)¶ | ||
|
|
||
| The instructions here show you how to use the script at ./scripts/docs.py with the python program directly. | ||
|
|
||
| But you can also use Typer CLI, and you will get autocompletion in your terminal for the commands after installing completion. | ||
|
|
||
| If you install Typer CLI, you can install completion with: | ||
|
|
||
| typer --install-completion | ||
| zsh completion installed in /home/user/.bashrc. | ||
| Completion will take effect once you restart the terminal. | ||
|
|
||
| restart ↻ | ||
|
|
||
| Docs Structure¶ | ||
|
|
||
| The documentation uses MkDocs. | ||
|
|
||
| And there are extra tools/scripts in place to handle translations in ./scripts/docs.py. | ||
|
|
||
| Tip | ||
|
|
||
| You don't need to see the code in ./scripts/docs.py, you just use it in the command line. | ||
|
|
||
| All the documentation is in Markdown format in the directory ./docs/en/. | ||
|
|
||
| Many of the tutorials have blocks of code. | ||
|
|
||
| In most of the cases, these blocks of code are actual complete applications that can be run as is. | ||
|
|
||
| In fact, those blocks of code are not written inside the Markdown, they are Python files in the ./docs_src/ directory. | ||
|
|
||
| And those Python files are included/injected in the documentation when generating the site. | ||
| Docs for tests¶ | ||
|
|
||
| Most of the tests actually run against the example source files in the documentation. | ||
|
|
||
| This helps to make sure that: | ||
|
|
||
| The documentation is up-to-date. | ||
| The documentation examples can be run as is. | ||
| Most of the features are covered by the documentation, ensured by test coverage. | ||
|
|
||
| Apps and docs at the same time¶ | ||
|
|
||
| If you run the examples with, e.g.: | ||
|
|
||
| fastapi dev tutorial001.py | ||
| INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) | ||
|
|
||
| restart ↻ | ||
|
|
||
| as Uvicorn by default will use the port 8000, the documentation on port 8008 won't clash. | ||
| Translations¶ | ||
|
|
||
| Help with translations is VERY MUCH appreciated! And it can't be done without the help from the community. 🌎 🚀 | ||
|
|
||
| Here are the steps to help with translations. | ||
| Tips and guidelines¶ | ||
|
|
||
| Check the currently existing pull requests for your language. You can filter the pull requests by the ones with the label for your language. For example, for Spanish, the label is lang-es. | ||
|
|
||
| Review those pull requests, requesting changes or approving them. For the languages I don't speak, I'll wait for several others to review the translation before merging. | ||
|
|
||
| Tip | ||
|
|
||
| You can add comments with change suggestions to existing pull requests. | ||
|
|
||
| Check the docs about adding a pull request review to approve it or request changes. | ||
|
|
||
| Check if there's a GitHub Discussion to coordinate translations for your language. You can subscribe to it, and when there's a new pull request to review, an automatic comment will be added to the discussion. | ||
|
|
||
| If you translate pages, add a single pull request per page translated. That will make it much easier for others to review it. | ||
|
|
||
| To check the 2-letter code for the language you want to translate, you can use the table List of ISO 639-1 codes. | ||
|
|
||
| Existing language¶ | ||
|
|
||
| Let's say you want to translate a page for a language that already has translations for some pages, like Spanish. | ||
|
|
||
| In the case of Spanish, the 2-letter code is es. So, the directory for Spanish translations is located at docs/es/. | ||
|
|
||
| Tip | ||
|
|
||
| The main ("official") language is English, located at docs/en/. | ||
|
|
||
| Now run the live server for the docs in Spanish: | ||
|
|
||
| fast → | ||
| 💬 Use the command "live" and pass the language code as a CLI argumentpython ./scripts/docs.py live es | ||
|
|
||
| Tip | ||
|
|
||
| Alternatively, you can perform the same steps that scripts does manually. | ||
|
|
||
| Go into the language directory, for the Spanish translations it's at docs/es/: | ||
|
|
||
| $ cd docs/es/ | ||
|
|
||
| Then run mkdocs in that directory: | ||
|
|
||
| $ mkdocs serve --dev-addr 127.0.0.1:8008 | ||
|
|
||
| Now you can go to http://127.0.0.1:8008 and see your changes live. | ||
|
|
||
| You will see that every language has all the pages. But some pages are not translated and have an info box at the top, about the missing translation. | ||
|
|
||
| Now let's say that you want to add a translation for the section Features. | ||
|
|
||
| Copy the file at: | ||
|
|
||
| docs/en/docs/features.md | ||
|
|
||
| Paste it in exactly the same location but for the language you want to translate, e.g.: | ||
|
|
||
| docs/es/docs/features.md | ||
|
|
||
| Tip | ||
|
|
||
| Notice that the only change in the path and file name is the language code, from en to es. | ||
|
|
||
| If you go to your browser you will see that now the docs show your new section (the info box at the top is gone). 🎉 | ||
|
|
||
| Now you can translate it all and see how it looks as you save the file. | ||
| Don't Translate these Pages¶ | ||
|
|
||
| 🚨 Don't translate: | ||
|
|
||
| Files under reference/ | ||
| release-notes.md | ||
| fastapi-people.md | ||
| external-links.md | ||
| newsletter.md | ||
| management-tasks.md | ||
| management.md | ||
| contributing.md | ||
|
|
||
| Some of these files are updated very frequently and a translation would always be behind, or they include the main content from English source files, etc. | ||
| New Language¶ | ||
|
|
||
| Let's say that you want to add translations for a language that is not yet translated, not even some pages. | ||
|
|
||
| Let's say you want to add translations for Creole, and it's not yet there in the docs. | ||
|
|
||
| Checking the link from above, the code for "Creole" is ht. | ||
|
|
||
| The next step is to run the script to generate a new translation directory: | ||
|
|
||
|
|
||
|
|
||
|
|
||
| Now you can check in your code editor the newly created directory docs/ht/. | ||
|
|
||
| That command created a file docs/ht/mkdocs.yml with a simple config that inherits everything from the en version: | ||
|
|
||
| INHERIT: ../en/mkdocs.yml | ||
|
|
||
| Tip | ||
|
|
||
| You could also simply create that file with those contents manually. | ||
|
|
||
| That command also created a dummy file docs/ht/index.md for the main page, you can start by translating that one. | ||
|
|
||
| You can continue with the previous instructions for an "Existing Language" for that process. | ||
|
|
||
| You can make the first pull request with those two files, docs/ht/mkdocs.yml and docs/ht/index.md. 🎉 | ||
| Preview the result¶ | ||
|
|
||
| As already mentioned above, you can use the ./scripts/docs.py with the live command to preview the results (or mkdocs serve). | ||
|
|
||
| Once you are done, you can also test it all as it would look online, including all the other languages. | ||
|
|
||
| To do that, first build all the docs: | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| This builds all those independent MkDocs sites for each language, combines them, and generates the final output at ./site/. | ||
|
|
||
| Then you can serve that with the command serve: | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| Translation specific tips and guidelines¶ | ||
|
|
||
| Translate only the Markdown documents (.md). Do not translate the code examples at ./docs_src. | ||
|
|
||
| In code blocks within the Markdown document, translate comments (# a comment), but leave the rest unchanged. | ||
|
|
||
| Do not change anything enclosed in "``" (inline code). | ||
|
|
||
| In lines starting with /// translate only the text part after |. Leave the rest unchanged. | ||
|
|
||
| You can translate info boxes like /// warning with for example /// warning | Achtung. But do not change the word immediately after the ///, it determines the color of the info box. | ||
|
|
||
| Do not change the paths in links to images, code files, Markdown documents. | ||
|
|
||
| However, when a Markdown document is translated, the #hash-parts in links to its headings may change. Update these links if possible. | ||
| Search for such links in the translated document using the regex #[^# ]. | ||
| Search in all documents already translated into your language for your-translated-document.md. For example VS Code has an option "Edit" -> "Find in Files". | ||
| When translating a document, do not "pre-translate" #hash-parts that link to headings in untranslated documents. | ||
|
|
||
| Was this page helpful? | ||
| Previous | ||
| Help FastAPI - Get Help | ||
| Next | ||
| Full Stack FastAPI Template | ||
| The FastAPI trademark is owned by @tiangolo and is registered in the US and across other regions | ||
| Made with Material for MkDocs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Error 🐛 Bug
HTML content inserted into encoders.py breaks Python syntax.
Issue Explanation
- File at
blarApp/fastapi/fastapi/encoders.pycontains non-Python text after a lambda assignment. - Lines starting with "Skip to content" and "Follow FastAPI on LinkedIn to stay updated" are invalid in Python.
- The expression
lambda td: td.total_is incomplete and followed by HTML, causing a syntax error on import.
datetime.timedelta: lambda td: td.total_
Skip to content
Follow FastAPI on LinkedIn to stay updatedReply if you have any questions or let me know if I missed something.
Don't forget to react with a 👍 or 👎 to the comments made by Blar to help us improve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could u help me understand why this issue is a problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely, let me clarify why this is a problem.
The issue is that your file, encoders.py, has some unexpected non-Python text inserted directly into the code. Here’s what’s wrong:
-
Python source files must only contain valid Python code (and possibly comments or docstrings).
-
In your case, after a line with lambda assignment, there are lines like:
datetime.timedelta: lambda td: td.total_ Skip to content Follow FastAPI on LinkedIn to stay updated
-
The text
Skip to contentandFollow FastAPI on LinkedIn to stay updatedis not valid Python—it looks like HTML or a pasted banner from a web page. -
This extra text will cause a syntax error when Python tries to parse the file, making it impossible to run or import.
Additionally, the lambda expression is incomplete:
lambda td: td.total_This doesn’t look like a complete method—it’s missing something (probably should be td.total_seconds()).
Quick summary:
Having random non-code text inside a Python file breaks the file, causing it not to run, and the lambda itself is also incomplete.
If you need help fixing it, let me know!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets make a good rule for our wiki to make sure this never happens again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea! Here’s a clear rule you can add to your wiki to prevent this type of issue in the future:
📜 Python Source File Hygiene Rule
Rule:
All Python files in the project must contain only valid Python code, comments, or documentation strings.
External content such as HTML, banners, web labels, or unrelated text must never be inserted into Python source code.
Why:
Non-Python content in source files will break parsing and execution, causing syntax errors and blocking imports.
How to Avoid:
- Do not paste code directly from web pages without checking for hidden or non-code lines.
- Review any changes before committing to ensure only valid Python code is present.
- Use an editor or IDE that highlights syntax errors.
Example of what NOT to do:
def my_function():
print("Hello, world!")
Skip to content
Follow us on LinkedInWould you like me to suggest a checklist or pre-commit hook to help enforce this as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 Warning 🐛 Bug
jsonable_encoder function definition is removed, causing NameError on existing calls.
Issue Explanation
- The
jsonable_encoderfunction definition is fully removed (seeMerged file: jsonable_encoder node marked DELETED). - Existing calls to
jsonable_encodernow reference an undefined name. - Runtime errors (NameError) will occur when such calls execute.
- No alternative implementation for
jsonable_encoderis present.
No information foundReply if you have any questions or let me know if I missed something.
Don't forget to react with a 👍 or 👎 to the comments made by Blar to help us improve.
| class WebSocketRequestValidationError(ValidationException): | ||
| pass | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Error 🐛 Bug
Signature in exception_handlers.py references removed class WebSocketRequestValidationError, causing a NameError at import.
Issue Explanation
- In
blarApp/fastapi/fastapi/exception_handlers.py, the functionwebsocket_request_validation_exception_handlerdeclares the parameterexc: WebSocketRequestValidationError. - The class
WebSocketRequestValidationErrorhas been deleted fromfastapi/exceptions.py. - The annotation of a non-existent class raises a NameError when the module is loaded.
async def websocket_request_validation_exception_handler(
websocket: WebSocket, exc: WebSocketRequestValidationError
) -> None:Reply if you have any questions or let me know if I missed something.
Don't forget to react with a 👍 or 👎 to the comments made by Blar to help us improve.
|
Review's done! 🚀 Check out the feedback and let me know if you need anything! – Blar |
|
Looks like your code is as disciplined as an unruly toddler after a sugar rush. Did you even run the tests or just hope for the best with this chaos? |
No description provided.