summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2011-05-11 16:20:13 +0000
committerivan <ivan>2011-05-11 16:20:13 +0000
commit83053569b3d965924e2e1d4f5b199609ec7c29af (patch)
treecf7b145fe37e171045040cf9619e6aab98689cae /FS
parent38eb380a88ea7a130e83b77ff9c51ef6967b707b (diff)
i18n, RT#12515
Diffstat (limited to 'FS')
-rw-r--r--FS/FS.pm2
-rw-r--r--FS/FS/Conf.pm5
-rw-r--r--FS/FS/L10N.pm6
-rw-r--r--FS/FS/Locales.pm61
-rw-r--r--FS/FS/Mason.pm17
-rw-r--r--FS/FS/Mason/Request.pm2
-rw-r--r--FS/FS/Msgcat.pm26
-rw-r--r--FS/FS/Setup.pm2
-rw-r--r--FS/FS/TicketSystem.pm2
-rw-r--r--FS/MANIFEST3
-rw-r--r--FS/t/Locales.t5
11 files changed, 115 insertions, 16 deletions
diff --git a/FS/FS.pm b/FS/FS.pm
index 60f4cd10a..c8c58bd4e 100644
--- a/FS/FS.pm
+++ b/FS/FS.pm
@@ -39,6 +39,8 @@ L<FS::CurrentUser> - Package representing the current user
L<FS::CGI> - Non OO-subroutines for the web interface.
+L<FS::Locales> - Locales
+
L<FS::Msgcat> - Message catalog
L<FS::SearchCache> - Search cache
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index f7b68b2d2..d5828f0c0 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -8,6 +8,7 @@ use MIME::Base64;
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 @@ and customer address. Include units.',
{
'key' => 'locale',
'section' => 'UI',
- 'description' => 'Message locale',
+ 'description' => 'Default locale',
'type' => 'select',
- 'select_enum' => [ qw(en_US) ],
+ 'select_enum' => [ FS::Locales->locales ],
},
{
diff --git a/FS/FS/L10N.pm b/FS/FS/L10N.pm
new file mode 100644
index 000000000..c48261f4c
--- /dev/null
+++ b/FS/FS/L10N.pm
@@ -0,0 +1,6 @@
+package FS::L10N;
+use base qw(Locale::Maketext);
+
+our %Lexicon = ( _AUTO=>1 );
+
+1;
diff --git a/FS/FS/Locales.pm b/FS/FS/Locales.pm
new file mode 100644
index 000000000..607f2be2d
--- /dev/null
+++ b/FS/FS/Locales.pm
@@ -0,0 +1,61 @@
+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;
+
diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm
index 67c1d9f7c..e74f44eb1 100644
--- a/FS/FS/Mason.pm
+++ b/FS/FS/Mason.pm
@@ -137,6 +137,8 @@ if ( -e $addl_handler_use_file ) {
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 @@ if ( -e $addl_handler_use_file ) {
$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 @@ sub mason_interps {
${$_[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]});
- },
+ escape_flags => { 'js_string' => $js_string_sub,
+ 'defang' => $defang_sub,
},
compiler => HTML::Mason::Compiler::ToObject->new(
allow_globals => [qw(%session)],
diff --git a/FS/FS/Mason/Request.pm b/FS/FS/Mason/Request.pm
index a5ec21f18..bf704bda7 100644
--- a/FS/FS/Mason/Request.pm
+++ b/FS/FS/Mason/Request.pm
@@ -51,7 +51,7 @@ sub freeside_setup {
} else {
package HTML::Mason::Commands;
- use vars qw( $cgi $p $fsurl );
+ use vars qw( $cgi $p $fsurl $lh );
use Encode;
use FS::UID qw( cgisuidsetup );
use FS::CGI qw( popurl rooturl );
diff --git a/FS/FS/Msgcat.pm b/FS/FS/Msgcat.pm
index 70933b238..e111f4e8c 100644
--- a/FS/FS/Msgcat.pm
+++ b/FS/FS/Msgcat.pm
@@ -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 @@ FS::UID->install_callback( sub {
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 @@ sub gettext {
$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 @@ sub geterror {
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 @@ i18n/l10n, eek
=head1 SEE ALSO
-L<FS::msgcat>, L<FS::Record>, schema.html from the base documentation.
+L<FS::Locales>, L<FS::msgcat>
=cut
diff --git a/FS/FS/Setup.pm b/FS/FS/Setup.pm
index 13d6f60b1..fec1c2d08 100644
--- a/FS/FS/Setup.pm
+++ b/FS/FS/Setup.pm
@@ -103,7 +103,7 @@ sub populate_addl_locales {
sub _add_country {
- use Locale::SubCountry;
+ use Locale::SubCountry 1.44;
my( $country ) = shift;
diff --git a/FS/FS/TicketSystem.pm b/FS/FS/TicketSystem.pm
index 8ea4b03a8..1020a8cc3 100644
--- a/FS/FS/TicketSystem.pm
+++ b/FS/FS/TicketSystem.pm
@@ -28,7 +28,7 @@ sub AUTOLOAD {
}
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
diff --git a/FS/MANIFEST b/FS/MANIFEST
index 009c40dec..28518017e 100644
--- a/FS/MANIFEST
+++ b/FS/MANIFEST
@@ -594,3 +594,6 @@ FS/msa.pm
t/msa.t
FS/rate_center.pm
t/rate_center.t
+FS/Locales.pm
+t/Locales.t
+FS/L10N.pm
diff --git a/FS/t/Locales.t b/FS/t/Locales.t
new file mode 100644
index 000000000..38dff7fe7
--- /dev/null
+++ b/FS/t/Locales.t
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n" }
+END {print "not ok 1\n" unless $loaded;}
+use FS::Locales;
+$loaded=1;
+print "ok 1\n";