diff options
author | Andras Timar <atimar@suse.com> | 2011-09-16 09:52:37 +0200 |
---|---|---|
committer | Andras Timar <atimar@suse.com> | 2011-09-17 10:18:18 +0200 |
commit | 1066677fd5e10bac78b8e4ebbabfa6bd44dc3859 (patch) | |
tree | 269110bb8815f3ebd3f898b40ee10f57394cd31a /l10ntools | |
parent | rewrite keyidGen.pl (diff) | |
download | core-1066677fd5e10bac78b8e4ebbabfa6bd44dc3859.tar.gz core-1066677fd5e10bac78b8e4ebbabfa6bd44dc3859.zip |
add a new helper script: addkeyid2pot.pl
It adds key IDs to pot entries in the form of #. type comments.
In Pootle the translator can search for strings using the key IDs.
Diffstat (limited to 'l10ntools')
-rw-r--r-- | l10ntools/prj/d.lst | 1 | ||||
-rw-r--r-- | l10ntools/scripts/addkeyid2pot.pl | 106 |
2 files changed, 107 insertions, 0 deletions
diff --git a/l10ntools/prj/d.lst b/l10ntools/prj/d.lst index ad2d7150df26..bcbe25206a59 100644 --- a/l10ntools/prj/d.lst +++ b/l10ntools/prj/d.lst @@ -40,6 +40,7 @@ mkdir: %_DEST%\bin\help\com\sun\star\help ..\scripts\localize %_DEST%\bin\localize ..\scripts\fast_merge.pl %_DEST%\bin\fast_merge.pl ..\scripts\keyidGen.pl %_DEST%\bin\keyidGen.pl +..\scripts\addkeyid2pot.pl %_DEST%\bin\addkeyid2pot.pl ..\scripts\po2lo %_DEST%\bin\po2lo ..\inc\export.hxx %_DEST%\inc\l10ntools\export.hxx ..\inc\l10ntools\directory.hxx %_DEST%\inc\l10ntools\directory.hxx diff --git a/l10ntools/scripts/addkeyid2pot.pl b/l10ntools/scripts/addkeyid2pot.pl new file mode 100644 index 000000000000..bd66a3b696e9 --- /dev/null +++ b/l10ntools/scripts/addkeyid2pot.pl @@ -0,0 +1,106 @@ +: +eval 'exec perl -S $0 ${1+"$@"}' + if 0; +# Version: MPL 1.1 / GPLv3+ / LGPLv3+ +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License or as specified alternatively below. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Initial Developer of the Original Code is +# Andras Timar <atimar@suse.com> +# Portions created by the Initial Developer are Copyright (C) 2011 the +# Initial Developer. All Rights Reserved. +# +# Major Contributor(s): +# +# For minor contributions see the git repository. +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 3 or later (the "GPLv3+"), or +# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), +# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable +# instead of those above. +# +# add keyids to pot files +# + +use File::Find; + +sub keyidgen +{ + my $key = shift; + my $crc = crc24($key); + my $symbols="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#_"; + my $keyid = ""; + while ( length($keyid) < 4 ) + { + $keyid .= substr($symbols, $crc & 63, 1); + $crc = $crc >> 6; + } + return $keyid; +} + +sub crc24 +{ + my $CRC24_INIT = 0x00b704ce; + my $CRC24_POLY = 0x00864cfb; + my $key = shift; + my $key_length = length($key); + my $crc = $CRC24_INIT; + my $position = 0; + + while ( $position < $key_length ) + { + $crc ^= (unpack("C", substr($key, $position, 1)) << 16); + my $i; + for ($i = 0; $i < 8; $i++) + { + $crc <<= 1; + $crc ^= $CRC24_POLY if ($crc & 0x01000000) + } + $position++; + } + return $crc & 0x00ffffff; +} + +my $potdir = $ARGV[0]; + +if (!$potdir) {die "Usage_ $0 <directory of pot files>\n";} + +my @potfiles = (); + +File::Find::find( sub {/^.*\.pot\z/s && push @potfiles, $File::Find::name;}, $potdir ); + +foreach $f (@potfiles) +{ + open OLDPOT , "< $f" || die("Cannot open source pot file: $f\n"); + $fnew = $f . ".new"; + @path = split ("/",$f); + $keypart1 = pop @path; + $keypart1 =~ s/.pot//; + $keypart1 .= "_"; + $keypart2 = pop @path; + $keypart1 = $keypart2 . "_" . $keypart1; + open NEWPOT , "> $fnew" || die("Cannot open target pot file: $f\n"); + while ( <OLDPOT> ) + { + chomp; + if( /^#: (.*)$/ ) + { + print NEWPOT "#. " . keyidgen($keypart1 . $1) . "\n"; + } + print NEWPOT $_ . "\n"; + } + close OLDPOT; + close NEWPOT; + rename $fnew,$f; +} + +exit 0; |