During the last few weeks, I learned about internationalization in bash and did a lot of refactoring/decomposing of the UI code, making the code a lot more DRY.

…Internationalization…

This intro to Internationalization in Bash from the Linux Journal and this Slackware doc put me on the road to internationalizing the UI code I had written thus far.

Instead of hardcoding strings into the whiptail commands, like this:

I set up a Message Catalog in a Portable Object file for English: en.po. The .po file contains msgid-msgstr key-value pairs:

To make these .po files usable in a script, use the Linux utility msgfmt to turn .po files into Message Object files:

Now that we have a Message Object file, we can access the key value pairs in a script using the gettext command. Pass the name of the msgid as a string to get back the localized natural language string:

In order for this to work, though, it’s important to export some environmental variables before running gettext. Mine look like:

…Refactoring/Reorganizing…

gpg-helper-scripts/
├─ gpg/
│    ├─ create_keys.sh
├─ whiptail/
│    ├─ gen_keys.sh
│    ├─ smartcard_init.sh
│    ├─ whiptail_helper.sh
├─ po/
│    ├─ en.po
├─ locale/
│    ├─ en_US/LC_MESSAGES/ui-strings.mo
├─ details/
│    ├─ gpg-algos
│    ├─ smartcard-workflow
├─ init.sh


While setting up whiptail functions I learned that one does not simply return values in bash. With the help of another Linux Journal article, I came up with:

to store user input as variables while keeping the code DRY.

I also looked a little bit at Google’s Shell Style Guide, gave my files better names and organized the directory structure.

…GPG…

I was curious about the correct abbreviations, key lengths and usages for all of the gpg2.1.16 supported algorithms so I created a reference in details/gpg-algos that will come in handy for validating the user’s input for different types of keys.

…Moving Forward…

Now that the code is much more readable, I can think more about the UI and the options that I want to include:

Lots more options could be added here.. Let me know your ideas.