<a id="gettext"></a>

# GNU gettext PO (Portable Object)

<a id="index-0"></a>

翻譯自由軟體用得最廣泛的格式。

通過調整檔案頭或連結到相應的來源檔案，可以支援儲存在檔案中的情境資訊。

#### SEE ALSO
* [使用 GNU gettext 來翻譯軟體](https://docs.weblate.org/zh-tw/latest/devel/gettext.md)
* [使用 Sphinx 翻譯說明文件](https://docs.weblate.org/zh-tw/latest/devel/sphinx.md)
* [維基百科上的 Gettext 條目](https://en.wikipedia.org/wiki/Gettext)
* [PO Files](https://docs.translatehouse.org/projects/translate-toolkit/en/latest/formats/po.html)
* [更新「configure」檔案中的 ALL_LINGUAS 變數](https://docs.weblate.org/zh-tw/latest/admin/addons.md#addon-weblate-gettext-configure)
* [自訂 gettext 輸出](https://docs.weblate.org/zh-tw/latest/admin/addons.md#addon-weblate-gettext-customize)
* [更新 LINGUAS 檔案](https://docs.weblate.org/zh-tw/latest/admin/addons.md#addon-weblate-gettext-linguas)
* [產生 MO 檔案](https://docs.weblate.org/zh-tw/latest/admin/addons.md#addon-weblate-gettext-mo)
* [更新 PO 檔案以符合 POT (msgmerge)](https://docs.weblate.org/zh-tw/latest/admin/addons.md#addon-weblate-gettext-msgmerge)

## 顯示來源字串變更

如果 PO 檔案中包含先前的來源字串，Weblate 可以擷取這些字串，並以此顯示需要編輯之字串的差異。若要納入這些資訊，執行 **msgmerge** 時必須加上 `--previous` 引數；產生的 PO 檔案會包含如下的特殊資料列：

```po
#, fuzzy
#| msgid "previous-untranslated-string"
msgid "untranslated-string"
msgstr "translated-string"
```

這由 `po_keep_previous` [檔案格式參數](https://docs.weblate.org/zh-tw/latest/formats.md#file-format-params) 參數控制，不會影響以 `#~` 標示的過時項目。

## 過時字串

**msgmerge** 預設會將已從 POT 檔案移除的字串保留為過時的 `#~` 項目。啟用 `po_remove_obsolete` [檔案格式參數](https://docs.weblate.org/zh-tw/latest/formats.md#file-format-params) 參數，可在 Weblate 儲存 PO 檔案時移除過時項目。

## PO 檔案標頭

Weblate 會自動維護 PO 檔案的標頭。可使用 [檔案格式參數](https://docs.weblate.org/zh-tw/latest/formats.md#file-format-params) 將 `Language-Team`、`Last-Translator`、`X-Generator` 及 `Report-Msgid-Bugs-To` 標頭納入設定。

<a id="gettext-contributor-comments"></a>

### 貢獻者註解

使用 `po_contributor_comments` [檔案格式參數](https://docs.weblate.org/zh-tw/latest/formats.md#file-format-params)，將貢獻者名稱和年份加入 PO 標頭註解。選擇 `gettext` 可使用傳統註解，選擇 `spdx` 則會產生 SPDX 著作權項目。預設值 `none` 會停用貢獻者更新，但不會移除現有註解。此設定與 `Last-Translator` 標頭設定互不影響。

使用 `gettext` 時，貢獻者註解如下：

```po
# Jane Doe <jane@example.com>, 2024, 2026.
```

使用 `spdx` 時，同一筆項目會變成：

```po
# SPDX-FileCopyrightText: 2024, 2026 Jane Doe <jane@example.com>
```

符合資格的貢獻者下次提交時，SPDX 模式會將所有可辨識的貢獻者註解轉換為 SPDX 格式、保留過去的貢獻年份，並為該貢獻者加入當前年份。系統會略過匿名的 Weblate 作者。其他無關註解和著作權聲明會予以保留。Weblate 不會從譯文中的致謝名單推斷著作權主張，也不會加入專案專屬的聲明或授權識別碼；這些工作請使用自訂工具處理。

## 換行

換行方式大致符合 GNU gettext 的行為。GNU gettext 的換行演算法及其所依據的 Unicode 資料都會持續演進，因此少數情況下可能出現差異。

可以用 `po_line_wrap` 引數設定換行寬度，見 [檔案格式參數](https://docs.weblate.org/zh-tw/latest/formats.md#file-format-params)。

## 產生相符的 MO 檔案

如果 MO 與 PO 檔案一同保留在儲存庫中，可以使用 [產生 MO 檔案](https://docs.weblate.org/zh-tw/latest/admin/addons.md#addon-weblate-gettext-mo) 讓 MO 檔案與 PO 檔案保持同步。

## 從 POT 檔案更新 PO 檔案

可以用 [更新 PO 檔案以符合 POT (msgmerge)](https://docs.weblate.org/zh-tw/latest/admin/addons.md#addon-weblate-gettext-msgmerge) 從 POT 檔案更新 PO 檔案，見 [更新目標語言檔案](https://docs.weblate.org/zh-tw/latest/devel/integration.md#updating-target-files)。

<a id="mono-gettext"></a>

## 單語言 gettext

一些專案決定使用 gettext 作為單語言格式 —— 它們僅在原始碼中編碼 ID，然後將字串翻譯成所有語言，包括英語。支援此功能，儘管在將組件匯入 Weblate 時必須明確選擇此檔案格式。

## 範例檔案

雙語言 gettext PO 檔案通常如下所示：

```po
#: weblate/media/js/bootstrap-datepicker.js:1421
msgid "Monday"
msgstr "Pondělí"

#: weblate/media/js/bootstrap-datepicker.js:1421
msgid "Tuesday"
msgstr "Úterý"

#: weblate/accounts/avatar.py:163
msgctxt "No known user"
msgid "None"
msgstr "Žádný"
```

單語言的 gettext PO 檔案通常如下所示：

```po
#: weblate/media/js/bootstrap-datepicker.js:1421
msgid "day-monday"
msgstr "Pondělí"

#: weblate/media/js/bootstrap-datepicker.js:1421
msgid "day-tuesday"
msgstr "Úterý"

#: weblate/accounts/avatar.py:163
msgid "none-user"
msgstr "Žádný"
```

基本語言檔案將是：

```po
#: weblate/media/js/bootstrap-datepicker.js:1421
msgid "day-monday"
msgstr "Monday"

#: weblate/media/js/bootstrap-datepicker.js:1421
msgid "day-tuesday"
msgstr "Tuesday"

#: weblate/accounts/avatar.py:163
msgid "none-user"
msgstr "None"
```

<!-- AUTOGENERATED START: format-features po-mono -->
<!-- This section is automatically generated by `./manage.py list_format_features`. Do not edit manually. -->

#### 支援的功能

| 副檔名                                                                            | `.po`, `.pot`   |
|--------------------------------------------------------------------------------|-----------------|
| 語言能力 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#bimono)                   | 單語言             |
| 支援複數 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#format-plurals)           | `Yes`           |
| 支援描述 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#format-description)       | `Yes`           |
| 支援解釋 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#format-explanation)       | `No`            |
| 支援情境 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#format-context)           | `Yes`           |
| 支援位置 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#format-location)          | `Yes`           |
| 支援旗標 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#format-flags)             | `Yes`           |
| 額外狀態 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#format-states)            | `Needs editing` |
| API 辨識碼                                                                        | `po-mono`       |
| 支援唯讀字串 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#read-only-strings)      | `No`            |
| 支援移除已不再使用的字串 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#obsolete-strings) | `Yes`           |
<!-- AUTOGENERATED END: format-features po-mono -->
<!-- AUTOGENERATED START: format-features po -->
<!-- This section is automatically generated by `./manage.py list_format_features`. Do not edit manually. -->

#### 支援的功能

| 副檔名                                                                            | `.po`, `.pot`   |
|--------------------------------------------------------------------------------|-----------------|
| 語言能力 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#bimono)                   | 雙語言             |
| 支援複數 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#format-plurals)           | `Yes`           |
| 支援描述 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#format-description)       | `Yes`           |
| 支援解釋 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#format-explanation)       | `No`            |
| 支援情境 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#format-context)           | `Yes`           |
| 支援位置 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#format-location)          | `Yes`           |
| 支援旗標 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#format-flags)             | `Yes`           |
| 額外狀態 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#format-states)            | `Needs editing` |
| API 辨識碼                                                                        | `po`            |
| 支援唯讀字串 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#read-only-strings)      | `No`            |
| 支援移除已不再使用的字串 [ⓘ](https://docs.weblate.org/zh-tw/latest/formats.md#obsolete-strings) | `Yes`           |
<!-- AUTOGENERATED END: format-features po -->

## Weblate 設定

|           | 典型的 Weblate 雙語 gettext [組件設定](https://docs.weblate.org/zh-tw/latest/admin/projects.md#component)   |
|-----------|----------------------------------------------------------------------------------------|
| 檔案遮罩      | `po/*.po`                                                                              |
| 單語言基底語言檔案 | 空白                                                                                     |
| 新翻譯的範本    | `po/messages.pot`                                                                      |
| 檔案格式      | Gettext PO 檔案                                                                          |

|           | 典型的 Weblate 單語 gettext [組件設定](https://docs.weblate.org/zh-tw/latest/admin/projects.md#component)   |
|-----------|----------------------------------------------------------------------------------------|
| 檔案遮罩      | `po/*.po`                                                                              |
| 單語言基底語言檔案 | `po/en.po`                                                                             |
| 新翻譯的範本    | `po/messages.pot`                                                                      |
| 檔案格式      | Gettext PO 檔案（單語言）                                                                     |

## 檔案格式參數

po_\* 模式的 [檔案格式參數](https://docs.weblate.org/zh-tw/latest/formats.md#file-format-params) 可用來設定 gettext 格式的行為。
