NAME

Locale::PO::Utils - Utils to build/extract the PO header and anything else

$Id: Utils.pm 491 2010-04-18 05:23:02Z steffenw $

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

VERSION

0.02

SYNOPSIS

use Locale::PO::Utils;

DESCRIPTION

Utils to build/extract the PO header and anything else.

SUBROUTINES/METHODS

method new

my $obj = Locale::PO::Utils->new();

method get_all_header_keys

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

$array_ref = $obj->get_all_header_keys();

or as class method

$array_ref => Locale::PO::Utils->get_all_header_keys();

The $array_ref is:

[ qw(
    Content-Transfer-Encoding
    Content-Type
    Language-Team-Mail
    Language-Team-Name
    Last-Translator-Mail
    Last-Translator-Name
    MIME-Version
    PO-Revision-Date
    POT-Creation-Date
    Plural-Forms
    Project-Id-Version
    Report-Msgid-Bugs-To-Mail
    Report-Msgid-Bugs-To-Name
    charset
    extended
) ]

method build_header_msgstr

There are more ways to do this.

minimal header

$obj->build_header_msgstr();

The result is:

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

maximal header

$obj->build_header_msgstr({
    'Project-Id-Version'        => 'Testproject',
    'Report-Msgid-Bugs-To-Name' => 'Bug Reporter',
    'Report-Msgid-Bugs-To-Mail' => 'bug@example.org',
    'POT-Creation-Date'         => 'no POT creation date',
    'PO-Revision-Date'          => 'no PO revision date',
    'Last-Translator-Name'      => 'Steffen Winkler',
    'Last-Translator-Mail'      => 'steffenw@example.org',
    'Language-Team-Name'        => 'MyTeam',
    'Language-Team-Mail'        => '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 result 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 split_header_msgstr (for internal use only)

This method is internal used at method get_header_msgstr_data.

$array_ref = $obj->split_header_msgstr($msgstr);

method get_header_msgstr_data

This method extracts the values using the given keys.

single mode

$string = $obj->get_header_msgstr_data($msgstr, 'Project-Id-Version');

$string is now "Testproject".

multiple mode

$data = $obj->get_header_msgstr_data(
    $msgstr,
    [qw(Project-Id-Version Report-Msgid-Bugs-To-Mail extended)],
),

$data is now:

[
    'Testproject',
    'bug@example.org',
    [
        'X-Poedit-Language',
        'German',
        'X-Poedit-Country',
        'GERMANY',
        'X-Poedit-SourceCharset',
        'utf-8',
    ],
]

method maketext_to_gettext

Maps maketext strings with [_1] or [quant,_1,singular,plural,zero] inside to %1 or %quant(%1,singluar,plural,zero] inside.

$gettext_string = $obj->maketext_to_gettext($maketext_string);

or

@gettext_strings = $obj->maketext_to_gettext($maketext_strings);

This method can called as class method too.

$gettext_string = Locale::PO::Utils->maketext_to_gettext($maketext_string);

or

@gettext_strings = Locale::PO::Utils->maketext_to_gettext($maketext_strings);

DIAGNOSTICS

none

CONFIGURATION AND ENVIRONMENT

none

DEPENDENCIES

Moose

MooseX::StrictConstructor

MooseX::FollowPBP

Carp

Clone

Params::Validate

INCOMPATIBILITIES

not known

BUGS AND LIMITATIONS

not known

AUTHOR

Steffen Winkler

LICENSE AND COPYRIGHT

Copyright (c) 2010, 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.