Commit e16e05ae authored by Piotr Szotkowski's avatar Piotr Szotkowski

utils for cross-version POT files

parent 432ea72e
#!/bin/bash
[ -z "$1" ] && echo 'locale missing' && exit 1
echo "adding $1 locale"
pots=`for pot in po/pot/*.pot; do basename $pot .pot; done`
mkdir -p po/$1
for pot in $pots; do
msginit -i po/pot/$pot.pot -o po/$1/$pot.po -l $1 --no-translator
done
ACL
Activity
Block
common
Contact
Core
Custom
Dashlet
Dedupe
Export
Form
Friend
Group
Import
Note
Price
Profile
Relationship
SMS
Standalone
Tag
UF
Upgrade
Utils
#!/bin/bash
[ -z "$1" ] || [ ! -d "$1" ] || [ -z "$2" ] || [ ! -d "$2" ] || [ -z "$3" ] && echo "usage: $0 CiviCRM-dir POT-dir releases" && exit 1
[ -n "$4" ] && echo 'provide releases as one, space-separated string' && exit 1
root="$1"
potdir="$2"
rels=`echo "$3" | tr ' ' '\n'`
temp=`mktemp -d`
for rel in $rels; do
mkdir -p $temp/$rel
mkdir -p $temp/pot/$rel
pushd .
cd $root
git archive $rel | tar -xC $temp/$rel
mkdir $temp/$rel/xml/default
echo '<?php define("CIVICRM_CONFDIR", ".");' > $temp/$rel/settings_location.php
echo '<?php define("CIVICRM_UF", "Drupal");' > $temp/$rel/xml/default/civicrm.settings.php
cd $temp/$rel/xml
php GenCode.php schema/Schema.xml
popd
bin/create-pot-files.sh $temp/$rel $temp/pot/$rel
done
pots=`for pot in $temp/pot/*/*.pot; do basename $pot .pot; done | sort -u | grep -v ^drupal-civicrm$`
# merge per-release files into unified ones
for pot in $pots; do
echo " * merging $pot.pot files"
msgcat --no-wrap --use-first $temp/pot/*/$pot.pot > $potdir/$pot.pot
done
# drop strings in common-base.pot from other files
for pot in $pots; do
[ $pot == 'common-base' ] && continue
echo " * dropping common-base strings from $pot.pot"
common=`tempfile`
msgcomm $potdir/$pot.pot $potdir/common-base.pot > $common
msgcomm --no-wrap --unique $potdir/$pot.pot $common | sponge $potdir/$pot.pot
rm $common
done
# drop strings in common-components.pot from other files
for pot in $pots; do
[ $pot == 'common-base' ] && continue
[ $pot == 'common-components' ] && continue
echo " * dropping common-components strings from $pot.pot"
common=`tempfile`
msgcomm $potdir/$pot.pot $potdir/common-components.pot > $common
msgcomm --no-wrap --unique $potdir/$pot.pot $common | sponge $potdir/$pot.pot
rm $common
done
rm -r $temp
#!/bin/bash
langs=`ls -1d po/?? po/??_?? | cut -d/ -f2`
for lang in $langs; do
echo "compiling $lang"
msgcat --use-first po/$lang/*.po | msgfmt -o po/$lang/civicrm.mo -
done
#!/bin/bash
[ "$1" == "" ] && echo 'source dir missing' && exit 1
test ! -e "$1" && echo 'source does not exist' && exit 1
test ! -d "$1" && echo 'source not a directory' && exit 1
[ "$2" == "" ] && echo 'target dir missing' && exit 1
test ! -e "$2" && echo 'target does not exist' && exit 1
test ! -d "$2" && echo 'target not a directory' && exit 1
root="$1"
potdir="$2"
header=`tempfile`
now=`date +'%F %R%z'`
sed "s/NOW/$now/" bin/header > $header
# $componets are the dirs with strings generating per-component $component.po files
components=`ls -1 $root/CRM $root/templates/CRM | grep -v :$ | grep -v ^$ | grep -viFf bin/basedirs | sort -u | xargs | tr [A-Z] [a-z]`
# build the three XML-originating files
echo ' * building menu.pot'
cp $header $potdir/menu.pot
grep -h '<title>' $root/CRM/*/xml/Menu/*.xml | sed 's/^.*<title>\(.*\)<\/title>.*$/\1/' | while read entry; do echo -e "msgctxt \"menu\"\nmsgid \"$entry\"\nmsgstr \"\"\n"; done >> $potdir/menu.pot
`dirname $0`/smarty-extractor.php $root $root/xml/templates/civicrm_navigation.tpl | grep '^msgid "' | sed 's/^msgid "\(.*\)"$/\1/' | while read entry; do echo -e "msgctxt \"menu\"\nmsgid \"$entry\"\nmsgstr \"\"\n"; done >> $potdir/menu.pot
msguniq $potdir/menu.pot | sponge $potdir/menu.pot
echo ' * building countries.pot'
cp $header $potdir/countries.pot
grep ^INSERT $root/xml/templates/civicrm_country.tpl | cut -d\" -f4 | while read entry; do echo -e "msgctxt \"country\"\nmsgid \"$entry\"\nmsgstr \"\"\n"; done >> $potdir/countries.pot
echo ' * building provinces.pot'
cp $header $potdir/provinces.pot
grep '^(' $root/xml/templates/civicrm_state_province.tpl | cut -d\" -f4 | while read entry; do echo -e "msgctxt \"province\"\nmsgid \"$entry\"\nmsgstr \"\"\n"; done >> $potdir/provinces.pot
# make sure none of the province names repeat
# FIXME: add country name to context and skip this to do the Right Thing™
msguniq $potdir/provinces.pot | sponge $potdir/provinces.pot
# create base POT file
echo ' * building common-base.pot'
cp $header $potdir/common-base.pot
`dirname $0`/extractor.php base $root >> $potdir/common-base.pot
msguniq $potdir/common-base.pot | sponge $potdir/common-base.pot
msgattrib --no-wrap $potdir/common-base.pot | sponge $potdir/common-base.pot
# create component POT files
for comp in $components; do
echo ' * building '$comp'.pot'
cp $header $potdir/$comp.pot
`dirname $0`/extractor.php $comp $root >> $potdir/$comp.pot
# drop strings already present in common-base.pot
common=`tempfile`
msgcomm $potdir/$comp.pot $potdir/common-base.pot > $common
msgcomm --unique $potdir/$comp.pot $common | sponge $potdir/$comp.pot
rm $common
done
# create common-components.pot with strings common to all components (but not base)
paths=''
for comp in $components; do
paths="$paths $potdir/$comp.pot"
done
echo ' * building common-components.pot'
msgcomm --no-wrap $paths > $potdir/common-components.pot
# drop strings in common-components.pot from component POT files
for comp in $components; do
common=`tempfile`
msgcomm $potdir/$comp.pot $potdir/common-components.pot > $common
msgcomm --no-wrap --unique $potdir/$comp.pot $common | sponge $potdir/$comp.pot
rm $common
done
# drop empty files
find $potdir -empty -exec rm {} \;
# create drupal-civicrm.pot
echo ' * building drupal-civicrm.pot'
cp $header $potdir/drupal-civicrm.pot
find $root/drupal -name '*.inc' -or -name '*.install' -or -name '*.module' -or -name '*.php' | xargs `dirname $0`/php-extractor.php $root $root/CRM/Core/Permission.php >> $potdir/drupal-civicrm.pot
rm $header
#!/usr/bin/php
<?php
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
/*
+--------------------------------------------------------------------+
| CiviCRM version 2.2 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2010 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007. |
| |
| CiviCRM 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 Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License along with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2010
* $Id$
*
*/
/**
* ts() and {ts} calls extractor
*
* Extracts translatable strings from CiviCRM PHP source (ts() calls) and
* Smarty templates ({ts} calls). Outputs a POT file on STDOUT, errors on
* STDERR.
*/
$phpModifier = "-iname '*.php' ";
$smartyModifier = "\( -iname '*.tpl' -or -iname '*.hlp' \) ";
if ($argv[1] == 'base') {
$phpDir = array();
$tplDir = array();
foreach (explode("\n", file_get_contents('bin/basedirs')) as $dir) {
$phpDir[] = "-iwholename '*/CRM/$dir/*'";
$tplDir[] = "-iwholename '*/templates/CRM/$dir/*'";
}
$phpModifier .= "\( " . implode(' -or ', $phpDir) . " \)";
$smartyModifier .= "\( " . implode(' -or ', $tplDir) . " \)";
} else {
$phpModifier .= "-iwholename '*/CRM/{$argv[1]}/*'";
$smartyModifier .= "-iwholename '*/templates/CRM/{$argv[1]}/*'";
}
$phpExtractor = dirname(__FILE__) . '/php-extractor.php';
$smartyExtractor = dirname(__FILE__) . '/smarty-extractor.php';
$dir = $argv[2];
$command = "find $dir/CRM $dir/packages/HTML/QuickForm $phpModifier -not -wholename '*/CRM/Core/I18n.php' -not -wholename '*/CRM/Core/Smarty/plugins/block.ts.php' | grep -v '/\.svn/' | sort | xargs $phpExtractor $dir";
$phpPot = `$command`;
$command = "find $dir/templates $dir/xml $smartyModifier | grep -v '/\.svn/' | sort | xargs $smartyExtractor $dir";
$smartyPot = `$command`;
$originalArray = explode("\n", $phpPot . $smartyPot);
$block = array();
$blocks = array();
$msgidArray = array();
$resultArray = array();
// rewrite the header to resultArray, removing it from the original
while ($originalArray[0] != '') {
$resultArray[] = array_shift($originalArray);
}
$resultArray[] = array_shift($originalArray);
// break the POT contents into separate comments/msgid blocks
foreach ($originalArray as $line) {
// if it's the end of a block, put the $block in $blocks and start a new one
if ($line == '' and $block != array()) {
$blocks[] = $block;
$block = array();
// else add the line to the proper $block part
} else {
// the lines in the POT file are either comments, single- and multiline
// msgids or empty msgstrs; we ignore the msgstrs
if (substr($line, 0, 1) == '#') {
$block['comments'][] = $line;
} elseif (substr($line, 0, 6) != 'msgstr') {
$block['msgid'][] = $line;
}
}
}
// combine the msgid parts into single strings and build a new array with msgid
// as key and arrays with comments as value; drop the empty msgids
foreach ($blocks as $block) {
$msgid = implode("\n", $block['msgid']);
if ($msgid != 'msgid ""') {
foreach ($block['comments'] as $comment) {
$msgidArray[$msgid][] = $comment;
}
}
}
// combine the comments indicating the source files into single comment lines
foreach ($msgidArray as $msgid => $commentsArray) {
$newCommentsArray = array();
$sourceComments = array();
foreach ($commentsArray as $comment) {
if (substr($comment, 0, 3) == '#: ') {
$sourceComments[] = substr($comment, 3);
} else {
$newCommentsArray[] = $comment;
}
}
if (count($sourceComments)) {
$newCommentsArray[] = '#: ' . implode(' ', $sourceComments);
}
$msgidArray[$msgid] = $newCommentsArray;
}
// build the rest of the $resultArray from the $msgidArray
foreach ($msgidArray as $msgid => $commentsArray) {
foreach ($commentsArray as $comment) {
$resultArray[] = $comment;
}
$resultArray[] = $msgid;
// if it's a plural, add plural msgstr, else add singular
if (strpos($msgid, "\nmsgid_plural ")) {
$resultArray[] = "msgstr[0] \"\"\nmsgstr[1] \"\"\n";
} else {
$resultArray[] = "msgstr \"\"\n";
}
}
// output the $resultArray to STDOUT
fwrite(STDOUT, implode("\n", $resultArray));
# Copyright CiviCRM LLC (c) 2004-2011
# This file is distributed under the same license as the CiviCRM package.
# If you contribute heavily to a translation and deem your work copyrightable,
# make sure you license it to CiviCRM LLC under Academic Free License 3.0.
msgid ""
msgstr ""
"Project-Id-Version: CiviCRM\n"
"POT-Creation-Date: NOW\n"
"Language-Team: CiviCRM Translators <civicrm-translators@lists.civicrm.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
This diff is collapsed.
#!/bin/bash
langs=`ls -1d po/?? po/??_?? | cut -d/ -f2`
pots=`for pot in po/pot/*.pot; do basename $pot .pot; done`
for lang in $langs; do
echo; echo $lang
for pot in $pots; do
msgmerge --no-wrap --unique po/$lang/$pot.po po/pot/$pot.pot
done
done
#!/usr/bin/php
<?php
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
/**
* smarty-extractor.php - rips gettext strings from Smarty {ts} calls
*
* ------------------------------------------------------------------------- *
* 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; this can later be used with the standard gettext tools.
*
* Usage:
* ./smarty-extractor.php <filename or directory> [file2, ...]
*
* If a parameter is a directory, the template files within will be parsed.
*
* @version $Id$
* @link http://smarty-gettext.sf.net/
* @author Sagi Bashari <sagi@boom.org.il>
* @author Piotr Szotkowski <shot@civicrm.org>
* @copyright 2004 Sagi Bashari
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
*/
$root = $_SERVER['argv'][1];
array_splice($_SERVER['argv'], 1, 1);
// smarty open tag
$ldq = preg_quote('{');
// smarty close tag
$rdq = preg_quote('}');
// smarty command
$cmd = preg_quote('ts');
// 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, $root;
// if there’s a {php} tag, fetch its contents into a file and parse it with php-extractor.php
$phpTagMatches = array();
preg_match_all("/{$ldq}\s*(php)\s*([^{$rdq}]*){$rdq}([^{$ldq}]*){$ldq}\/\\1{$rdq}/", $content, $phpTagMatches);
$phpCode = $phpTagMatches[3][0];
if ($phpCode) {
// we want to create a file with the same path and name, but under the
// tempdir; this allows the php-extractor.php to add the right comment
$tempdir = sys_get_temp_dir();
$filedir = substr(dirname($file), strlen($root) + 1);
$filename = basename($file);
@mkdir("$tempdir/$filedir", 0777, true);
file_put_contents("$tempdir/$filedir/$filename", "<?php $phpCode ?>");
passthru("bin/php-extractor.php $tempdir $tempdir/$filedir/$filename");
}
preg_match_all("/{$ldq}\s*({$cmd})\s*([^{$rdq}]*){$rdq}([^{$ldq}]*){$ldq}\/\\1{$rdq}/", $content, $matches);
for ($i=0; $i < count($matches[0]); $i++) {
$output = array();
$output[] = '#: ' . substr($file, strlen($root) + 1);
if (preg_match('/plural\s*=\s*["\']?\s*(.[^\"\']*)\s*["\']?/', $matches[2][$i], $match)) {
$output[] = 'msgid "' . fs($matches[3][$i]) . '"';
$output[] = 'msgid_plural "' . fs($match[1]) . '"';
$output[] = 'msgstr[0] ""';
$output[] = 'msgstr[1] ""';
} else {
$output[] = 'msgid "' . fs($matches[3][$i]) . '"';
$output[] = 'msgstr ""';
}
print implode("\n", $output) . "\n\n";
}
preg_match_all("/{$ldq}\s*(docURL)\s*([^{$rdq}]*){$rdq}/", $content, $matches);
for ($i=0; $i < count($matches[0]); $i++) {
if (preg_match('/text\s*=\s*["\']?\s*(.[^\"\']*)\s*["\']?/', $matches[2][$i], $match)) {
print '#: ' . substr($file, strlen($root) + 1) . "\n";
print 'msgid "' . fs($match[1]) . "\"\n";
print "msgstr \"\"\n\n";
}
if (preg_match('/title\s*=\s*["\']?\s*(.[^\"\']*)\s*["\']?/', $matches[2][$i], $match)) {
print '#: ' . substr($file, strlen($root) + 1) . "\n";
print 'msgid "' . fs($match[1]) . "\"\n";
print "msgstr \"\"\n\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])) {
do_dir($_SERVER['argv'][$ac]);
} else {
do_file($_SERVER['argv'][$ac]);
}
}
#!/bin/bash
[ -z "$1" ] && echo 'source locale missing' && exit 1
[ -z "$2" ] && echo 'target locale missing' && exit 1
echo "porting from $1 to $2"
pots=`for pot in po/pot/*.pot; do basename $pot .pot; done`
for pot in $pots; do
echo -n $pot
msgcat --use-first po/$2/$pot.po po/$1/$pot.po | sponge po/$2/$pot.po
msgmerge --update po/$2/$pot.po po/pot/$pot.pot
msgattrib --no-obsolete --no-wrap po/$2/$pot.po | sponge po/$2/$pot.po
done
echo
echo "porting from $2 to $1"
pots=`for pot in po/pot/*.pot; do basename $pot .pot; done`
for pot in $pots; do
echo -n $pot
msgcat --use-first po/$1/$pot.po po/$2/$pot.po | sponge po/$1/$pot.po
msgmerge --update po/$1/$pot.po po/pot/$pot.pot
msgattrib --no-obsolete --no-wrap po/$1/$pot.po | sponge po/$1/$pot.po
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