The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Locale::TextDomain::OO::Plugin::Expand::Gettext - Additional gettext methods

$Id: Gettext.pm 444 2013-12-20 07:28:03Z steffenw $

$HeadURL: svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/module/trunk/lib/Locale/TextDomain/OO/Plugin/Expand/Gettext.pm $

VERSION

1.000

DESCRIPTION

This module provides an additional getext methods for static domain and category handling.

SYNOPSIS

    my $loc = Locale::Text::TextDomain::OO->new(
        plugins => [ qw (
            Expand::Gettext
            ...
        )],
        ...
    );

SUBROUTINES/METHODS

Translations methods

How to build the method name?

Use __ and append this with "n", "p" and/or "x" in alphabetic order.

 .------------------------------------------------------------------------.
 | Snippet | Description                                                  |
 |---------+--------------------------------------------------------------|
 | __      | Special marked for extraction.                               |
 | n       | Using plural forms.                                          |
 | p       | Context is the first parameter.                              |
 | x       | Last parameters as hash/hash_ref are for named placeholders. |
 '------------------------------------------------------------------------'

method __

Translate only

    print $loc->__(
        'Hello World!',
    );

method __x

Expand named placeholders

    print $loc->__x(
        'Hello {name}!',
        # hash or hash_ref
        name => 'Steffen',
    );

method __n

Plural

    print $loc->__n(
        'one file read',       # Singular
        'a lot of files read', # Plural
        $num_files,            # number to select the right plural form
    );

method __nx

Plural and expand named placeholders

    print $loc->__nx(
        '{num} file read',
        '{num} files read',
        $num_files,
        # hash or hash_ref
        num => $num_files,
    );

method __p

Context

    print $loc->__p (
        'time', # Context
        'to',
    );

    print $loc->__p (
        'destination', # Context
        'to',
    );

method __px

Context and expand named placeholders

    print $loc->__px (
        'destination',
        'from {town_from} to {town_to}',
        # hash or hash_ref
        town_from => 'Chemnitz',
        town_to   => 'Erlangen',
    );

method __np

Context and plural

    print $loc->__np (
        'maskulin',
        'Dear friend',
        'Dear friends',
        $friends,
    );

method __npx

Context, plural and expand named placeholders

    print $loc->__npx(
        'maskulin',
        'Mr. {name} has {num} book.',
        'Mr. {name} has {num} books.',
        $books,
        # hash or hash_ref
        name => $name,
    );

Methods to mark the translation for extraction only

How to build the method name?

Use N__ and append this with "n", "p" and/or "x" in alphabetic order.

 .------------------------------------------------------------------------.
 | Snippet | Description                                                  |
 |---------+--------------------------------------------------------------|
 | __      | Special marked for extraction.                               |
 | n       | Using plural forms.                                          |
 | p       | Context is the first parameter.                              |
 | x       | Last parameters as hash/hash_ref are for named placeholders. |
 '------------------------------------------------------------------------'

methods N__, N__x, N__n, N__nx, N__p, N__px, N__np, N__npx

The extractor looks for __('... and has no problem with $loc->N__('....

This is the idea of the N-Methods.

    $loc->N__('...');
    $loc->N__x('...', ...);
    ...

EXAMPLE

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

DIAGNOSTICS

confess

CONFIGURATION AND ENVIRONMENT

none

DEPENDENCIES

Locale::Utils::PlaceholderNamed

Moo::Role

namespace::autoclean

INCOMPATIBILITIES

not known

BUGS AND LIMITATIONS

none

SEE ALSO

Locale::TextDoamin::OO

AUTHOR

Steffen Winkler

LICENSE AND COPYRIGHT

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