File: MOFile.pm

package info (click to toggle)
libpetal-perl 2.20-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,148 kB
  • sloc: perl: 4,712; xml: 726; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 963 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package Petal::TranslationService::MOFile;
use Locale::Maketext::Gettext;
use Encode;
use strict;
use warnings;


sub new
{
    my $class = shift;
    my $file  = shift || do {
        warn "No file specified for " . __PACKAGE__ . "::new (\$file)";
        return bless {}, $class;
    };

    -e $file or do { 
        warn "$file does not seem to exist";
        return bless {}, $class;
    };

    -f $file or do {
        warn "$file does not seem to be a file";
        return bless {}, $class;
    };

    my $self = bless { file => $file }, $class;
    $self->{lexicon} = { read_mo ($file) };

    ($self->{encoding}) = $self->{lexicon}{""} =~ /^Content-Type: text\/plain; charset=(.*)$/im;
    return $self;
}


sub maketext
{
    my $self = shift;
    my $id   = shift || return;
    $self->{lexicon} || return;
    my $res  = $self->{lexicon}->{$id};

    return undef unless defined $res;

    return decode($self->{encoding}, $res);
}


1;


__END__