X-Git-Url: https://git.deb.at/?p=deb%2Fpackages.git;a=blobdiff_plain;f=lib%2FPackages%2FI18N%2FLocale.pm;h=c65c9b70d3f6a6f5ed7dab8bdf4349adae91e8a5;hp=2bfaef2b43d0c2defff0bad1b73b7fa507a750a5;hb=58039945e72bbba9d7395e78df27f028479f00d3;hpb=a5b7db12d70653d35344cb6567db1c5e0cd326d1 diff --git a/lib/Packages/I18N/Locale.pm b/lib/Packages/I18N/Locale.pm index 2bfaef2..c65c9b7 100644 --- a/lib/Packages/I18N/Locale.pm +++ b/lib/Packages/I18N/Locale.pm @@ -3,58 +3,39 @@ package Packages::I18N::Locale; 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", - ); - -# most of them can probably changed to UTF-8 in Sarge -# as there are more available UTF-8 locales then -my %lang2charset = ( - default => 'UTF-8', - ja => 'EUC-JP', - uk => 'KOI8-U', - ); - -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; +use base 'Locale::Maketext'; +use Locale::Maketext::Lexicon; + +use base 'Exporter'; + +our @EXPORT = qw( N_ ); + +sub load { + my ($podir) = @_; + + Locale::Maketext::Lexicon->import( { + 'en' => [Gettext => "$podir/pdo.pot", + Gettext => "$podir/templates.pot", + Gettext => "$podir/langs.pot", + Gettext => "$podir/sections.pot", + Gettext => "$podir/debtags.pot"], + '*' => [Gettext => "$podir/pdo.*.po", + Gettext => "$podir/templates.*.po", + Gettext => "$podir/langs.*.po", + Gettext => "$podir/sections.*.po", + Gettext => "$podir/debtags.*.po"], + _auto => 1, + _style => 'gettext', + } ); } -sub get_charset { - my $lang = shift; +sub N_ { return $_[0]; } - return $lang2charset{default} unless $lang; - return $lang2charset{$lang} || $lang2charset{default}; +sub g { + my ($self, $format, @args) = @_; + my $result = $self->maketext($format, @args); + return sprintf($result, @args) if $result =~ /%([su]|[.\d]*f)/; + return $result; } -sub _ { return gettext( $_[0] ) } -sub _g { return gettext( $_[0] ) } -sub N_ { return $_[0] } - 1;