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 Russian translation for docs/ru/docs/tutorial/middleware.md #10538

Closed

Conversation

AlertRED
Copy link
Contributor

No description provided.

@tiangolo
Copy link
Owner

📝 Docs preview for commit a3d640c at: https://14559915.fastapitiangolo.pages.dev

@tiangolo tiangolo added lang-all Translations lang-ru Russian translations awaiting-review labels Oct 30, 2023

* Он принимает каждый **запрос**, поступающий в ваше приложение.
* Затем он может что-то сделать с этим **запросом** или выполнить любой необходимый код.
* Затем он передает **запрос** на обработку в *операцию пути*.
Copy link
Contributor

Choose a reason for hiding this comment

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

...в оставшуюся часть приложения (через операцию пути)


В приложения **FastAPI** можно добавлять мидлвары.

Мидлвар - это функция, которая работает с каждым **запросом** до того, как он будет обработан какой-либо *операцией пути*. А также с каждым **ответом** перед его возвратом клиенту.
Copy link
Contributor

Choose a reason for hiding this comment

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

...перед отправкой его клиенту.

@@ -0,0 +1,61 @@
# Мидлвар
Copy link
Contributor

Choose a reason for hiding this comment

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

Так себе транслитерация. Есть русские "промежуточное ПО" либо "промежуточный слой кода". Как вариант – переводить по-русски, а в скобках писать (middleware).

* Он принимает каждый **запрос**, поступающий в ваше приложение.
* Затем он может что-то сделать с этим **запросом** или выполнить любой необходимый код.
* Затем он передает **запрос** на обработку в *операцию пути*.
* Затем принимается **ответ**, сгенерированный *операцией пути*.
Copy link
Contributor

Choose a reason for hiding this comment

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

Затем он принимает ответ созданный приложением (какой-либо операцией пути)

* Он может что-то сделать с этим **ответом** или выполнить любой необходимый код.
* Затем он возвращает **ответ**.

!!! note "Технические детали"
Copy link
Contributor

Choose a reason for hiding this comment

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

детали –> подробности

* Затем он возвращает **ответ**.

!!! note "Технические детали"
Если у вас есть зависимости с `yield`, то код выхода (finally) будет выполняться *после* мидлвар.
Copy link
Contributor

Choose a reason for hiding this comment

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

выполНЕН

!!! note "Технические детали"
Если у вас есть зависимости с `yield`, то код выхода (finally) будет выполняться *после* мидлвар.

Если были фоновые задачи (описанные позже), то они будут выполняться *после* всех промежуточных программ.
Copy link
Contributor

@s111d s111d Jan 7, 2024

Choose a reason for hiding this comment

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

(описанные НИЖЕ)
всех промежуточных программ –> всего промежуточного ПО


## Создание мидлвар

Для создания мидлвар используется декоратор `@app.middleware("http")` поверх функции.
Copy link
Contributor

@s111d s111d Jan 7, 2024

Choose a reason for hiding this comment

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

можно просто "перед функцией" или "к функции применяется декоратор..."


Но если у вас есть пользовательские заголовки, чтобы их мог видеть клиент в браузере, вам необходимо добавить их в CORS-конфигурации ([CORS (Cross-Origin Resource Sharing)](cors.md){.internal-link target=_blank}) с помощью параметра `expose_headers`, описанного в <a href="https://www.starlette.io/middleware/#corsmiddleware" class="external-link" target="_blank">документации по CORS в библиотеке Starlette</a>.

!!! note "Технические детали"
Copy link
Contributor

@s111d s111d Jan 7, 2024

Choose a reason for hiding this comment

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

детали –> подробности


**FastAPI** предоставляет его в качестве удобства для вас, разработчика. Но он поставляется непосредственно из Starlette.

### До и после `ответа`
Copy link
Contributor

Choose a reason for hiding this comment

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

вряд ли здесь стоит переводить Response, т.к. имеется в виду объект.


Более подробно о других мидлварах вы можете прочитать в разделе [Расширенное руководство пользователя: Продвинутый мидлвар](../advanced/middleware.md){.internal-link target=_blank}.

О том, как управлять <abbr title="Cross-Origin Resource Sharing">CORS</abbr> с помощью мидлвар, вы узнаете в следующем разделе.
Copy link
Contributor

Choose a reason for hiding this comment

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

возможно, лучше "перехватывать"

@tiangolo
Copy link
Owner

tiangolo commented Feb 8, 2024

As this PR had requested changes to be applied but has been inactive for a while, it's now going to be closed. But if there's anyone interested, feel free to create a new PR.

@tiangolo tiangolo closed this Feb 8, 2024
@JonnyBootsNpants
Copy link

JonnyBootsNpants commented Feb 9, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants