」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 幫助 FastAPI:如何為文件翻譯做出貢獻

幫助 FastAPI:如何為文件翻譯做出貢獻

發佈於2024-11-08
瀏覽:462

One of the great features of FastAPI is its great documentation ?. But wouldn't it be better if more people around the world had access to this documentation? ❤️

Sometimes we take for granted that all people can read the docs we provide, but it's not necessarily how it works to people around the world.

? Why add translations?

? There is already a really good documentation written in english in FastAPI website, so why help translate to other languages?

Making a fast google search, you can see that only 17% of the ? world population speaks english. You can check this wikipedia post: List of countries by English-speaking population to check the percentage of english speakers in your country.

For example, I'm a brazilian living in Brazil. And here, only 5% of the population have some level of english. This represents a very small portion of the population that can follow documentation written in English.

And continuing with the portuguese, it's not only Portugal and Brazil that speaks this language. There's also Angola, Mozambique, Cape Verde and many other countries. You can see the full list here.

Do you have any idea on how many people you can help when you translate the docs from your favorite programming language or framework? It's mindblowing thinking in the number of people who benefit from it.

Additionally, helping with translations is a very practical way to understand the way the project works, the workflow and approval that maintainers follow, etc.

✏️ How to create your first translation

FastAPI docs has a page dedicated on how to contribute to the project, including a section for the documentations and translations.

So let's take a look step by step on how you can setup your local environment and start creating translations to a language other then english!

? Forking FastAPI's repository

The first thing that you want to do is fork the FastAPI repo. Github has a great doc explaining how you can fork a repository. But basically, what you'll need to do is browse the repo you want, in this case FastAPI's repo and click Fork.

Helping FastAPI: How to contribute to docs translations

And that's it. Know you have your own copy of the repository. Now if you browse your own repositories, you'll see the forked repo right there:

Helping FastAPI: How to contribute to docs translations

?️ FastAPI's documentation structure

The FastAPI's documentation lives inside the folder docs, in the root of the repository. And all the source code from the docs lives inside docs_src folder.

Helping FastAPI: How to contribute to docs translations

As you can see, inside docs folder, there are all the current languages that has translations. It uses the ISO 693-1 two letter code for each language.

Each language folder will follow the same structure:

Helping FastAPI: How to contribute to docs translations

The en folder will have the complete documentation, but you'll notice that in other languages, despite having the same structure, not all files are present. And that's because not all files are translated to all languages (yet ?).

? So now you know the first way to find what you can translate: There is a missing file in your language? That's the one you can start translating!

☹️ Missing languages

Not all languages has translations yet. For example, if you look for the ?? Armenian code (hy) in the docs, you'll notice the it doesn't exist yet:

Helping FastAPI: How to contribute to docs translations

In these cases, FastAPI docs has a really good explanation on how you can add translations to new languages.

As you can see from the docs, FastAPI has a neat script to initialize a new language translation:

python ./scripts/docs.py new-lang hy

Now that the script added the folder and files, you can follow the process of adding translations to existing languages.

?️ Translating existing languages

Now that you already forked the FastAPI's repository and learned how the add a missing language (if its your case), let's see the whole process of translating a file of the docs.

? Ways to verify what doc to translate

There are a few ways you can easily find what doc you can translate.

1️⃣ Navigating through the docs

A simple and easy way is: Read the docs in your desired language. Just go to the docs at fastapi.tiangolo.com and select the desired language:

Helping FastAPI: How to contribute to docs translations

Once you reach a doc that has no translations, you'll see a warning telling you that the doc has not been yet translated:

Helping FastAPI: How to contribute to docs translations

Now you can go to the source code, find the doc file and create a copy at your desired language folder. The folder structure of the docs are pretty simple to understand.

In the example above, the breadcrumbs say that we are at: FastAPI (The root) - Learn - Advanced. So we can infer that the document lives somewhere in docs/en/docs. Probably in some folder named learn or advanced.

If we go to the source code, will see that the folder advanced really exists, and the file custom-response.md also exists.

An easier way to find the file is get the last part of the url and find for it in your editor. For example, in VSCode you can use ctrl e and enter that name:

Helping FastAPI: How to contribute to docs translations

2️⃣ Looking in source code

Another way you can find files that has no translations it to open the source code with your editor. Then you'll expand the desired language and the english language.

You will probably notice that the English folder has more files than the folder for your desired language. Now you can pick the missing file, create a copy of it at the language folder and translate it.

3️⃣ Using FastAPI Translations Management package

I created a ? package to help with FastAPI translations named fastapi translations management.

It's basically a lib that will look at all doc files and check the last commit date. This will give you a list of files that has not been translated yet and the files that are outdated.

Helping FastAPI: How to contribute to docs translations

To use it, you can install it with pip:

pip install -U fastapi-translations

And then use it at the root folder of your forked FastAPI repository:

fastapi_translations -l {two-letter-code-for-language}

This will give you a brief summary of missing translations and outdated translations:

Helping FastAPI: How to contribute to docs translations

You can also generate a csv file with all files that are outdated and missing with -c:

fastapi_translations -l pt -c

? Things to know before start your first translation

? Discussions

If you want to translate to a language that already exists, probably it has a Topic created under Discussions. You can search your language in github.com/fastapi/fastapi/discussions.

Helping FastAPI: How to contribute to docs translations

At portuguese discussions, we have a pattern to always post the file we are translating, and after we finish, we edit it to add the PR link:

Helping FastAPI: How to contribute to docs translations

? Reviews

All pull requests for translations must have at least two approvals from a person who speaks that language.

For example, if you create a translation for Japanese. Two people that speaks Japanese must review it before some mantainer approves the PR.

??‍⚖️ Another rules

There are some other rules that apply when we are translating some docs.

✅ Don't translate the code in docs_src;
✅ Only translate the markdown files;
✅ Inside code blocks, only translate the # comments;

You can check all the rules in FastAPI docs for tips and guidelines for translations.

✨ Creating your first translation

Now that we know almost everything that is to be know about translating FastAPI docs, let's get started and translate a new doc.

⚙️ Update your FastAPI fork

Whenever you start a new translation, you need to update your forked repository to make sure everything is updated ✔️.

The easiest way to do this is to navigate to your repository at github and click in sync fork -> update branch.

Helping FastAPI: How to contribute to docs translations

Now you can update your local repository with all changes from the main repo.

Helping FastAPI: How to contribute to docs translations

? Find the doc to translate

Now that our local repository is updated. Let's find some missing translation.

Helping FastAPI: How to contribute to docs translations

We can see that under docs/pt/docs/advanced, the ? folder security is missing. So let's translate the index.md for the advanced security topic.

??‍♀️ Notifying about translation in progress

Now that we picked a file to translate, let's tell everyone that in the ? Discussion for Portuguese translations that we are working on it:

Helping FastAPI: How to contribute to docs translations

?️ Creating the translation

Not let's create a branch for the translation:

git checkout -b features/pt-advanced-security-index

Since we working on our local forked repository, we don't necessarily need to create a specific branch. But I think it's a good thing to do. And working this way, we can start another work while people are reviewing our PR.

Now we can create both the missing folder ?, and the missing file ? under docs/pt/docs/advanced.

When I'm translating some file, I like to split the editor with the file that I'm working on, and the original file in english. But feel free to work the way is best for you.

Helping FastAPI: How to contribute to docs translations

Now that we finished our work translating the file, we can commit it:

git add docs/pt/docs/advanced/security/index.md
git commit -m "Add translation to docs/pt/docs/advanced/security/index.md"
git push origin features/pt-advanced-security-index

? Previewing the translation

Now that we finished the translation, we can see how it will look like on the official docs.

You can type in your terminal ??‍? (remember to install all deps):

python scripts/docs.py live pt

And you'll be able to check the result:

Helping FastAPI: How to contribute to docs translations

? Creating the Pull Request

Remember that we are working on our fork. Now that we commited to our repository, we need to send it to the FastAPI repository. Luckily, this is very easy to do.

If you go to the FastAPI repository, github will warn you that you pushed to your fork, and now you can create a PR to merge it:

Helping FastAPI: How to contribute to docs translations

We can click on compare & pull request and create the PR following the pattern for the title:

? Add Portuguese translation for path/of/file.md

Helping FastAPI: How to contribute to docs translations

Now we can wait for all the checks to run (they must pass). And someone from the FastAPI team will add the necessary tags.

Helping FastAPI: How to contribute to docs translations

And of course, we need to update our post at the discussions to inform that we finished the translation:

Helping FastAPI: How to contribute to docs translations

And after everything goes well, you'll get a message telling you that your PR was approved ✨:

Helping FastAPI: How to contribute to docs translations

? Dealing with problems

I didn't anticipate this when I started writing this article. A problem related with github actions and upload-artifact started happening and the checks from my PR failed ?.

This was a really nice thing to happen to demonstrate how we can deal with situations that our PR has some problems.

