Skip to content

Instantly share code, notes, and snippets.

@manuelcanga
Last active February 26, 2022 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manuelcanga/dae7fe922c1b70d6205736239cb6ee7a to your computer and use it in GitHub Desktop.
Save manuelcanga/dae7fe922c1b70d6205736239cb6ee7a to your computer and use it in GitHub Desktop.
Searching and creating gettext entries
APP_ROOT=$1
if [ $# == 2 ]
then
echo "error: app path?"
fi
echo "1.Creating smarty.php in $APP_ROOT"
echo "<?php" >$APP_ROOT/smarty.php
grep -hoie "{t}.*{/t}" $APP_ROOT/* -R|sed "s/{t}/echo _\(\'/g"|sed "s/{\/t}/\'\);/g"|grep -hoiE "_\('.+'\)" >>$APP_ROOT/smarty.php
echo -e "\n?>" >>$APP_ROOT/smarty.php
echo "2.Creating javascript.php in $APP_ROOT"
echo "<?php" >$APP_ROOT/_javascript.php
find . -iname "*.js" -exec grep -hoiE "_\('.+'\)" {} >>$APP_ROOT/_javascript.php \;
echo -e "\n?>" >>$APP_ROOT/_javascript.php
sed -e "s/^_/echo\ _/g" $APP_ROOT/_javascript.php > $APP_ROOT/javascript.php
rm _javascript.php
echo "3.Creating messages.po from app \( $APP_ROOT \) "
$(rm messages.po 2>/dev/null)
touch messages.po
find $APP_ROOT -iname "*.php" -exec xgettext {} -j --from-code=iso-8859-1 \;
rm $APP_ROOT/smarty.php
rm $APP_ROOT/javascript.php
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment