Commit 8f09f0b9 authored by Benoit Mortier's avatar Benoit Mortier

Merge branch '7-adding-locales-generation-scripts-from-management-tools' into 'master'

Resolve "Adding locales generation scripts from management-tools"

Closes #7

See merge request !6
parents f44a8cb8 cd0161c5
#!/bin/sh
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
for template in $(find . -name '*.xml'); do
echo "* converting .xml files: $(basename $template)"
sed -e 's/<label>/<?php $t= _("/g;s!</label>!");?>!g' $template > $template.new
mv $template.new $template
done
for class in $(find . -name 'class_*.inc'); do
echo "* converting class_*.inc files: $(basename $class)"
sed -e 's/\($pl[DH][^=]*\)= *"\([^"]*\)";$/\1= _("\2");/g' $class > $class.new
mv $class.new $class
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"
find . -name '*.[ctpix][mophn][nlpc]' | xgettext -f - --keyword=must --copyright-holder="FusionDirectory Project" --package-name=$package --package-version=$version --msgid-bugs-address="bugs@fusiondirectory.org" -d fusiondirectory -L PHP -n -o $LOCALE_DIR/$BASIC_LANG/fusiondirectory.po || exit "$?";
# If no .po got generated, exit method now
[ -f "$LOCALE_DIR/$BASIC_LANG/fusiondirectory.po" ] || return;
sed --in-place "$LOCALE_DIR/$BASIC_LANG/fusiondirectory.po" --expression="s/CHARSET/UTF-8/"
find . -name '*.c' | xgettext -f - --keyword=must --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
#!/bin/sh
SRC_DIR="/home/bmortier/develop/projects/fusiondirectory/"
TOOL_DIR="/home/bmortier/scripts/fusiondirectory-update-locale"
PLUGIN_DIR="fusiondirectory-plugins"
CORE_DIR="fusiondirectory"
CONTRIB_DIR="contrib/bin"
## DONT CHANGE ANYTHING AFTER THIS LINE ##
echo 'this will update the locales of all the plugins situated in '$SRC_DIR/$PLUGIN_DIR
cd $SRC_DIR/$PLUGIN_DIR/
for locale in `ls -1 | grep -v README.md | grep -v CODE_OF_CONDUCT.md | grep -v CONTRIBUTING.md | grep -v LICENSE`; do
cd $locale;
sh $TOOL_DIR -g || exit "$?";
cd ..;
done
#!/usr/bin/env php
<?php
/**
* tsmarty2c.php - rips gettext strings from smarty template
*
* ------------------------------------------------------------------------- *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
* ------------------------------------------------------------------------- *
*
* This command line script rips gettext strings from smarty file,
* and prints them to stdout in C format, that can later be used with the
* standard gettext tools.
*
* Usage:
* ./tsmarty2c.php <filename or directory> <file2> <..> > smarty.c
*
* If a parameter is a directory, the template files within will be parsed.
*
* @package smarty-gettext
* @version $Id: tsmarty2c.php,v 1.3 2005/07/27 17:59:39 sagi Exp $
* @link http://smarty-gettext.sf.net/
* @author Sagi Bashari <sagi@boom.org.il>
* @copyright 2004-2005 Sagi Bashari
*/
// smarty open tag
$ldq = preg_quote('{');
// smarty close tag
$rdq = preg_quote('}');
// smarty command
$cmd = preg_quote('t');
// extensions of smarty files, used when going through a directory
$extensions = array('tpl');
// "fix" string - strip slashes, escape and convert new lines to \n
function fs($str)
{
$str = stripslashes($str);
$str = str_replace('"', '\"', $str);
$str = str_replace("\n", '\n', $str);
return $str;
}
// rips gettext strings from $file and prints them in C format
function do_file($file)
{
$content = @file_get_contents($file);
if (empty($content)) {
return;
}
global $ldq, $rdq, $cmd;
preg_match_all(
"/{$ldq}\s*({$cmd})\s*([^{$rdq}]*){$rdq}([^{$ldq}]*){$ldq}\/\\1{$rdq}/",
$content,
$matches
);
for ($i=0; $i < count($matches[0]); $i++) {
// TODO: add line number
echo "/* $file */\n"; // credit: Mike van Lammeren 2005-02-14
if (preg_match('/plural\s*=\s*["\']?\s*(.[^\"\']*)\s*["\']?/', $matches[2][$i], $match)) {
echo 'ngettext("'.fs($matches[3][$i]).'","'.fs($match[1]).'",x);'."\n";
} else {
echo 'gettext("'.fs($matches[3][$i]).'");'."\n";
}
echo "\n";
}
}
// go through a directory
function do_dir($dir)
{
$d = dir($dir);
while (false !== ($entry = $d->read())) {
if ($entry == '.' || $entry == '..') {
continue;
}
$entry = $dir.'/'.$entry;
if (is_dir($entry)) { // if a directory, go through it
do_dir($entry);
} else { // if file, parse only if extension is matched
$pi = pathinfo($entry);
if (isset($pi['extension']) && in_array($pi['extension'], $GLOBALS['extensions'])) {
do_file($entry);
}
}
}
$d->close();
}
for ($ac=1; $ac < $_SERVER['argc']; $ac++) {
if (is_dir($_SERVER['argv'][$ac])) { // go through directory
do_dir($_SERVER['argv'][$ac]);
} else { // do file
do_file($_SERVER['argv'][$ac]);
}
}
?>
#!/bin/bash
if [ -z "$1" ]; then
echo "usage: $0 fusiondirectory version\n"
echo " ex: FusionDirectory-107\n"
exit
fi
FD_VERSION=$1
for resource in `ls -1 | grep -v .md`; do
tx set --auto-local -r $FD_VERSION.$resource $resource/'locale/<lang>/fusiondirectory.po' \
--source-lang en \
--source-file $resource'/locale/en/fusiondirectory.po' --execute
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