Commit 6591faf2 authored by Benoit Mortier's avatar Benoit Mortier

Merge branch '11-create-a-script-to-allow-localization-of-external-themes' into 'master'

Resolve "create a script to allow localization of external themes"

Closes #11

See merge request fusiondirectory/dev-tools!12
parents d273a9cf 70b21c4e
#!/bin/sh
set -x
generate_po() {
ORIG=`pwd`
TEMPDIR="/tmp/fusiondirectory-locale"
TRUE=`which true`
PATHDIR=$(cd `dirname "$0"` && pwd)
LOCALE_DIR="locale"
BASIC_LANG="en"
php "$PATHDIR/tsmarty2c.php" || exit $?;
echo
echo "Creating temporary directory..."
[ -d "$TEMPDIR" ] && rm -rf "$TEMPDIR"
mkdir "$TEMPDIR"
echo "Creating copy of FusionDirectory..."
tar c . | tar x -C "$TEMPDIR"
echo "Converting .tpl files..."
cd "$TEMPDIR"
for template in $(find . -name '*.tpl'); do
echo "* converting .tpl files: $(basename $template)"
php "$PATHDIR/tsmarty2c.php" $template > $template.c
done
echo "Extracting languages into fusiondirectory.po ..."
if [ ! -d "$TEMPDIR/$LOCALE_DIR" ]; then
# Control will enter here if $TEMPDIR/$LOCALE_DIR doesn't exist.
mkdir -p "$TEMPDIR/$LOCALE_DIR"
fi
[ -f "$LOCALE_DIR/$BASIC_LANG/fusiondirectory.po" ] && rm "$LOCALE_DIR/$BASIC_LANG/fusiondirectory.po"
touch $LOCALE_DIR/$BASIC_LANG/fusiondirectory.po
find . -name '*.c' | xgettext -f - --keyword=must --from-code="UTF-8" --copyright-holder="FusionDirectory Project" --package-name=$package --package-version=$version --msgid-bugs-address="bugs@fusiondirectory.org" -d fusiondirectory -L C -n -j -o $LOCALE_DIR/$BASIC_LANG/fusiondirectory.po || exit "$?";
sed --in-place "$LOCALE_DIR/$BASIC_LANG/fusiondirectory.po" --expression="s/nplurals=INTEGER/nplurals=2/"
sed --in-place "$LOCALE_DIR/$BASIC_LANG/fusiondirectory.po" --expression="s/plural=EXPRESSION/plural=(n != 1)/"
sed --in-place "$LOCALE_DIR/$BASIC_LANG/fusiondirectory.po" --expression="s/Last-Translator: .*\"/Last-Translator: FusionDirectory project <contact@fusiondirectory.org>\\\n\"/"
sed --in-place "$LOCALE_DIR/$BASIC_LANG/fusiondirectory.po" --expression="s/Language-Team: .*\"/Language-Team: English\\\n\"/"
sed --in-place "$LOCALE_DIR/$BASIC_LANG/fusiondirectory.po" --expression="s/Language: .*\"/Language: en\\\n\"/"
if [ ! -d "$ORIG/$LOCALE_DIR/$BASIC_LANG" ]; then
# Control will enter here if $ORIG/$LOCALE_DIR/$BASIC_LANG doesn't exist.
mkdir -p "$ORIG/$LOCALE_DIR/$BASIC_LANG"
fi
cp "$TEMPDIR/$LOCALE_DIR/$BASIC_LANG/fusiondirectory.po" "$ORIG/$LOCALE_DIR/$BASIC_LANG/fusiondirectory.po"
}
clean_po() {
ORIG=`pwd`
PO="fusiondirectory.po"
LOCALE_DIR="locale"
cd $ORIG
for f in `ls -1 | grep -v .md`; do
[ -f "$f/$LOCALE_DIR/$PO" ] && rm `ls "$f/$LOCALE_DIR/$PO"`
done
}
#
# MAIN
#
package="FusionDirectory";
version="VERSION";
while getopts "p:v:gch" opt
do
case $opt in
p) package=$OPTARG;
;;
v) version=$OPTARG;
;;
g) generate_po;
;;
c) clean_po;
;;
\?|h|--help)
echo "Usage: $(basename $0) [-p package] [-v version] [-gch]"
echo "-p package to set in .po headers"
echo "-v version to set in .po headers"
echo "-g generate po source files"
echo "-c clean generated po sourcefiles"
echo "-h this help"
exit 1
;;
esac
done
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment