debug( "LANGUAGES=@all_langs header=".
($input->http("Accept-Language")||'').
" http_lang=$http_lang", 1 ) if DEBUG;
- bindtextdomain ( 'pdo', $LOCALES );
- bindtextdomain ( 'templates', $LOCALES );
- bindtextdomain ( 'langs', $LOCALES );
- textdomain( 'pdo' );
# backwards compatibility stuff
debug( "SCRIPT_URL=$ENV{SCRIPT_URL} SCRIPT_URI=$ENV{SCRIPT_URI}" ) if DEBUG;
my %params = Packages::CGI::parse_params( $input, \%params_def, \%opts );
Packages::CGI::init_url( $input, \%params, \%opts );
- my $locale = get_locale($opts{lang});
- my $charset = get_charset($opts{lang});
- setlocale ( LC_ALL, $locale )
- or do { debug( "couldn't set locale $locale, using default" ) if DEBUG;
- setlocale( LC_ALL, get_locale() )
- or do {
- debug( "couldn't set default locale either" ) if DEBUG;
- setlocale( LC_ALL, "C" );
- };
- };
- debug( "locale=$locale charset=$charset", 1 ) if DEBUG;
+ my $charset = "UTF-8";
+ my $cat = Packages::I18N::Locale->get_handle( $opts{lang} )
+ or die "get_handle failed";
$opts{h_suites} = { map { $_ => 1 } @suites };
$opts{h_sections} = { map { $_ => 1 } @sections };
my $template = new Packages::Template( $TEMPLATEDIR, $opts{format},
{ lang => $opts{lang}, charset => $charset,
+ cat => $cat,
debug => ( DEBUG ? $opts{debug} : 0 ) },
( $CACHEDIR ? { COMPILE_DIR => $CACHEDIR } : {} ) );
use strict;
use warnings;
-use Exporter;
-use Locale::gettext;
-
-our @ISA = qw( Exporter );
-# the reason we have both _g and _ is simply that there
-# seem to be some situations where Perl doesn't handle _
-# correctly. If in doubt use _g
-our @EXPORT = qw( get_locale get_charset _g N_ );
-
-my %lang2loc = ( en => "en_US",
- cs => "cs_CZ",
- da => "da_DK",
- ja => "ja_JP",
- sv => "sv_SE",
- uk => "uk_UA",
- default => "en_US",
- );
-
-# this can probably be removed now that all locales are available in UTF-8
-my %lang2charset = (
- default => 'UTF-8',
- );
-
-sub get_locale {
- my $lang = shift;
- my $locale = $lang;
-
- return "$lang2loc{default}.".get_charset() unless $lang;
-
- if ( length($lang) == 2 ) {
- $locale = $lang2loc{$lang} || ( "${lang}_" . uc $lang );
- } elsif ( $lang !~ /^[a-z][a-z]_[A-Z][A-Z]$/ ) {
- warn "get_locale: couldn't determine locale\n";
- return;
- }
- $locale .= ".".get_charset($lang);
- return $locale;
-}
-
-sub get_charset {
- my $lang = shift;
-
- return $lang2charset{default} unless $lang;
- return $lang2charset{$lang} || $lang2charset{default};
-}
-
-sub tt_gettext {
- my ($str, @args) = @_;
- return dgettext( 'templates', $str ) unless @args;
- return sprintf(dgettext( 'templates', $str ), @args);
+use base 'Locale::Maketext';
+use Locale::Maketext::Lexicon {
+ '*' => [Gettext => '/home/djpig/debian/www.d.o/packages/po/pdo.*.po',
+ Gettext => '/home/djpig/debian/www.d.o/packages/po/templates.*.po',
+ Gettext => '/home/djpig/debian/www.d.o/packages/po/langs.*.po'],
+ _auto => 1,
+ _style => 'gettext',
+};
+
+use base 'Exporter';
+
+our @EXPORT = qw( _g N_ );
+
+sub _g { return $_[0]; }
+sub N_ { return $_[0]; }
+
+sub g {
+ my ($self, $format, @args) = @_;
+ my $result = $self->maketext($format, @args);
+ return sprintf($result, @args) if $result =~ /%[su]/;
+ return $result;
}
-sub _g { return gettext( $_[0] ) }
-sub N_ { return $_[0] }
1;
};
$vars->{make_search_url} = sub { return &Packages::CGI::make_search_url(@_) };
$vars->{make_url} = sub { return &Packages::CGI::make_url(@_) };
- $vars->{g} = sub { return &Packages::I18N::Locale::tt_gettext(@_) };
+ if ($vars->{cat}) {
+ $vars->{g} = sub { return Packages::I18N::Locale::g($vars->{cat}, @_) };
+ }
$vars->{extract_host} = sub { my $uri = URI->new($_[0]);
my $host = $uri->host;
$host .= ':'.$uri->port if $uri->port != $uri->default_port;