Skip to content

Format all PO files with dprint #1359

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

Merged
merged 1 commit into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Install Gettext
run: |
sudo apt install gettext

- name: Install nightly rustfmt
run: |
rustup default nightly
Expand Down
43 changes: 20 additions & 23 deletions TRANSLATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ directory. The `.po` files are small text-based translation databases.
> such as [Poedit](https://poedit.net/). There are also several online editors
> available. This will ensure that the file is encoded correctly.

> **Important:** If you are planning to use [Poedit](https://poedit.net/) as
> suggested above, make sure to follow the
> [additional configuration steps](#Additional-Configuration-for-Poedit) below
> to ensure the `.po` file is correctly formatted.
> **Important:** You need to run `dprint fmt` after editing the PO file. This
> ensures consistent formatting of the file. You need to install the Gettext
> tools for this, see the Preparation section below.

There is a `.po` file for each language. They are named after the [ISO 639]
language codes: Danish would go into `po/da.po`, Korean would go into
Expand All @@ -32,25 +31,28 @@ GNU Gettext utilities below.

## Preparation

You will need the [Gettext] utilities (`msginit`, `msgmerge`). Under Debian and
Ubuntu, you can install with:
You will need the [Gettext] utilities (`msginit`, `msgmerge`) and [`dprint`].
Under Debian and Ubuntu, you can install Gettext with:

```shell
sudo apt install gettext
```

Install `dprint` using their installation instructions.

[dprint]: https://dprint.dev/

Ensure you can build the book, and that `mdbook serve` works. For this, follow
the instructions in the [README](README.md).

## Creating and Updating Translations

First, you need to know how to update the `.pot` and `.po` files.

As a general rule, you should never touch the auto-generated `po/messages.pot`
file. You should also not edit the `msgid` entries in a `po/xx.po` file. If you
find mistakes, you need to update the original English text instead. The fixes
to the English text will flow into the `.po` files the next time the translators
update them.
You should never touch the auto-generated `po/messages.pot` file. You should
also not never the `msgid` entries in a `po/xx.po` file. If you find mistakes,
you need to update the original English text instead. The fixes to the English
text will flow into the `.po` files the next time the translators update them.

> **Tip:** See our [style guide](STYLE.md) for some things to keep in mind when
> writing the translation.
Expand Down Expand Up @@ -134,20 +136,15 @@ will take care of escaping things like `"` correctly.
There are many PO editors available. [Poedit](https://poedit.net/) is a popular
cross-platform choice, but you can also find several online editors.

#### Additional Configuration for Poedit

If you are using [Poedit](https://poedit.net/) to work with your `.po` file, you
will need to change a few things from their default configuration:
If the file is not formatted correct, you will get an error on the PR. Install
[Gettext] and [`dprint`](https://dprint.dev/) and then run

1. Open the **Settings** dialog
1. On Windows, go to **File / Settings**
1. On MacOS, select **Settings** from the **Poedit** menu item
1. Go to the **Advanced** tab
1. On **Line endings**, select the option **Unix (recommended)**
1. Check the **Wrap at** box, and **79** on the textbox
1. _**Uncheck**_ the **Preserve formatting of existing files** box
```shell
dprint fmt
```

![Poedit Screenshot](poedit-screenshot.png)
This will automatically format the files for you. Commit the formatting fix and
push to your branch. Your PR should now be error free.

## Using Translations

Expand Down
3 changes: 3 additions & 0 deletions dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"commands": [{
"command": "rustfmt --edition 2021",
"exts": ["rs"]
}, {
"command": "msgcat -",
"exts": ["po"]
}]
},
"excludes": [
Expand Down
Loading