[interchange-i18n] parse_locale

Stefan Hornburg Racke racke at linuxia.de
Wed Feb 27 09:21:02 UTC 2002


Quite a while ago I put the code which handles the [L]...[/L] replacement
in a separate function in Util.pm. Besides being more clean it has the
advantage to be useful in user tags:

UserTag demo Routine <<EOF
sub {
    $out = 'bla bla';
    $out .= '[L]Translate Me[/L]';
    $out .= 'laber';
    ....
    return $Tag->parse_locale($out);
}
EOF

I suppose this will help us in several places where we need translation
of/in components, UI usertags etc.

The patches are used by me a while and noticed no problems. My idea
is to apply them to 4.8.x if no one objects, otherwise to 4.9.x.

I hope it applies clean to the vanilla sources, because I ripped
it out of a patch set.

Please tell me your opinion about this.

Ciao
        Racke

--- interchange-4.8.4-vanilla/lib/Vend/Util.pm	24 Jan 2002 05:07:02 -0000	2.1.2.4
+++ interchange-4.8.4/lib/Vend/Util.pm	1 Feb 2002 22:35:26 -0000
@@ -822,6 +857,26 @@
 	return $text;
 }
 
+sub parse_locale {
+	my ($contents) = @_;
+	
+	if($Vend::Cfg->{Locale}) {
+		my $key;
+		$contents =~ s~\[L(\s+([^\]]+))?\]([\000-\377]*?)\[/L\]~
+						$key = $2 || $3;		
+						defined $Vend::Cfg->{Locale}{$key}
+						?  ($Vend::Cfg->{Locale}{$key})	: $3 ~eg;
+		$contents =~ s~\[LC\]([\000-\377]*?)\[/LC\]~
+						find_locale_bit($1) ~eg;
+		undef $Lang;
+	}
+	else {
+		$contents =~ s~\[L(?:\s+[^\]]+)?\]([\000-\377]*?)\[/L\]~$1~g;
+	}
+
+	$contents;
+}
+
 # Reads in a page from the page directory with the name FILE and ".html"
 # appended. If the HTMLsuffix configuration has changed (because of setting in
 # catalog.cfg or Locale definitions) it will substitute that. Returns the
@@ -910,22 +965,8 @@
 	}
 
 	return unless defined $contents;
-	
-	if($Vend::Cfg->{Locale}) {
-		my $key;
-		$contents =~ s~\[L(\s+([^\]]+))?\]([\000-\377]*?)\[/L\]~
-						$key = $2 || $3;		
-						defined $Vend::Cfg->{Locale}{$key}
-						?  ($Vend::Cfg->{Locale}{$key})	: $3 ~eg;
-		$contents =~ s~\[LC\]([\000-\377]*?)\[/LC\]~
-						find_locale_bit($1) ~eg;
-		undef $Lang;
-	}
-	else {
-		$contents =~ s~\[L(?:\s+[^\]]+)?\]([\000-\377]*?)\[/L\]~$1~g;
-	}
 
-	return $contents;
+	parse_locale ($contents);
 }
 
 sub readfile_db {
diff -u -c -r2.0.2.4 Parse.pm
*** Parse.pm	24 Jan 2002 05:07:01 -0000	2.0.2.4
--- Parse.pm	27 Feb 2002 14:17:34 -0000
***************
*** 102,107 ****
--- 102,108 ----
  				or               1
  				order            2
  				page             2
+ 				parse_locale     0
  				perl             1
  				price            1
  				profile          1
***************
*** 192,197 ****
--- 193,199 ----
  				msg				=> [qw( key )],
  				mvasp			=> [qw( tables )],
  				options			=> [qw( code )],
+ 				parse_locale	=> [qw( )],			 
  				price			=> [qw( code )],
  				profile			=> [qw( name )],
  				process      	=> [qw( target secure )],
***************
*** 321,327 ****
  						msg				1
                          mvasp           1
                          perl            1
!                         query           1
                          region          1
                          restrict        1
                          row             1
--- 323,330 ----
  						msg				1
                          mvasp           1
                          perl            1
!                         parse_locale    1
!  				        query           1
                          region          1
                          restrict        1
                          row             1
***************
*** 540,545 ****
--- 543,549 ----
  # MVASP
  				mvasp			=> \&Vend::Interpolate::mvasp,
  # END MVASP
+    				parse_locale    => \&Vend::Util::parse_locale,
  				price        	=> \&Vend::Interpolate::tag_price,
  				process      	=> \&Vend::Interpolate::tag_process,
  				profile      	=> \&Vend::Interpolate::tag_profile,

Ciao
        Racke

-- 
Think of it !

For projects and other business stuff please refer to COBOLT NetServices
(URL: http://www.cobolt.net; Email: info at cobolt.net; Phone: 0041-1-3884400)



More information about the interchange-i18n mailing list