[freeside-commits] freeside/FS/FS Locales.pm, NONE, 1.1 Conf.pm, 1.451, 1.452 Mason.pm, 1.71, 1.72 L10N.pm, NONE, 1.1 Msgcat.pm, 1.3, 1.4 Setup.pm, 1.24, 1.25 TicketSystem.pm, 1.6, 1.7

Ivan,,, ivan at wavetail.420.am
Wed May 11 09:20:14 PDT 2011


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv24392/FS/FS

Modified Files:
	Conf.pm Mason.pm Msgcat.pm Setup.pm TicketSystem.pm 
Added Files:
	Locales.pm L10N.pm 
Log Message:
i18n, RT#12515

Index: Conf.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Conf.pm,v
retrieving revision 1.451
retrieving revision 1.452
diff -u -w -d -r1.451 -r1.452
--- Conf.pm	5 May 2011 17:01:10 -0000	1.451
+++ Conf.pm	11 May 2011 16:20:12 -0000	1.452
@@ -8,6 +8,7 @@
 use FS::ConfItem;
 use FS::ConfDefaults;
 use FS::Conf_compat17;
+use FS::Locales;
 use FS::payby;
 use FS::conf;
 use FS::Record qw(qsearch qsearchs);
@@ -1800,9 +1801,9 @@
   {
     'key'         => 'locale',
     'section'     => 'UI',
-    'description' => 'Message locale',
+    'description' => 'Default locale',
     'type'        => 'select',
-    'select_enum' => [ qw(en_US) ],
+    'select_enum' => [ FS::Locales->locales ],
   },
 
   {

Index: Mason.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Mason.pm,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -w -d -r1.71 -r1.72
--- Mason.pm	15 Apr 2011 03:13:06 -0000	1.71
+++ Mason.pm	11 May 2011 16:20:12 -0000	1.72
@@ -137,6 +137,8 @@
   use FS::TicketSystem;
   use FS::NetworkMonitoringSystem;
   use FS::Tron qw( tron_lint );
+  use FS::Locales;
+  use FS::L10N;
 
   use FS::agent;
   use FS::agent_type;
@@ -406,6 +408,11 @@
     $m->comp('/elements/errorpage-popup.html', @_);
   }
 
+  sub mt {
+    use vars qw($lh);
+    $lh->maketext(@_);
+  }
+
   sub redirect {
     my( $location ) = @_;
     use vars qw($m);
@@ -526,13 +533,15 @@
     ${$_[0]} = "'". ${$_[0]}. "'";
   };
 
+  my $defang_sub = sub {
+    ${$_[0]} = $html_defang->defang(${$_[0]});
+  };
+
   my $fs_interp = new HTML::Mason::Interp (
     %interp,
     comp_root    => $fs_comp_root,
     escape_flags => { 'js_string' => $js_string_sub,
-                      'defang'    => sub {
-                        ${$_[0]} = $html_defang->defang(${$_[0]});
-                      },
+                      'defang'      => $defang_sub,
                     },
     compiler     => HTML::Mason::Compiler::ToObject->new(
                       allow_globals        => [qw(%session)],

Index: TicketSystem.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/TicketSystem.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -w -d -r1.6 -r1.7
--- TicketSystem.pm	10 May 2011 23:21:44 -0000	1.6
+++ TicketSystem.pm	11 May 2011 16:20:12 -0000	1.7
@@ -28,7 +28,7 @@
 }
 
 sub _upgrade_data {
-  return if $system ne 'RT_Internal';
+  return if !defined($system) || $system ne 'RT_Internal';
   my ($class, %opts) = @_;
 
   # go ahead and use the RT API for this

Index: Setup.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Setup.pm,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -w -d -r1.24 -r1.25
--- Setup.pm	24 Apr 2011 00:33:56 -0000	1.24
+++ Setup.pm	11 May 2011 16:20:12 -0000	1.25
@@ -103,7 +103,7 @@
 
 sub _add_country {
 
-  use Locale::SubCountry;
+  use Locale::SubCountry 1.44;
 
   my( $country ) = shift;
 

Index: Msgcat.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Msgcat.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -d -r1.3 -r1.4
--- Msgcat.pm	18 Jun 2008 00:42:31 -0000	1.3
+++ Msgcat.pm	11 May 2011 16:20:12 -0000	1.4
@@ -1,7 +1,7 @@
 package FS::Msgcat;
 
 use strict;
-use vars qw( @ISA @EXPORT_OK $conf $locale $debug );
+use vars qw( @ISA @EXPORT_OK $conf $def_locale $debug );
 use Exporter;
 use FS::UID;
 #use FS::Record qw( qsearchs ); # wtf?  won't import...
@@ -16,7 +16,7 @@
   eval "use FS::Conf;";
   die $@ if $@;
   $conf = new FS::Conf;
-  $locale = $conf->config('locale') || 'en_US';
+  $def_locale = $conf->config('locale') || 'en_US';
   $debug = $conf->exists('show-msgcat-codes')
 });
 
@@ -52,17 +52,28 @@
   $debug ? geterror(@_) : _gettext(@_);
 }
 
+#though i guess we don't really have to cache here since we do it in
+# FS::L10N::DBI
+our %cache;
+
 sub _gettext {
   my $msgcode = shift;
+  my $locale =  (@_ && shift)
+             || $FS::CurrentUser::CurrentUser->option('locale')
+             || $def_locale;
+
+  return $cache{$locale}->{$msgcode} if exists $cache{$locale}->{$msgcode};
+
   my $msgcat = FS::Record::qsearchs('msgcat', {
     'msgcode' => $msgcode,
-    'locale' => $locale
+    'locale'  => $locale,
   } );
   if ( $msgcat ) {
-    $msgcat->msg;
+    $cache{$locale}->{$msgcode} = $msgcat->msg;
   } else {
-    warn "WARNING: message for msgcode $msgcode in locale $locale not found";
-    $msgcode;
+    warn "WARNING: message for msgcode $msgcode in locale $locale not found"
+      unless $locale eq 'en_US';
+    $cache{$locale}->{$msgcode} = $msgcode;
   }
 
 }
@@ -78,6 +89,7 @@
   my $msgcode = shift;
   my $msg = _gettext($msgcode);
   if ( $msg eq $msgcode ) {
+    my $locale = $FS::CurrentUser::CurrentUser->option('locale') || $def_locale;
     "Error code $msgcode (message for locale $locale not found)";
   } else {
     "$msg (error code $msgcode)";
@@ -92,7 +104,7 @@
 
 =head1 SEE ALSO
 
-L<FS::msgcat>, L<FS::Record>, schema.html from the base documentation.
+L<FS::Locales>, L<FS::msgcat>
 
 =cut
 

--- NEW FILE: Locales.pm ---
package FS::Locales;

use strict;
use Tie::IxHash;

=head1 NAME

FS::Locales - Supported locales

=head1 SYNOPSIS

  use FS::Locales;

  my @locales = FS::Locales->locales;

=head1 DESCRIPTION

FS::Locales provides a list of supported locales.

=head1 CLASS METHODS

=over 4

=item locales

Returns a list of the available locales.

=cut

tie our %locales, 'Tie::IxHash',
  'en_US', { name => 'English', country => 'United States', },
  'iw_IL', { name => 'Hebrew',  country => 'Israel', rtl=>1, },
;

sub locales {
  keys %locales;
}

=item locale_info LOCALE

Returns a hash of information about a locale.

=cut

sub locale_info {
  my($class, $locale) = @_;
  %{ $locales{$locale} };
}

=back

=head1 BUGS

=head1 SEE ALSO

L<FS::Msgcat>

=cut

1;


--- NEW FILE: L10N.pm ---
package FS::L10N;
use base qw(Locale::Maketext);

our %Lexicon = ( _AUTO=>1 );

1;



More information about the freeside-commits mailing list