Recipes¶
linting all your PO files¶
Sometimes it’s good to just get a look at all the PO files and make sure they’re ok:
$ dennis-cmd lint locale/
It’ll give you a summary at the end.
linting your POT file¶
Linting your POT file can reduce the number of issues that translators will stumble over. It’s good to lint it before you push new strings to translate:
$ dennis-cmd lint locale/templates/LC_MESSAGES/messages.pot
translate PO file to find problems with localization¶
Use the Dennis translator to find l10n issues in your application without having to bother your translators.
For example, this translates strings into Pirate for a web application written in Python:
1#!/bin/bash
2
3mkdir -p locale/xx/LC_MESSAGES
4cp locale/templates/LC_MESSAGES/messages.pot \
5 locale/xx/LC_MESSAGES/messages.po
6
7dennis-cmd translate \
8 --pipeline=html,pirate \
9 --varsformat=python-format,python-brace-format \
10 locale/xx/LC_MESSAGES/messages.po
Now view your application with the xx
locale and behold it’s
Piratey wonderfulness!
There are a variety of transforms which have different properties and suss out different kinds of localization problems.
selective MO compiling¶
The Dennis linter returns an exit code of 1 if the file(s) it’s linting have errors. You can trivially use this to selectively compile PO files into MO files iff they are error free [1]:
1#!/bin/bash
2
3for pofile in `find locale/ -name "*.po"`
4do
5 dir=`dirname "$pofile"`
6 stem=`basename "$pofile" .po`
7
8 dennis-cmd lint --errorsonly "$pofile"
9 if [ $? -ne 0 ]
10 then
11 echo "ERRORZ!!! Not compiling $pofile!"
12
13 else
14 msgfmt -o "${dir}/${stem}.mo" "$pofile"
15 fi
16done
commit-msg git hook¶
You can automatically translate all future commit messages for your
git project by creating a commit-msg
hook like this:
1#!/bin/bash
2
3# Pipe the contents of the commit message file through dennis to
4# a temp file, then copy it back.
5(cat < $1 | dennis-cmd translate - > $1.tmp) && mv $1.tmp $1
6
7# We always exit 0 even if the dennis-cmd fails. If the dennis-cmd
8# fails, you get your original commit message. No one likes it when
9# shenanigans break your stuff for realz.
10exit 0;
convert your web page into Pirate for April fools day¶
The Dennis translator can take content from stdin. Translate entire HTML pages:
1#!/bin/bash
2
3(cat < "$1" | dennis-cmd translate --pipeline=html,pirate -) > "pirate_$1"
Or show how you really feel about April fools day on the Internet:
#!/bin/bash
(cat < "$1" | dennis-cmd translate --pipeline=html,haha -) > "haha_$1"