Skip to content

Instantly share code, notes, and snippets.

@raspi
Created July 1, 2014 17:03
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save raspi/f3bb3ea92d6e4a108f1f to your computer and use it in GitHub Desktop.
Save raspi/f3bb3ea92d6e4a108f1f to your computer and use it in GitHub Desktop.
Shell script for updating Gettext .po files in a PHP project. Create new languages simply by copying base.pot to <language code>.po. For example: cp base.pot fi.po. Then just edit fi.po with poedit or some other editor.
#!/bin/bash -e
# generate file list
echo -e "" > files.txt
find ../application -type f \( -iname "*.php" -or -iname "*.phtml" \) -exec readlink -f "{}" \; > files.txt
# scan files
xgettext --force-po --add-comments --from-code=UTF-8 --language=php --package-name=app --package-version=1.0 --msgid-bugs-address=noreply@example.com -o base.pot -f files.txt
# base pot -> <lang>.po update
find . -type f -iname "*.po" -exec bash -c 'msgmerge --update "{}" base.pot' \;
# compile .po to .mo
find . -type f -iname "*.po" -exec bash -c 'msgfmt "{}" -o "$(basename "{}" .po).mo"' \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment