Commit 46492224 authored by intrigeri's avatar intrigeri

Port Perl code to translatable strings format supported by GNU gettext

refs #17928
parent 4fb5851f
......@@ -35,15 +35,15 @@ See https://tails.boum.org/.
use Carp;
use Carp::Assert::More;
use Fatal qw{open close};
use Locale::gettext;
use POSIX;
use Locale::TextDomain 'tails';
use Tails::Download::HTTPS;
use Try::Tiny;
use XML::Atom;
use XML::Atom::Feed;
setlocale(LC_MESSAGES, "");
textdomain("tails");
### initialization
POSIX::setlocale(&POSIX::LC_MESSAGES, '');
### configuration
......@@ -121,7 +121,7 @@ Notify the user about the Atom entries passed as arguments.
sub notify_user {
my @entries = @_;
my $body = gettext('This version of Tails has known security issues:') . "\n";
my $body = __('This version of Tails has known security issues:') . "\n";
for (@entries) {
$body .= '' . '<a href="' . $_->id . '">' . $_->title . '</a>' . "\n";
......@@ -132,7 +132,7 @@ sub notify_user {
exec(
qw{/usr/bin/zenity --warning},
q{--ellipsize},
q{--title}, gettext('Known security issues'),
q{--title}, __('Known security issues'),
q{--text}, $body,
);
}
......
......@@ -26,12 +26,11 @@ See https://tails.boum.org/.
use Data::Dumper;
use Desktop::Notify;
use English '-no_match_vars';
use Locale::gettext;
use POSIX;
use Locale::TextDomain 'tails';
### initialization
setlocale(LC_MESSAGES, "");
textdomain("tails");
POSIX::setlocale(&POSIX::LC_MESSAGES, '');
my $htp_done_file = '/run/htpdate/done';
my $htp_success_file = '/run/htpdate/success';
my $htp_log_file = '/var/log/htpdate.log';
......@@ -49,8 +48,8 @@ my $notify = Desktop::Notify->new()
or die "Failed creating Desktop::Notify object.";
debug('$notify:' . "\n" . Dumper($notify));
my $summary = gettext("Synchronizing the system's clock");
my $body = gettext("Tor needs an accurate clock to work properly, especially for Onion Services. Please wait...");
my $summary = __("Synchronizing the system's clock");
my $body = __("Tor needs an accurate clock to work properly, especially for Onion Services. Please wait...");
my $notification = $notify->create(summary => $summary,
body => $body,
......@@ -84,7 +83,7 @@ unless (-e $htp_success_file) {
}
$last_log .= $_;
}
my $failure_summary = gettext("Failed to synchronize the clock!");
my $failure_summary = __("Failed to synchronize the clock!");
my $failure_body = $last_log;
my $failure_notification = $notify->create(summary => $failure_summary,
body => $failure_body,
......
......@@ -25,13 +25,12 @@ See https://tails.boum.org/.
use Desktop::Notify;
use English '-no_match_vars';
use IPC::System::Simple qw{capturex $EXITVAL};
use Locale::gettext;
use Locale::TextDomain 'tails';
use Net::DBus::Reactor;
use POSIX;
### initialization
setlocale(LC_MESSAGES, "");
textdomain("tails");
POSIX::setlocale(&POSIX::LC_MESSAGES, '');
### callbacks
......@@ -68,17 +67,17 @@ my ($body, $summary);
chomp($vm_name);
if (grep {$_ eq $vm_name} @whitelist) {
$summary = gettext("Warning: virtual machine detected!");
$summary = __("Warning: virtual machine detected!");
}
else {
$summary = gettext("Warning: non-free virtual machine detected!");
$summary = __("Warning: non-free virtual machine detected!");
}
$body = gettext("Both the host operating system and the virtualization software are able to monitor what you are doing in Tails. Only free software can be considered trustworthy, for both the host operating system and the virtualization software.");
$body = __("Both the host operating system and the virtualization software are able to monitor what you are doing in Tails. Only free software can be considered trustworthy, for both the host operating system and the virtualization software.");
$notify->create(summary => $summary,
body => $body,
actions => { "moreinfo_$PID" => gettext('Learn more'), },
actions => { "moreinfo_$PID" => __('Learn more'), },
hints => { 'transient' => 1, },
timeout => 0)->show();
......
......@@ -11,6 +11,7 @@ use strictures 2;
use autodie qw(:all);
use Carp;
use Carp::Assert;
use Carp::Assert::More;
use Function::Parameters;
use Path::Tiny;
......@@ -21,10 +22,7 @@ use Try::Tiny;
use Types::Path::Tiny qw{AbsDir AbsFile AbsPath};
use Types::Standard qw(Str);
use Locale::gettext;
use POSIX;
setlocale(LC_MESSAGES, "");
textdomain("tails");
use Locale::TextDomain 'tails';
no Moo::sification;
use Moo;
......@@ -220,8 +218,8 @@ method _build_boot_block_device () {
} catch {
$self->display_error(
$self->main_window,
$self->encoding->decode(gettext(q{Error})),
$self->encoding->decode(gettext(
$self->encoding->decode(__(q{Error})),
$self->encoding->decode(__(
q{The device Tails is running from cannot be found. Maybe you used the 'toram' option?},
)),
);
......@@ -249,7 +247,7 @@ method _build_boot_drive () {
} catch {
$self->display_error(
$self->main_window,
$self->encoding->decode(gettext(
$self->encoding->decode(__(
q{The drive Tails is running from cannot be found. Maybe you used the 'toram' option?},
)),
'',
......
......@@ -22,10 +22,7 @@ use Tails::Persistence::Configuration::Presets;
use Types::Path::Tiny qw{AbsPath};
use List::MoreUtils qw{none};
use Locale::gettext;
use POSIX;
setlocale(LC_MESSAGES, "");
textdomain("tails");
use Locale::TextDomain 'tails';
use namespace::clean;
......
......@@ -20,10 +20,7 @@ use List::MoreUtils qw{all};
use Tails::Persistence::Configuration::Atom;
use Types::Standard qw(ArrayRef Str);
use Locale::gettext;
use POSIX;
setlocale(LC_MESSAGES, "");
textdomain("tails");
use Locale::TextDomain 'tails';
use namespace::clean;
......@@ -52,8 +49,8 @@ method _build__presets () {
my @presets = (
{
id => 'PersonalData',
name => $self->encoding->decode(gettext(q{Personal Data})),
description => $self->encoding->decode(gettext(
name => $self->encoding->decode(__(q{Personal Data})),
description => $self->encoding->decode(__(
q{Keep files stored in the `Persistent' directory}
)),
icon_name => 'stock_folder',
......@@ -67,8 +64,8 @@ method _build__presets () {
},
{
id => 'GreeterSettings',
name => $self->encoding->decode(gettext(q{Welcome Screen})),
description => $self->encoding->decode(gettext(
name => $self->encoding->decode(__(q{Welcome Screen})),
description => $self->encoding->decode(__(
q{Language, administration password, and additional settings}
)),
icon_name => 'preferences-system',
......@@ -82,8 +79,8 @@ method _build__presets () {
},
{
id => 'BrowserBookmarks',
name => $self->encoding->decode(gettext(q{Browser Bookmarks})),
description => $self->encoding->decode(gettext(
name => $self->encoding->decode(__(q{Browser Bookmarks})),
description => $self->encoding->decode(__(
q{Bookmarks saved in the Tor Browser}
)),
icon_name => 'user-bookmarks',
......@@ -97,8 +94,8 @@ method _build__presets () {
},
{
id => 'NetworkConnections',
name => $self->encoding->decode(gettext(q{Network Connections})),
description => $self->encoding->decode(gettext(
name => $self->encoding->decode(__(q{Network Connections})),
description => $self->encoding->decode(__(
q{Configuration of network devices and connections}
)),
icon_name => 'network-wired',
......@@ -112,8 +109,8 @@ method _build__presets () {
},
{
id => 'AdditionalSoftware',
name => $self->encoding->decode(gettext(q{Additional Software})),
description => $self->encoding->decode(gettext(
name => $self->encoding->decode(__(q{Additional Software})),
description => $self->encoding->decode(__(
q{Software installed when starting Tails}
)),
icon_name => 'package-x-generic',
......@@ -132,8 +129,8 @@ method _build__presets () {
},
{
id => 'Printers',
name => $self->encoding->decode(gettext(q{Printers})),
description => $self->encoding->decode(gettext(
name => $self->encoding->decode(__(q{Printers})),
description => $self->encoding->decode(__(
q{Printers configuration}
)),
icon_name => 'printer',
......@@ -147,8 +144,8 @@ method _build__presets () {
},
{
id => 'Thunderbird',
name => $self->encoding->decode(gettext(q{Thunderbird})),
description => $self->encoding->decode(gettext(
name => $self->encoding->decode(__(q{Thunderbird})),
description => $self->encoding->decode(__(
q{Thunderbird emails, feeds, and settings}
)),
icon_name => 'thunderbird',
......@@ -162,8 +159,8 @@ method _build__presets () {
},
{
id => 'GnuPG',
name => $self->encoding->decode(gettext(q{GnuPG})),
description => $self->encoding->decode(gettext(
name => $self->encoding->decode(__(q{GnuPG})),
description => $self->encoding->decode(__(
q{GnuPG keyrings and configuration}
)),
icon_name => 'seahorse-key',
......@@ -177,8 +174,8 @@ method _build__presets () {
},
{
id => 'BitcoinClient',
name => $self->encoding->decode(gettext(q{Bitcoin Client})),
description => $self->encoding->decode(gettext(
name => $self->encoding->decode(__(q{Bitcoin Client})),
description => $self->encoding->decode(__(
q{Electrum's bitcoin wallet and configuration}
)),
icon_name => 'electrum',
......@@ -192,8 +189,8 @@ method _build__presets () {
},
{
id => 'Pidgin',
name => $self->encoding->decode(gettext(q{Pidgin})),
description => $self->encoding->decode(gettext(
name => $self->encoding->decode(__(q{Pidgin})),
description => $self->encoding->decode(__(
q{Pidgin profiles and OTR keyring}
)),
icon_name => 'pidgin',
......@@ -207,8 +204,8 @@ method _build__presets () {
},
{
id => 'SSHClient',
name => $self->encoding->decode(gettext(q{SSH Client})),
description => $self->encoding->decode(gettext(
name => $self->encoding->decode(__(q{SSH Client})),
description => $self->encoding->decode(__(
q{SSH keys, configuration and known hosts}
)),
icon_name => 'seahorse-key-ssh',
......@@ -222,8 +219,8 @@ method _build__presets () {
},
{
id => 'Dotfiles',
name => $self->encoding->decode(gettext(q{Dotfiles})),
description => $self->encoding->decode(gettext(
name => $self->encoding->decode(__(q{Dotfiles})),
description => $self->encoding->decode(__(
q{Symlink into $HOME every file or directory found in the `dotfiles' directory}
)),
icon_name => 'preferences-desktop',
......
......@@ -22,10 +22,7 @@ Glib::Object::Introspection->setup(
package => 'Gio'
);
use Locale::gettext;
use POSIX;
setlocale(LC_MESSAGES, "");
textdomain("tails");
use Locale::TextDomain 'tails';
use Moo;
use MooX::late;
......@@ -110,7 +107,7 @@ has 'configuration_app_desktop_id' => (
=cut
method _build_name () {
$self->encoding->decode(gettext('Custom'));
$self->encoding->decode(__('Custom'));
}
method _build_id () {
......
......@@ -14,10 +14,7 @@ use Function::Parameters;
use Glib qw{TRUE FALSE};
use Gtk3 qw{-init};
use Locale::gettext;
use POSIX;
setlocale(LC_MESSAGES, "");
textdomain("tails");
use Locale::TextDomain 'tails';
use Moo::Role;
use MooX::late;
......
......@@ -33,11 +33,6 @@ use Tails::Persistence::Step::Configure;
use Tails::Persistence::Step::Delete;
use Tails::Persistence::Utils qw{align_up_at_2MiB align_down_at_2MiB step_name_to_class_name get_variable_from_file check_config_file_permissions};
use Locale::gettext;
use POSIX;
setlocale(LC_MESSAGES, "");
textdomain("tails");
no Moo::sification;
use Moo;
use MooX::late;
......@@ -49,8 +44,24 @@ with 'Tails::Role::HasEncoding';
use namespace::clean;
# Must be after namespace::clean, so that we can use "around" for the "__"
# function.
use Locale::TextDomain 'tails';
POSIX::setlocale(&POSIX::LC_MESSAGES, '');
use MooX::Options;
# Workaround the fact MooX::Options is incompatible with Locale::TextDomain
# (it needs a __ method, which it injects via MooX::Locale::Passthrough,
# but that does not go well when Locale::TextDomain is loaded).
around __ => sub {
my $orig = shift;
# if called as a class or object method,
# let's ignore the second argument ($self)
shift if ref $_[0] or $_[0] eq __PACKAGE__;
my $msgid = shift;
Locale::TextDomain::__($msgid);
};
=head1 ATTRIBUTES
......@@ -262,7 +273,7 @@ method _build_steps () {
method _build_main_window () {
my $win = Gtk3::Window->new('toplevel');
$win->set_title($self->encoding->decode(gettext('Setup Tails persistent volume')));
$win->set_title($self->encoding->decode(__('Setup Tails persistent volume')));
$win->set_border_width(10);
......@@ -340,8 +351,8 @@ method _build_configuration () {
catch {
$self->display_error(
$self->main_window,
$self->encoding->decode(gettext('Error')),
$self->encoding->decode(gettext(
$self->encoding->decode(__('Error')),
$self->encoding->decode(__(
$_,
)));
exit 4;
......@@ -368,58 +379,52 @@ method check_sanity (Str $step_name) {
'bootstrap' => [
{
method => 'device_has_persistent_volume',
message => $self->encoding->decode(gettext(
"Device %s already has a persistent volume.")),
message => __"Device already has a persistent volume.",
must_be_false => 1,
can_be_forced => 1,
needs_device_arg => 1,
},
{
method => 'device_has_enough_free_space',
message => $self->encoding->decode(gettext(
"Device %s has not enough unallocated space.")),
message => __"Device has not enough unallocated space.",
},
],
'delete' => [
{
method => 'device_has_persistent_volume',
message => $self->encoding->decode(gettext(
"Device %s has no persistent volume.")),
message => __"Device has no persistent volume.",
needs_device_arg => 1,
},
{
method => 'persistence_is_enabled',
message => $self->encoding->decode(gettext(
"Cannot delete the persistent volume on %s while in use. You should restart Tails without persistence.")),
message =>
__"Cannot delete the persistent volume while in use. You should restart Tails without persistence.",
must_be_false => 1,
},
],
'configure' => [
{
method => 'device_has_persistent_volume',
message => $self->encoding->decode(gettext(
"Device %s has no persistent volume.")),
message => __"Device has no persistent volume.",
needs_device_arg => 1,
},
{
method => 'persistence_partition_is_unlocked',
message => $self->encoding->decode(gettext(
"Persistence volume on %s is not unlocked.")),
message => __"Persistence volume is not unlocked.",
},
{
method => 'persistence_filesystem_is_mounted',
message => $self->encoding->decode(gettext(
"Persistence volume on %s is not mounted.")),
message => __"Persistence volume is not mounted.",
},
{
method => 'persistence_filesystem_is_readable',
message => $self->encoding->decode(gettext(
"Persistence volume on %s is not readable. Permissions or ownership problems?")),
message =>
__"Persistence volume is not readable. Permissions or ownership problems?",
},
{
method => 'persistence_filesystem_is_writable',
message => $self->encoding->decode(gettext(
"Persistence volume on %s is not writable.")),
message =>
__"Persistence volume is not writable.",
},
],
);
......@@ -427,21 +432,20 @@ method check_sanity (Str $step_name) {
my @checks = (
{
method => 'drive_is_connected_via_a_supported_interface',
message => $self->encoding->decode(gettext(
"Tails is running from non-USB / non-SDIO device %s.")),
message =>
__"Tails is running from non-USB / non-SDIO device.",
needs_drive_arg => 1,
},
{
method => 'drive_is_optical',
message => $self->encoding->decode(gettext(
"Device %s is optical.")),
message => __"Device is optical.",
must_be_false => 1,
needs_drive_arg => 1,
},
{
method => 'started_from_device_installed_with_tails_installer',
message => $self->encoding->decode(gettext(
"Device %s was not created using a USB image or Tails Installer.")),
message =>
__"Device was not created using a USB image or Tails Installer.",
must_be_false => 0,
},
);
......@@ -468,9 +472,7 @@ method check_sanity (Str $step_name) {
$res = ! $res;
}
if (! $res) {
my $message = $self->encoding->decode(sprintf(
gettext($check->{message}),
$self->boot_device_file));
my $message = $self->encoding->decode($check->{message});
if ($self->force && exists($check->{can_be_forced}) && $check->{can_be_forced}) {
say STDERR "$message",
"... but --force is enabled, ignoring results of this sanity check.";
......@@ -478,7 +480,7 @@ method check_sanity (Str $step_name) {
else {
$self->display_error(
$self->main_window,
$self->encoding->decode(gettext('Error')),
$self->encoding->decode(__('Error')),
$message
);
return;
......@@ -684,10 +686,10 @@ method goto_next_step () {
return;
}
}
$self->current_step->title->set_text($self->encoding->decode(gettext(
$self->current_step->title->set_text($self->encoding->decode(__(
q{Persistence wizard - Finished}
)));
$self->current_step->subtitle->set_text($self->encoding->decode(gettext(
$self->current_step->subtitle->set_text($self->encoding->decode(__(
q{Any changes you have made will only take effect after restarting Tails.
You may now close this application.}
......
......@@ -16,10 +16,7 @@ use IPC::System::Simple qw{systemx};
use Number::Format qw(:subs);
use Types::Standard qw(HashRef);
use Locale::gettext;
use POSIX;
setlocale(LC_MESSAGES, "");
textdomain("tails");
use Locale::TextDomain 'tails';
use Moo;
use MooX::late;
......@@ -92,20 +89,19 @@ has 'passphrase_check_button' => (
=cut
method BUILD (@args) {
$self->title->set_text($self->encoding->decode(gettext(
$self->title->set_text($self->encoding->decode(__(
q{Persistence wizard - Persistent volume creation}
)));
$self->subtitle->set_text($self->encoding->decode(gettext(
$self->subtitle->set_text($self->encoding->decode(__(
q{Choose a passphrase to protect the persistent volume}
)));
$self->description->set_markup($self->encoding->decode(sprintf(
# TRANSLATORS: size, device vendor, device model
gettext(q{A %s persistent volume will be created on the <b>%s %s</b> device. Data on this volume will be stored in an encrypted form protected by a passphrase.}),
format_bytes($self->size_of_free_space, mode => "iec"),
$self->drive_vendor,
$self->drive_model,
$self->description->set_markup($self->encoding->decode(__x(
q{A {size} persistent volume will be created on the <b>{vendor} {model}</b> device. Data on this volume will be stored in an encrypted form protected by a passphrase.},
size => format_bytes($self->size_of_free_space, mode => "iec"),
vendor => $self->drive_vendor,
model => $self->drive_model,
)));
$self->go_button->set_label($self->encoding->decode(gettext(q{Create})));
$self->go_button->set_label($self->encoding->decode(__(q{Create})));
}
method _build_main_widget () {
......@@ -147,7 +143,7 @@ method _build_intro () {
$intro->set_line_wrap_mode('word');
$intro->set_single_line_mode(FALSE);
$intro->set_max_width_chars(72);
$intro->set_markup($self->encoding->decode(gettext(
$intro->set_markup($self->encoding->decode(__(
q{<b>Beware!</b> Using persistence has consequences that must be well understood. Tails can't help you if you use it wrong! See the <i>Encrypted persistence</i> page of the Tails documentation to learn more.}
)));
......@@ -175,7 +171,7 @@ method _build_warning_area () {
}
method _build_label () {
my $label = Gtk3::Label->new($self->encoding->decode(gettext(
my $label = Gtk3::Label->new($self->encoding->decode(__(
q{Passphrase:}
)));
$label->set_alignment(0.0, 0.5);
......@@ -183,7 +179,7 @@ method _build_label () {
}
method _build_verify_label () {
my $label = Gtk3::Label->new($self->encoding->decode(gettext(
my $label = Gtk3::Label->new($self->encoding->decode(__(
q{Verify Passphrase:}
)));
$label->set_alignment(0.0, 0.5);
......@@ -195,7 +191,7 @@ method _build_warning_label () {
$label->set_padding(10, 0);
$label->set_markup(
"<i>"
. $self->encoding->decode(gettext(q{Passphrase can't be empty}))
. $self->encoding->decode(__(q{Passphrase can't be empty}))