Steffen Winkler
and 1 contributors

NAME

Locale::File::PO::Header - Utils to build/extract the PO header

$Id: Utils.pm 602 2011-11-13 13:49:23Z steffenw $

$HeadURL: https://dbd-po.svn.sourceforge.net/svnroot/dbd-po/Locale-File-PO-Header/trunk/lib/Locale/PO/Utils.pm $

VERSION

0.004

SYNOPSIS

    require Locale::PO::Utils;

    $obj = Locale::PO::Utils->new;

DESCRIPTION

Utils to build or extract the PO header

The header of a PO file is quite complex. This module helps to build the header and extract.

SUBROUTINES/METHODS

method msgstr - read and write the header as string

reader

    $msgstr = $obj->msgstr;

If nothing was set before it returns a minimal header:

 MIME-Version: 1.0
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: 8bit

writer

    $obj->msgstr(<<'EOT');
        Content-Type: text/plain; charset=UTF-8
    EOT

If nothing else was set before the msgstr is:

 MIME-Version: 1.0
 Content-Type: text/plain; charset=UTF-8
 Content-Transfer-Encoding: 8bit

method all_keys - names of all items

This sub returns all header keys you can set or get.

    @all_keys = $obj->all_keys;

The returned array is:

    qw(
        Project-Id-Version
        Report-Msgid-Bugs-To_name
        Report-Msgid-Bugs-To_address
        POT-Creation-Date
        PO-Revision-Date
        Last-Translator_name
        Last-Translator_address
        Language-Team_name
        Language-Team_address
        MIME-Version
        Content-Type
        charset
        Content-Transfer-Encoding
        Plural-Forms
        extended
    )

method data - modify lots of items

    $obj->data({
        Project-Id-Version           => 'Example',
        Report-Msgid-Bugs-To_address => 'bug@example.com',
        extended                     => {
            X-Example => 'This is an example',
        },
    });

If nothing else was set before the msgstr is:

 Project-Id-Version: Example
 Report-Msgid-Bugs-To: bug@example.com
 MIME-Version: 1.0
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: 8bit
 X-Example: This is an example

An example to write all keys:

    $obj->data({
        'Project-Id-Version'           => 'Testproject',
        'Report-Msgid-Bugs-To_name'    => 'Bug Reporter',
        'Report-Msgid-Bugs-To_address' => 'bug@example.org',
        'POT-Creation-Date'            => 'no POT creation date',
        'PO-Revision-Date'             => 'no PO revision date',
        'Last-Translator_name'         => 'Steffen Winkler',
        'Last-Translator_address'      => 'steffenw@example.org',
        'Language-Team_name'           => 'MyTeam',
        'Language-Team_address'        => 'cpan@example.org',
        'MIME-Version'                 => '1.0',
        'Content-Type'                 => 'text/plain',
        'charset'                      => 'utf-8',
        'Content-Transfer-Encoding'    => '8bit',
        'extended'                     => [
            'X-Poedit-Language'      => 'German',
            'X-Poedit-Country'       => 'GERMANY',
            'X-Poedit-SourceCharset' => 'utf-8',
        ],
    });

The msgstr is:

 Project-Id-Version: Testproject
 Report-Msgid-Bugs-To: Bug Reporter <bug@example.org>
 POT-Creation-Date: no POT creation date
 PO-Revision-Date: no PO revision date
 Last-Translator: Steffen Winkler <steffenw@example.org>
 Language-Team: MyTeam <cpan@example.org>
 MIME-Version: 1.0
 Content-Type: text/plain; charset=utf-8
 Content-Transfer-Encoding: 8bit
 X-Poedit-Language: German
 X-Poedit-Country: GERMANY
 X-Poedit-SourceCharset: utf-8

method item - read or write one item

writer

   $obj->item( 'Project-Id-Version' => 'Example' );

reader

   $value = $obj->item('Project-Id-Version');

method items - read lots of items

    @values = $obj->items( @keys );

    @values = $obj->items( qw(Project-Id-Version charset) );

EXAMPLE

Inside of this distribution is a directory named example. Run the *.pl files.

DIAGNOSTICS

none

CONFIGURATION AND ENVIRONMENT

none

DEPENDENCIES

Moose

MooseX::StrictConstructor

namespace::autoclean;

syntax

Clone

INCOMPATIBILITIES

not known

BUGS AND LIMITATIONS

not known

SEE ALSO

http://en.wikipedia.org/wiki/Gettext

AUTHOR

Steffen Winkler

LICENSE AND COPYRIGHT

Copyright (c) 2011 - 2017, Steffen Winkler <steffenw at cpan.org>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.