[Libreoffice-commits] .: solenv/bin
Michael Meeks
mmeeks at kemper.freedesktop.org
Fri Dec 17 12:05:27 PST 2010
solenv/bin/modules/pre2par/language.pm | 57 +++++++++++++++------------------
1 file changed, 26 insertions(+), 31 deletions(-)
New commits:
commit dc0912cd03399824e0c694a05e06a2981fa1f2c0
Author: Michael Meeks <michael.meeks at novell.com>
Date: Fri Dec 17 20:04:29 2010 +0000
make pre2par 5x faster, and simpler too
diff --git a/solenv/bin/modules/pre2par/language.pm b/solenv/bin/modules/pre2par/language.pm
index 62d96f9..bc02064 100644
--- a/solenv/bin/modules/pre2par/language.pm
+++ b/solenv/bin/modules/pre2par/language.pm
@@ -105,29 +105,25 @@ sub get_language_block_from_language_file
}
############################################
-# collecting all replace strings
+# collecting all replace variables
# in a language file
############################################
-sub get_all_replace_strings
+sub get_all_replace_variables
{
my ($langfile) = @_;
- my @allstrings = ();
-
+ my %allvars = ();
+
for ( my $i = 0; $i <= $#{$langfile}; $i++ )
- {
+ {
if ( ${$langfile}[$i] =~ /^\s*\[\s*(.*?)\s*\]\s*$/ )
{
- my $replacestring = $1;
- if (! pre2par::existence::exists_in_array($replacestring, \@allstrings))
- {
- push(@allstrings, $replacestring);
- }
+ $allvars{$1} = 1;
}
}
-
- return \@allstrings;
+
+ return \%allvars;
}
############################################
@@ -139,34 +135,33 @@ sub localize
{
my ($parfile, $langfile) = @_;
- my $allreplacestrings = get_all_replace_strings($langfile);
-
+ my $replace_hash = get_all_replace_variables($langfile);
+
+ # parse lines of the form Name (st) = STR_NAME_MODULE_HELPPACK_OC;
+ # for variable substitution
+ my $langlinere = qr/^\s*\w+\s*\(([\w-]+)\)\s*\=\s*([\w-]+)\s*;/;
for ( my $i = 0; $i <= $#{$parfile}; $i++ )
{
my $oneline = ${$parfile}[$i];
- for ( my $j = 0; $j <= $#{$allreplacestrings}; $j++ )
- {
- if ( $oneline =~ /\b${$allreplacestrings}[$j]\b/ ) # Not for basic scripts
- {
- my $oldstring = ${$allreplacestrings}[$j];
-
- if ( $oneline =~ /^\s*\w+\s*\(([\w-]+)\)\s*\=/ )
- {
- my $language = $1; # can be "01" or "en" or "en-US" or ...
-
- my $languageblock = get_language_block_from_language_file($oldstring, $langfile);
+ if ( $oneline =~ $langlinere) {
+ my $language = $1; # can be "01" or "en" or "en-US" or ...
+ my $variable = $2;
+
+# print "line '$oneline' split to '$language' '$variable'\n";
+
+ if (defined $replace_hash->{$variable}) {
+ my $languageblock = get_language_block_from_language_file($variable, $langfile);
my $newstring = get_language_string_from_language_block($languageblock, $language);
- if ( $newstring eq "" ) { $newstring = "\"" . $oldstring . "\""; }
-
- $oneline =~ s/$oldstring/$newstring/g;
-
+ if ( $newstring eq "" ) { $newstring = "\"" . $variable . "\""; }
+
+ $oneline =~ s/$variable/$newstring/g;
+
${$parfile}[$i] = $oneline;
}
- }
}
- }
+ }
}
1;
More information about the Libreoffice-commits
mailing list