mirror of
https://gitlab.com/davical-project/davical.git
synced 2026-08-06 14:40:28 +00:00
Scripts for building initial messages.po file for use with gettext.
This commit is contained in:
parent
194328b396
commit
4d4b99be19
142
scripts/po/extract.pl
Executable file
142
scripts/po/extract.pl
Executable file
@ -0,0 +1,142 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Perl script to extract strings from all the files and print
|
||||
# to stdout for use with xgettext.
|
||||
#
|
||||
# This script is based on the one provided with the Horde project
|
||||
# http://www.horde.org/. As such, it inherits the license from the
|
||||
# original version. You can find that license here:
|
||||
#
|
||||
# http://cvs.horde.org/co.php/horde/COPYING?r=2.1
|
||||
#
|
||||
# I'm not exactly sure what the license restrictions are in this case,
|
||||
# but I want to give full credit to the original authors, including
|
||||
# the Gallery project which the script passed through on the way.
|
||||
#
|
||||
# Copyright 2000-2002 Joris Braakman <jbraakman@yahoo.com>
|
||||
# Copyright 2001-2002 Chuck Hagenbuch <chuck@horde.org>
|
||||
# Copyright 2001-2002 Jan Schneider <jan@horde.org>
|
||||
# Copyright 2002-2003 Bharat Mediratta <bharat@menalto.com>
|
||||
#
|
||||
#
|
||||
use FileHandle;
|
||||
use File::Basename;
|
||||
use File::Find;
|
||||
use IPC::Open2;
|
||||
use strict;
|
||||
|
||||
my %strings;
|
||||
|
||||
my $exts = '(php|pl)';
|
||||
|
||||
foreach my $moduleDir (@ARGV) {
|
||||
find(\&extract, $moduleDir);
|
||||
}
|
||||
|
||||
print join("\n" => sort keys %strings), "\n";
|
||||
|
||||
sub extract {
|
||||
my $file = $File::Find::name;
|
||||
my $dir = $File::Find::dir;
|
||||
my $fd = new FileHandle;
|
||||
|
||||
if ($file =~ /\.$exts$/) {
|
||||
open($fd, basename($file));
|
||||
my $data = join('' => <$fd>);
|
||||
|
||||
# grab phrases for translate( or i18n( calls; capture string parameter enclosed
|
||||
# in single or double quotes including concatenated strings like 'one' . "two"
|
||||
while ($data =~
|
||||
/(translate|i18n)\(\s*(((\s*\.\s*)?('((\\')?[^']*)*[^\\]'|"((\\")?[^"]*)*[^\\]"))+)\s*\)/sg) {
|
||||
# Call out to php to parse string..
|
||||
my ($in, $out);
|
||||
open2($in, $out, 'php -q');
|
||||
print $out '<?php print ';
|
||||
print $out $2;
|
||||
print $out ' ?>';
|
||||
close $out;
|
||||
my $text = join('', <$in>);
|
||||
close $in;
|
||||
$text =~ s/\"/\\\"/sg; # escape double-quotes
|
||||
$strings{qq{gettext("$text")}}++;
|
||||
}
|
||||
|
||||
# grab phrases of this format: translate(array('one' => '...', 'many' => '...'))
|
||||
while ($data =~ /translate\(.*?array\('one'\s*=>\s*'(.*?)'.*?'many'\s*=>\s*'(.*?)'.*?\).*?\)/sg) {
|
||||
my ($one, $many) = ($1, $2);
|
||||
$one =~ s/\"/\\\"/sg; # escape double-quotes
|
||||
$many =~ s/\"/\\\"/sg; # escape double-quotes
|
||||
$strings{qq{ngettext("$one", "$many")}}++;
|
||||
}
|
||||
|
||||
# grab phrases of this format: translate(array('text' => '...', ...))
|
||||
while ($data =~ /translate\(\s*array\('text'\s*=>\s+'(.*?[^\\])'/sg) {
|
||||
my $text = $1;
|
||||
$text =~ s/\"/\\\"/sg; # escape double-quotes
|
||||
$strings{qq{gettext("$text")}}++;
|
||||
}
|
||||
|
||||
# grab phrases of this format {g->text ..... }
|
||||
while ($data =~ /(\{\s*g->text\s+.*?[^\\]\})/sg) {
|
||||
my $string = $1;
|
||||
my $text;
|
||||
my $one;
|
||||
my $many;
|
||||
|
||||
# Ignore translations of the form:
|
||||
# text=$foo
|
||||
# as we expect those to be variables containing values that
|
||||
# have been marked elsewhere with the i18n() function
|
||||
if ($string =~ /text=\$/) {
|
||||
next;
|
||||
}
|
||||
|
||||
# text=.....
|
||||
if ($string =~ /text="(.*?[^\\])"/s) {
|
||||
$text = $1;
|
||||
}
|
||||
elsif ($string =~ /text='(.*?)'/s) {
|
||||
$text = $1;
|
||||
$text =~ s/\"/\\\"/sg; # escape double-quotes
|
||||
}
|
||||
|
||||
# one = .....
|
||||
if ($string =~ /\s+one="(.*?[^\\])"/s) {
|
||||
$one = $1;
|
||||
}
|
||||
elsif ($string =~ /\s+one='(.*?)'/s) {
|
||||
$one = $1;
|
||||
$one =~ s/\"/\\\"/sg; # escape double-quotes
|
||||
}
|
||||
|
||||
# many = .....
|
||||
if ($string =~ /\s+many="(.*?[^\\])"/s) {
|
||||
$many = $1;
|
||||
}
|
||||
elsif ($string =~ /\s+many='(.*?)'/s) {
|
||||
$many = $1;
|
||||
$many =~ s/\"/\\\"/sg; # escape double-quotes
|
||||
}
|
||||
|
||||
# pick gettext() or ngettext()
|
||||
if ($text) {
|
||||
$string = qq{gettext("$text")};
|
||||
}
|
||||
elsif ($one and $many) {
|
||||
$string = qq{ngettext("$one", "$many")};
|
||||
}
|
||||
else {
|
||||
# parse error
|
||||
$text =~ s/\n/\n>/sg;
|
||||
print STDERR "extract.pl parse error: $file:\n";
|
||||
print STDERR "> $string\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$string =~ s/\\\}/\}/sg; # unescape right-curly-braces
|
||||
$strings{qq{$string}}++;
|
||||
}
|
||||
|
||||
close($fd);
|
||||
}
|
||||
}
|
||||
32
scripts/po/rebuild-translations.sh
Executable file
32
scripts/po/rebuild-translations.sh
Executable file
@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Rebuild all of our strings to be translated. Written for
|
||||
# the Really Simple CalDAV Store by Andrew McMillan vaguely
|
||||
# based on something that originally came from Horde.
|
||||
#
|
||||
|
||||
[ -n "${DEBUG}" ] && set -o xtrace
|
||||
|
||||
POTOOLS="scripts/po"
|
||||
PODIR="po"
|
||||
LOCALEDIR="locale"
|
||||
APPLICATION="rscds"
|
||||
|
||||
${POTOOLS}/extract.pl htdocs inc > ${PODIR}/strings.raw
|
||||
xgettext --keyword=_ -C --no-location --output=${PODIR}/messages.tmp ${PODIR}/strings.raw
|
||||
sed -e 's/CHARSET/UTF-8/' <${PODIR}/messages.tmp >${PODIR}/messages.po
|
||||
rm ${PODIR}/messages.tmp
|
||||
|
||||
|
||||
for LOCALE in `psql -qAt -c 'SELECT locale FROM supported_locales;' caldav` ; do
|
||||
if [ ! -f ${PODIR}/${LOCALE}.po ] ; then
|
||||
cp ${PODIR}/messages.po ${PODIR}/${LOCALE}.po
|
||||
fi
|
||||
msgmerge --quiet --width 105 --update ${PODIR}/${LOCALE}.po ${PODIR}/messages.po
|
||||
done
|
||||
|
||||
for LOCALE in `psql -qAt -c 'SELECT locale FROM supported_locales;' caldav` ; do
|
||||
mkdir -p ${LOCALEDIR}/${LOCALE}/LC_MESSAGES
|
||||
msgfmt ${PODIR}/${LOCALE}.po -o ${LOCALEDIR}/${LOCALE}/LC_MESSAGES/${APPLICATION}.mo
|
||||
done
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user