NAME

Text::PO::String - A GNU Gettext String Class

SYNOPSIS

use Text::PO::Gettext;
my $str = Text::PO::String->new(
    locale   => 'fr_FR',
    value    => 'Salut tout le monde !',
}) || die( Text::PO::String->error );

say $str;

VERSION

v0.1.0

DESCRIPTION

This class is a simple representation of a localised string. It is an inline package living within Text::PO::Gettext.

The purpose is to associate a locale to a string when it is returned by Text::PO::Gettext. This is useful when you return localised content to the user in an HTTP request, for example, and you want to set the HTTP header Content-Language. When using Text::PO::Gettext, every localised content is guaranteed to be an instance of this class.

Objects from this class are overloaded with stringification capability.

CONSTRUCTOR

new

Takes the following options and returns a Text::PO::String object.

  • locale

    A locale, such as en_US, en, ja_JP, etc. See Locale::Unicode for more information about locale

  • value

    The localised text.

METHODS

as_string

Returns the "value", but as a simple string, not a Module::Generic::Scalar object.

This is called automatically when the object is stringified, such as:

say "$str";

locale

$str->locale( 'fr_FR' );
$str->locale; # fr_FR

Sets or gets the locale for this object.

This returns the current value as a Module::Generic::Scalar object.

See Locale::Unicode for more information about locale

value

$str->value( 'Salut tout le monde !' );
$str->value; # Salut tout le monde !

Sets or gets the localised text.

This returns the current value as a Module::Generic::Scalar object.

THREAD-SAFETY

This module is thread-safe for all operations, as it operates on per-object state and uses thread-safe external libraries.

AUTHOR

Jacques Deguest <jack@deguest.jp>

SEE ALSO

Text::PO::Gettext, Text::PO, Text::PO::Element, Text::PO::MO

Module::Generic::Scalar

COPYRIGHT & LICENSE

Copyright(c) 2021-2025 DEGUEST Pte. Ltd. DEGUEST Pte. Ltd.