Helping FastAPI: How to contribute to docs translations

When I saw the failing checks, I tried to see if it was related with my PR directly. I saw it was not related, and then I marked Alejandra, who is a very helpful member of the FastAPI team. Sofie, who is also a member of the team mentioned the issue related with the problem right away.

Helping FastAPI: How to contribute to docs translations

As you can see, FastAPI has a really nice and helpful team and they always do their best to help you:

Helping FastAPI: How to contribute to docs translations

So if you need some help, try to reach one the them. Just be polite and patiente that they will help you ❤️!

? Benefits of translating docs

There are several benefits helping with the translations ?.

To me, the most important one is to help people who have difficulty reading documentation in english.

They can be ??‍? students trying to learn a new language or framework, or even a ?‍? professional who has not yet had the opportunity to learn english.

In addition to helping people, you can also ? learn new topics, find out about that detail that you used but didn't quite understand why, etc.

Also, helping translate docs requires you to review the original documentation. This may result in you finding improvements, topics that could be better explained, etc.

So, my advice is: do you have a language or framework that you really like and would like to start helping? Start with the documentation ?!

版本聲明 本文轉載於:https://dev.to/ceb10n/helping-fastapi-how-to-contribute-to-docs-translations-44a7?1如有侵犯,請聯絡[email protected]刪除
最新教學 更多>
  • 如何在 PHP 中有效率地計算兩個日期之間的月份數?
    如何在 PHP 中有效率地計算兩個日期之間的月份數?
    有效找出日期之間的月份計數一個常見的程式設計挑戰是確定兩個日期之間的月份數。在 PHP 中,有許多方法可以解決這個問題。 使用 DateTime 類別 (PHP >= 5.3):PHP 5.3 中引入的 DateTime 類別提供了方便的方法用於日期操作。計算月份差異:$d1 = new DateT...
    程式設計 發佈於2024-11-08
  • Bootstrap:建立和自訂導覽列
    Bootstrap:建立和自訂導覽列
    介紹 Bootstrap 是一個開源框架,廣泛用於 Web 開發,用於建立響應式且適合行動裝置的網站。 Bootstrap 的關鍵元件之一是導覽欄,它是一個水平導覽欄,用於組織和導覽網站的內容。在本文中,我們將討論使用 Bootstrap 建立和自訂導覽列的優點和缺點及其功能。 ...
    程式設計 發佈於2024-11-08
  • 將 WebSocket 與 Python 結合使用
    將 WebSocket 與 Python 結合使用
    什麼是 WebSocket? WebSocket 是一種支援瀏覽器和伺服器之間即時、雙向通訊的協定。傳統的 HTTP 通訊涉及客戶端發送請求和伺服器回應以交換資料。相較之下,使用 WebSocket,一旦建立了初始連接,客戶端和伺服器都可以相互發送和接收訊息,而無需重複建立新連接。...
    程式設計 發佈於2024-11-08
  • 如何在 PHP 中從子網域中提取網域?
    如何在 PHP 中從子網域中提取網域?
    在PHP 中從子域中提取域名在當代Web 開發中,必須解析和檢索域名,甚至是從子域中解析和檢索網域名稱。一個簡單的範例可能包括諸如“here.example.com”或“example.org”之類的網域。為了滿足這一需求,我們提出了一個全面的 PHP 函數,旨在從任何給定的輸入中提取根域名。 結合...
    程式設計 發佈於2024-11-08
  • 如何在多執行緒程式設計中連接向量以獲得最佳效率?
    如何在多執行緒程式設計中連接向量以獲得最佳效率?
    連結向量:深入分析在多執行緒程式設計中,合併結果是一個常見的挑戰。這通常涉及將多個向量組合成單一綜合向量。讓我們探索連接向量以獲得最大效率的最佳方法。 最佳連接方法為了高效的向量連接,最佳實踐是利用保留和插入方法:AB.reserve(A.size() B.size()); // Preallo...
    程式設計 發佈於2024-11-08
  • 如何優化FastAPI以實現高效的JSON資料回傳?
    如何優化FastAPI以實現高效的JSON資料回傳?
    FastAPI 傳回大型 JSON 資料的最佳化透過 FastAPI 傳回大量 JSON 資料集可能是一項耗時的任務。為了解決這個瓶頸,我們探索提高效能的替代方法。 識別瓶頸:使用 json.dumps 將 Parquet 檔案解析為 JSON 的初始方法( ) 和 json.loads() 效率低...
    程式設計 發佈於2024-11-08
  • React:狀態 X 派生狀態
    React:狀態 X 派生狀態
    什麼是派生狀態?考慮文字的一種狀態,然後考慮大寫文字的另一種狀態。 匯出狀態 function Foo() { const [text, setText] = useState('hello, za warudo!'); const [uppercaseText, ...
    程式設計 發佈於2024-11-08
  • 如何使用自訂使用者類型將 PostgreSQL JSON 欄位對應到 Hibernate 實體?
    如何使用自訂使用者類型將 PostgreSQL JSON 欄位對應到 Hibernate 實體?
    將 PostgreSQL JSON 欄位對應到 Hibernate 實體使用 PostgreSQL 資料庫時,常常會遇到以 JSON 格式儲存資料的資料列。為了使用 Hibernate 有效地將這些欄位對應到 Java 實體,選擇適當的資料類型至關重要。 在這種情況下,目前的問題圍繞著將 Postg...
    程式設計 發佈於2024-11-08
  • 確保整個團隊的 Node.js 版本一致
    確保整個團隊的 Node.js 版本一致
    .nvmrc 和 package.json 綜合指南 在現今動態的開發環境中,跨不同專案管理多個 Node.js 版本通常是一項複雜且容易出錯的任務。 Node.js 版本不一致可能會導致許多問題,從意外行為到應用程式完全失敗。 利用 .nvmrc 檔案進行版本控制 在專案中保持一...
    程式設計 發佈於2024-11-08
  • 何時在 JavaScript Promise 中使用 Promise.reject 與 Throw?
    何時在 JavaScript Promise 中使用 Promise.reject 與 Throw?
    JavaScript Promise:Reject 與Throw 之謎使用JavaScript Promise 時,開發人員經常面臨一個困境:他們是否應該使用Promise . reject 或者只是拋出一個錯誤?雖然這兩種方法具有相似的目的,但關於它們的差異和潛在優勢仍然存在混淆。 探索相似之處最...
    程式設計 發佈於2024-11-08
  • 建立 Chrome 擴充功能:快速概述
    建立 Chrome 擴充功能:快速概述
    模组——修改? 如果您喜欢游戏,您就会知道没有什么比玩模组游戏更好的了。这是您最喜欢的游戏,但具有额外的功能、功能和乐趣。现在,想象一下为您的网络浏览体验带来同样的兴奋。这正是浏览器扩展的作用——它们就像浏览器的模组,以您从未想过的方式增强浏览器的功能。 通过 Chrome 扩展程序,您可以调整浏览...
    程式設計 發佈於2024-11-08
  • 如何使用 CSS 設定表格列寬?
    如何使用 CSS 設定表格列寬?
    設定表格列寬表格通常用於呈現表格數據,但調整列寬對於確保可讀性和正確性至關重要結盟。在本文中,我們將探討如何使用 CSS 設定表格列的寬度。 使用 CSS 寬度屬性的方法表格列的寬度可以使用 col 元素的 width 屬性進行設定。寬度值可以以像素為單位指定(例如 width: 200px;),也...
    程式設計 發佈於2024-11-08
  • 如何從 Python 中的巢狀函數存取非局部變數?
    如何從 Python 中的巢狀函數存取非局部變數?
    存取嵌套函數作用域中的非局部變數在Python 中,嵌套函數作用域提供對封閉作用域的訪問。但是,嘗試修改巢狀函數內封閉範圍內的變數可能會導致 UnboundLocalError。 要解決此問題,您有多種選擇:1。使用 'nonlocal' 關鍵字 (Python 3 ):對於 Pyt...
    程式設計 發佈於2024-11-08
  • 使用 CSS 將漸層應用於文字。
    使用 CSS 將漸層應用於文字。
    文字漸變 現在你可以在很多地方看到像文字漸變這樣的好技巧......但是呢?你有沒有想過它們是如何製作的?今天就讓我來教你。 .text-gradient { background: linear-gradient(-25deg, #5662f6 0%, #7fffd4 10...
    程式設計 發佈於2024-11-08
  • 如何在Python中執行自訂區間舍入?
    如何在Python中執行自訂區間舍入?
    Python 中捨入為自訂間隔在 Python 中,內建 round() 函數通常用於對數值進行舍入。然而,它採用以 10 為基數的捨入方案,這可能並不總是適合特定要求。例如,如果您想將數字四捨五入到最接近的 5 倍數,則標準 round() 函數不合適。 要解決此問題,可以建立自訂函數,將數值四捨...
    程式設計 發佈於2024-11-08

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3