NAME
App::FileSync::Base - shared i18n behaviour for App::FileSync objects
SYNOPSIS
package App::FileSync::Something;
use parent -norequire, 'App::FileSync::Base';
sub check {
my ($self, $path) = @_;
$self->_throw('path.empty') unless length $path;
return $self->i18n('client.verbose_action', { verb => 'push', path => $path });
}
DESCRIPTION
Objects carry an optional language (a code such as de or a locale name such as de_DE.UTF-8). Two objects with different languages render their messages independently, so a server can answer in its own language while a client in the same process uses another.
METHODS
i18n
Purpose: render a catalogued message in this object's language.
Args: $key, optional \%args.
Returns: the rendered string, without a trailing newline.
Side Effects: none.
Usage:
my $text = $self->i18n('cli.sync.summary', { repo => $name, dry => '', pulled => 3, pushed => 0, deleted => 0, conflicts => 0 });
EXAMPLE
my $client = App::FileSync::Client->new(config => $c, name => 'docs', language => 'en');
print $client->i18n('word.file', { count => 2 }), "\n"; # 2 files
API SPECIFICATION
INPUT
[
{ name => 'self', type => 'object', can => 'i18n' },
{ name => 'key', type => 'string', min => 1 },
{ name => 'args', type => 'hashref', optional => 1 },
]
OUTPUT
{ type => 'string' }
MESSAGES
None; it renders them.
FORMAL SPECIFICATION
i18n(self, k, a) = message(k, a, self.language)
language
Purpose: the language this object renders messages in.
Args: none.
Returns: the configured language or locale, or undef for the process default.
Side Effects: none.
Usage:
my $language = $object->language;
EXAMPLE
print $admin->language // 'process default', "\n";
API SPECIFICATION
INPUT
[ { name => 'self', type => 'object' } ]
OUTPUT
{ type => 'string', optional => 1 }
MESSAGES
None.
FORMAL SPECIFICATION
language(self) = self.language
LIMITATIONS
_throw is :Protected (Sub::Protected), so only subclasses may raise through it. Like every Sub::Protected check it is bypassed while HARNESS_ACTIVE is set, so tests see the same behaviour as production only when they turn the bypass off.
AUTHOR
Nigel Horne, <njh at nigelhorne.com>
LICENCE AND COPYRIGHT
Copyright 2026 Nigel Horne.
Usage is subject to the GPL2 licence terms. If you use it, please let me know.