Last active
March 19, 2018 17:37
-
-
Save aubreypwd/531ec618046ef0f28bbd91fe1683651e to your computer and use it in GitHub Desktop.
Programmatically (from the command line) convert a folder of .po files to .mo files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/sh/bin | |
### | |
# PO 2 MO files conversion. | |
# | |
# @since Monday, March 19, 2018 | |
## | |
function po2mo { | |
if ! [ -x "$(command -v msgfmt)" ]; then | |
echo "Please run: brew install gettext" && return | |
fi | |
if ! [ -x "$(command -v dos2unix)" ]; then | |
echo "Please run: brew install dos2unix" && return | |
fi | |
help="Usage: cd into folder; then run po2mo"; | |
if [ '--help' == "$1" ]; then | |
echo "$help" && return | |
fi | |
# Clean BOM from .po files: https://unix.stackexchange.com/questions/381230/how-can-i-remove-the-bom-from-a-utf-8-file. | |
for f in *.po; do | |
dos2unix "$f" &>/dev/null | |
done | |
# Convert .po to .mo... | |
find . -name \*.po -execdir sh -c 'msgfmt "$0" -o `basename $0 .po`.mo' '{}' \; | |
echo "Done!" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment