Is there a command to generate all .mo files from multiple .po files?

547 views Asked by At

I have multiple .po files in a standard directory structure of GNU gettext:

locales/
├── en_US
│   └── LC_MESSAGES
│       └── myapp.po
└── zh_TW
    └── LC_MESSAGES
        └── myapp.po

I knew that I could write a script that uses msgfmt to generate .mo files from these .po files. Something like:

# generate-mo-files.sh

for PO_FILE in locales/*/LC_MESSAGES/*.po
do
    MO_FILE="${PO_FILE/.po/.mo}"
    msgfmt -o "$MO_FILE" "$PO_FILE"
done

However, writing this script for each project I work on is a bit tedious. Is there a ready-made script for such use case?

1

There are 1 answers

0
Guido Flohr On

If you are using GNU autotools, you can use the script gettextize to prepare your project for gettext. Other build systems have similar special tools.

Otherwise, your little script is exactly the right solution.