Archive for August, 2022

Translating Cinnamon desktop spices with help from machines

August 6, 2022

Linux Mint relies on its users to translate it. There are guides that teach you how the translation workflow, both for Mint itself, and for its optional Spices.
Unfortunately, as the translation tables show as of July 2022, Spices are mostly untranslated. This is probably because translating by hand can be time-consuming and tedious. So machine pre-translation can be a welcome aid in accelerating this. This tutorial will teach you how to use it. Remember that you still need to be fluent in the language you’re translating, because you must still manually check all translations. Still, this turns a ~1-week job into a ~2-hour job.

Steps:
1) Preparation: Follow the spices translation guide, up until the part where you create a new branch. The branch should be called something that clearly describes what you’re doing. I named mine lots-of-ro-translations because I was just adding a lot (all) of the Romanian translations. I advise you to use VS Code since I wrote this tutorial with it in mind.

2) Create .po files: Go to the root of the repository, in the Terminal. Run the following command (make sure to replace your_language_code with your own language’s code):

find . -name ".pot" -exec sh -c 'pot_file="{}"; base=$(basename "$pot_file" .pot); lang="your_language_code"; po_file="$lang.po"; if [ ! -e "${pot_file%/}/$po_file" ]; then msginit --no-translator -i "$pot_file" -o "${pot_file%/*}/$po_file" -l "$lang"; fi' \;

This will create a .po file in the same directory as each .pot file. Some .po files might already exist, so we skip them. After you’ve created all of the new .po files, you can commit them. The VS Code diff view is useful here. Use a message like “Create all .po files for [your language]”. It’s good to keep separate steps in your work in separate commits.

4) Installing required software: Install PHP 8.1 (instructions for Mint 20) and potrans. Potrans will do most of the magic for you. Make sure you install composer the way potrans advises you. Install also the PHP curl extension, as potrans advises. If you’ve used the PPA for installing PHP, install php-curl from the same PPA. Use apt show php-curl to make sure it’s the same one.

5) Get API key: Create a DeepL API account, use the free trial. Make sure it’s an API account because they also have a premium option for their website. Get the API key, for the next step.

6) Create and run the script: In the potrans directory, create a new bash script, with the following contents:

for file in /home/yourusername/spices/cinnamon-spices-desklets/*/files/*/po/yourlanguagecode.po; 
do 
bin/potrans deepl  "$file" "$(dirname "${file}")"  --to=yourlanguagecode --apikey=yourapikey;
done

Make sure that you replace desklets with the directory you’re working on, as well as replacing your username, your language code, and your API key.

Run this bash script in the terminal. Sit back and watch the progress bars. You can also look at the usage tab of your DeepL account to check if you’re getting anywhere near the usage limit (you probably aren’t). Check the diff in VS Code and commit the changed .po files, with a message like “Run the translation script”.

7) Check and fix translations by hand: This part took the longest, in my experience (about 2h, also depends on how much is already translated). I advise you to use VS Code and just filter the files for your language. With the project open, search all files (Ctrl+Shift+F) for a string you can only find in your language’s files. For example, searching for the string “Language: ro” will only show the ro.po files. I couldn’t find another better way to filter the files. Go through each result. Look through the entire file for each. Fix any errors in the machine translation. For example, make sure the level of formality is consistent, and make sure the vocabulary used is consistent (for example, either always translate the word “desktop” or never do it). You can be smart about it by using global search and replace (Ctrl+Shift+H) to fix all instances of a mistake in all files at once. Once you’ve checked all the files, commit your changes.

8) Make the PR: You can now make the Pull Request, as instructed in the original tutorial. Then wait for it to get accepted & merged.

That’s it! Good job, you’ve made a big contribution to the Linux Mint project.