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

# GNU gettext PO (Portable Object)

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

Most widely used format for translating libre software.

Contextual info stored in the file is supported by adjusting its
headers or linking to corresponding source files.

#### SEE ALSO
* [Translating software using GNU gettext](https://docs.weblate.org/no/latest/devel/gettext.md)
* [Translating documentation using Sphinx](https://docs.weblate.org/no/latest/devel/sphinx.md)
* [Gettext on Wikipedia](https://en.wikipedia.org/wiki/Gettext)
* [PO Files](https://docs.translatehouse.org/projects/translate-toolkit/en/latest/formats/po.html)
* [Update ALL_LINGUAS variable in the «configure» file](https://docs.weblate.org/no/latest/admin/addons.md#addon-weblate-gettext-configure)
* [Customize gettext output](https://docs.weblate.org/no/latest/admin/addons.md#addon-weblate-gettext-customize)
* [Update LINGUAS file](https://docs.weblate.org/no/latest/admin/addons.md#addon-weblate-gettext-linguas)
* [Generate MO files](https://docs.weblate.org/no/latest/admin/addons.md#addon-weblate-gettext-mo)
* [Update PO files to match POT (msgmerge)](https://docs.weblate.org/no/latest/admin/addons.md#addon-weblate-gettext-msgmerge)

## Showing source string change

Weblate can extract previous source strings from the PO files if present and
show the string difference for strings needing editing based on that. To
include these, **msgmerge** has to be executed with `--previous` and
the resulting PO file then contains lines such as:

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

This is controlled by the `po_keep_previous` [File format parameters](https://docs.weblate.org/no/latest/formats.md#file-format-params)
parameter. It does not affect obsolete entries marked with `#~`.

## Obsolete strings

**msgmerge** keeps strings removed from the POT file as obsolete `#~`
entries by default. Enable the `po_remove_obsolete` [File format parameters](https://docs.weblate.org/no/latest/formats.md#file-format-params)
parameter to remove obsolete entries when Weblate saves PO files.

## PO file header

The header of the PO file is automatically maintained by Weblate.
It can be configured to include the `Language-Team`, `Last-Translator`,
`X-Generator` and `Report-Msgid-Bugs-To` headers using the [File format parameters](https://docs.weblate.org/no/latest/formats.md#file-format-params).

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

### Contributor comments

Use the `po_contributor_comments` [File format parameters](https://docs.weblate.org/no/latest/formats.md#file-format-params) parameter to add
contributor names and years to PO header comments. Choose `gettext` for
traditional comments or `spdx` for SPDX copyright entries. The default,
`none`, disables contributor updates without removing existing comments.
This setting works independently of the `Last-Translator` header setting.

With `gettext`, contributor comments look like this:

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

With `spdx`, the same entry becomes:

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

On the next commit by an eligible contributor, SPDX mode converts all recognized
contributor comments, preserves historical contribution years, and adds the
current year for that contributor. Anonymous Weblate authors are skipped.
Unrelated comments and copyright notices are preserved. Weblate does not infer
copyright claims from translated credit strings or add project-specific notices
or license identifiers; handle these in custom tooling.

## Line wrapping

The line wrapping mostly matches GNU gettext behavior. Both the wrapping
algorithm in the GNU gettext and the Unicode data the wrapping is based on
evolve which might cause differences in some corner cases.

The wrapping width can be configured using the `po_line_wrap` parameter, see [File format parameters](https://docs.weblate.org/no/latest/formats.md#file-format-params).

## Generating matching MO files

In case MO files are kept in the repository together with PO files,
[Generate MO files](https://docs.weblate.org/no/latest/admin/addons.md#addon-weblate-gettext-mo) can be used to keep them up-to-date with PO
files.

## Updating PO files from the POT file

[Update PO files to match POT (msgmerge)](https://docs.weblate.org/no/latest/admin/addons.md#addon-weblate-gettext-msgmerge) can be used to update PO files from the
POT file, see [Updating target-language files](https://docs.weblate.org/no/latest/devel/integration.md#updating-target-files).

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

## Monolingual gettext

Some projects decide to use gettext as monolingual formats—they code just the IDs
in their source code and the string then needs to be translated to all languages,
including English. This is supported, though you have to choose
this file format explicitly when importing components into Weblate.

## Example files

The bilingual gettext PO file typically looks like this:

```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ý"
```

The monolingual gettext PO file typically looks like this:

```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ý"
```

While the base language file will be:

```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. -->

#### Supported features

| File extensions                                                                                      | `.po`, `.pot`   |
|------------------------------------------------------------------------------------------------------|-----------------|
| Linguality [ⓘ](https://docs.weblate.org/no/latest/formats.md#bimono)                                   | Monolingual     |
| Supports plural [ⓘ](https://docs.weblate.org/no/latest/formats.md#format-plurals)                      | `Yes`           |
| Supports descriptions [ⓘ](https://docs.weblate.org/no/latest/formats.md#format-description)            | `Yes`           |
| Supports explanation [ⓘ](https://docs.weblate.org/no/latest/formats.md#format-explanation)             | `No`            |
| Supports context [ⓘ](https://docs.weblate.org/no/latest/formats.md#format-context)                     | `Yes`           |
| Supports location [ⓘ](https://docs.weblate.org/no/latest/formats.md#format-location)                   | `Yes`           |
| Supports flags [ⓘ](https://docs.weblate.org/no/latest/formats.md#format-flags)                         | `Yes`           |
| Additional states [ⓘ](https://docs.weblate.org/no/latest/formats.md#format-states)                     | `Needs editing` |
| API identifier                                                                                       | `po-mono`       |
| Supports read-only strings [ⓘ](https://docs.weblate.org/no/latest/formats.md#read-only-strings)        | `No`            |
| Supports removing obsolete strings [ⓘ](https://docs.weblate.org/no/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. -->

#### Supported features

| File extensions                                                                                      | `.po`, `.pot`   |
|------------------------------------------------------------------------------------------------------|-----------------|
| Linguality [ⓘ](https://docs.weblate.org/no/latest/formats.md#bimono)                                   | Bilingual       |
| Supports plural [ⓘ](https://docs.weblate.org/no/latest/formats.md#format-plurals)                      | `Yes`           |
| Supports descriptions [ⓘ](https://docs.weblate.org/no/latest/formats.md#format-description)            | `Yes`           |
| Supports explanation [ⓘ](https://docs.weblate.org/no/latest/formats.md#format-explanation)             | `No`            |
| Supports context [ⓘ](https://docs.weblate.org/no/latest/formats.md#format-context)                     | `Yes`           |
| Supports location [ⓘ](https://docs.weblate.org/no/latest/formats.md#format-location)                   | `Yes`           |
| Supports flags [ⓘ](https://docs.weblate.org/no/latest/formats.md#format-flags)                         | `Yes`           |
| Additional states [ⓘ](https://docs.weblate.org/no/latest/formats.md#format-states)                     | `Needs editing` |
| API identifier                                                                                       | `po`            |
| Supports read-only strings [ⓘ](https://docs.weblate.org/no/latest/formats.md#read-only-strings)        | `No`            |
| Supports removing obsolete strings [ⓘ](https://docs.weblate.org/no/latest/formats.md#obsolete-strings) | `Yes`           |
<!-- AUTOGENERATED END: format-features po -->

## Weblate configuration

|                                | Typical Weblate [Component configuration](https://docs.weblate.org/no/latest/admin/projects.md#component) for bilingual gettext   |
|--------------------------------|--------------------------------------------------------------------------------------------------------------------------|
| File mask                      | `po/*.po`                                                                                                                |
| Monolingual base language file | Empty                                                                                                                    |
| Template for new translations  | `po/messages.pot`                                                                                                        |
| File format                    | Gettext PO file                                                                                                          |

|                                | Typical Weblate [Component configuration](https://docs.weblate.org/no/latest/admin/projects.md#component) for monolingual gettext   |
|--------------------------------|----------------------------------------------------------------------------------------------------------------------------|
| File mask                      | `po/*.po`                                                                                                                  |
| Monolingual base language file | `po/en.po`                                                                                                                 |
| Template for new translations  | `po/messages.pot`                                                                                                          |
| File format                    | Gettext PO file (monolingual)                                                                                              |

## File format parameters

[File format parameters](https://docs.weblate.org/no/latest/formats.md#file-format-params) with the pattern po_\* can be used to configure the behavior of the gettext format.
