]> git.deb.at Git - deb/packages.git/blob - lib/Packages/I18N/Locale.pm
Remove the _ subroutine. I don't use it anyway and even its sheer
[deb/packages.git] / lib / Packages / I18N / Locale.pm
1 package Packages::I18N::Locale;
2
3 use strict;
4 use warnings;
5
6 use Exporter;
7 use Locale::gettext;
8
9 our @ISA = qw( Exporter );
10 # the reason we have both _g and _ is simply that there
11 # seem to be some situations where Perl doesn't handle _
12 # correctly. If in doubt use _g
13 our @EXPORT = qw( get_locale get_charset _g N_ );
14
15 my %lang2loc = ( en => "en_US",
16                  cs => "cs_CZ",
17                  da => "da_DK",
18                  ja => "ja_JP",
19                  sv => "sv_SE",
20                  uk => "uk_UA",
21                  default => "en_US",
22                  );
23
24 # most of them can probably changed to UTF-8 in Sarge
25 # as there are more available UTF-8 locales then
26 my %lang2charset = (
27                     default => 'UTF-8',
28                     ja => 'EUC-JP',
29                     uk => 'KOI8-U',
30                     );
31
32 sub get_locale {
33     my $lang = shift;
34     my $locale = $lang;
35
36     return "$lang2loc{default}.".get_charset() unless $lang;
37
38     if ( length($lang) == 2 ) {
39         $locale = $lang2loc{$lang} || ( "${lang}_" . uc $lang );
40     } elsif ( $lang !~ /^[a-z][a-z]_[A-Z][A-Z]$/ ) {
41         warn "get_locale: couldn't determine locale\n";
42         return;
43     }
44     $locale .= ".".get_charset($lang);
45     return $locale;
46 }
47
48 sub get_charset {
49     my $lang = shift;
50
51     return $lang2charset{default} unless $lang;
52     return $lang2charset{$lang} || $lang2charset{default};
53 }
54
55 sub _g { return gettext( $_[0] ) }
56 sub N_ { return $_[0] }
57
58 1;