aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Whitaker <mageia@martin-whitaker.me.uk>2024-01-21 17:21:05 +0000
committerMartin Whitaker <mageia@martin-whitaker.me.uk>2024-01-21 19:50:43 +0000
commit51f5991e35c8d5e384c6b642042132b7a2238d07 (patch)
tree7f1a059d9faef3bc154d0cdde8def34d0b2cbb2c
parent238402069f07fc90d274b291fa8df967ae74c620 (diff)
downloadqarepo-51f5991e35c8d5e384c6b642042132b7a2238d07.tar
qarepo-51f5991e35c8d5e384c6b642042132b7a2238d07.tar.gz
qarepo-51f5991e35c8d5e384c6b642042132b7a2238d07.tar.bz2
qarepo-51f5991e35c8d5e384c6b642042132b7a2238d07.tar.xz
qarepo-51f5991e35c8d5e384c6b642042132b7a2238d07.zip
Convert UTF-8 strings returned by gettext to native Perl strings.
Sadly libintl-perl doesn't take care of this for us. Also remove the call to setlocale, which doesn't appear to be needed.
-rw-r--r--po/Makefile2
-rw-r--r--qarepo111
2 files changed, 59 insertions, 54 deletions
diff --git a/po/Makefile b/po/Makefile
index bc6abc5..5aeda3c 100644
--- a/po/Makefile
+++ b/po/Makefile
@@ -17,7 +17,7 @@ all: $(MOFILES)
update: $(NAME).pot
$(NAME).pot: $(PL_FILE) $(DT_FILE)
- xgettext --language=perl --keyword=__ --add-comments=PO: --output tmp1.pot $(PL_FILE)
+ xgettext --language=perl --keyword=N --add-comments=PO: --output tmp1.pot $(PL_FILE)
intltool-update --pot --gettext-package tmp2
msgcat --use-first tmp1.pot tmp2.pot > $@
@rm -r tmp*.pot
diff --git a/qarepo b/qarepo
index 7006a88..734f5ce 100644
--- a/qarepo
+++ b/qarepo
@@ -1,6 +1,6 @@
#!/usr/bin/perl
-# Copyright (C) 2018-2023 Mageia
+# Copyright (C) 2018-2024 Mageia
# Martin Whitaker <mageia@martin-whitaker.me.uk>
#
# This program is free software; you can redistribute it and/or modify
@@ -22,25 +22,22 @@ use warnings;
use Glib qw(TRUE FALSE);
use Gtk3 '-init';
-use Locale::Messages qw(LC_MESSAGES);
use Locale::TextDomain qw(qarepo);
use MDK::Common;
-use POSIX qw(setlocale);
use URPM;
+use utf8;
my $version = '(devel)';
-setlocale(LC_MESSAGES, '');
-
###############################################################################
# States and Status
###############################################################################
my %status_text = (
- disabled => __"Disabled",
- enabled => __"Enabled",
- changed => __"Needs update",
- failed => __"Update failed"
+ disabled => N("Disabled"),
+ enabled => N("Enabled"),
+ changed => N("Needs update"),
+ failed => N("Update failed")
);
my $state;
@@ -86,7 +83,7 @@ my $active_qa_repo;
my $last_release = $release;
my $last_arch = '';
-my $fatal_message = __"*** application will terminate ***";
+my $fatal_message = N("*** application will terminate ***");
my $fatal_error;
###############################################################################
@@ -97,40 +94,40 @@ my $window = Gtk3::Window->new('toplevel');
my $grid = Gtk3::Grid->new();
-my $label1 = Gtk3::Label->new(__"Mirror:");
+my $label1 = Gtk3::Label->new(N("Mirror:"));
my $entry1 = Gtk3::Entry->new();
-my $label2 = Gtk3::Label->new(__"Release:");
+my $label2 = Gtk3::Label->new(N("Release:"));
my $entry2 = Gtk3::Entry->new();
-my $label3 = Gtk3::Label->new(__"QA Repo:");
+my $label3 = Gtk3::Label->new(N("QA Repo:"));
my $entry3 = Gtk3::Entry->new();
# PO: abbreviation of "architecture", e.g. i586, x86_64
-my $label4 = Gtk3::Label->new(__"Arch:");
+my $label4 = Gtk3::Label->new(N("Arch:"));
my $entry4 = Gtk3::ComboBoxText->new();
-my $label5 = Gtk3::Label->new(__"RPMs:");
+my $label5 = Gtk3::Label->new(N("RPMs:"));
my $entry5 = Gtk3::TextView->new();
my $scroll = Gtk3::ScrolledWindow->new();
-my $label6 = Gtk3::Label->new(__"Status:");
+my $label6 = Gtk3::Label->new(N("Status:"));
my $status = Gtk3::Label->new('');
-my $button1 = Gtk3::Button->new(__"Quit");
-my $button2 = Gtk3::Button->new(__"Disable");
-my $button3 = Gtk3::Button->new(__"Enable");
-my $button4 = Gtk3::Button->new(__"Clear");
-my $button5 = Gtk3::Button->new(__"Downgrade");
+my $button1 = Gtk3::Button->new(N("Quit"));
+my $button2 = Gtk3::Button->new(N("Disable"));
+my $button3 = Gtk3::Button->new(N("Enable"));
+my $button4 = Gtk3::Button->new(N("Clear"));
+my $button5 = Gtk3::Button->new(N("Downgrade"));
my $check0 = Gtk3::CheckButton->new_with_label("core");
my $check1 = Gtk3::CheckButton->new_with_label("nonfree");
my $check2 = Gtk3::CheckButton->new_with_label("tainted");
-my $check3 = Gtk3::CheckButton->new_with_label(__"fuzzy\nversion");
+my $check3 = Gtk3::CheckButton->new_with_label(N("fuzzy\nversion"));
# PO: abbreviation of "add dependencies"
-my $check4 = Gtk3::CheckButton->new_with_label(__"add\ndeps");
+my $check4 = Gtk3::CheckButton->new_with_label(N("add\ndeps"));
$window->set_title("QA Repo $version");
$window->set_default_size(600, 400);
@@ -251,7 +248,7 @@ my $dialogue_text = Gtk3::TextView->new();
my $dialogue_scroll = Gtk3::ScrolledWindow->new();
-my $dialogue_button = Gtk3::Button->new(__"Dismiss");
+my $dialogue_button = Gtk3::Button->new(N("Dismiss"));
$dialogue_window->set_default_size(600, 300);
$dialogue_window->set_border_width(10);
@@ -328,7 +325,7 @@ sub disable {
}
sub enable {
- check_no_testing_media(__"This may enable unwanted packages to be installed.")
+ check_no_testing_media(N("This may enable unwanted packages to be installed."))
or return;
disable_buttons();
get_settings();
@@ -355,7 +352,7 @@ sub clear {
}
sub downgrade {
- check_no_testing_media(__"This may stop some packages from being downgraded.")
+ check_no_testing_media(N("This may stop some packages from being downgraded."))
or return;
disable_buttons();
if ($active_qa_repo) {
@@ -380,8 +377,8 @@ sub dialogue_dismiss {
sub check_no_testing_media {
my ($message2) = @_;
if (system("urpmq --list-media active --list-url | grep -q updates_testing") == 0) {
- my $message1 = __"Some updates_testing media are enabled.";
- my $message3 = __"Please disable these media and try again.";
+ my $message1 = N("Some updates_testing media are enabled.");
+ my $message3 = N("Please disable these media and try again.");
show_error_dialogue(($message1, $message2, $message3));
return 0;
}
@@ -414,9 +411,9 @@ sub set_state {
$button4->set_sensitive(TRUE);
$button5->set_sensitive($state ne 'changed');
if ($state eq 'changed' || $state eq 'failed') {
- $button3->set_label(__"Update");
+ $button3->set_label(N("Update"));
} else {
- $button3->set_label(__"Enable");
+ $button3->set_label(N("Enable"));
}
}
@@ -467,7 +464,7 @@ sub disable_repo {
if (system("$pkexec /usr/libexec/qarepo-helper disable $arch_type") == 0) {
$active_qa_repo = '';
} else {
- my $message = __"couldn't disable the local repository ['" . $qa_repo_name . "']";
+ my $message = N("couldn't disable the local repository ['") . $qa_repo_name . "']";
show_error_dialogue($message, $fatal_message);
print_error($message, 'fatal');
}
@@ -478,7 +475,7 @@ sub enable_repo {
if (system("$pkexec /usr/libexec/qarepo-helper enable $arch_type $qa_repo/$arch") == 0) {
$active_qa_repo = $qa_repo;
} else {
- my $message = __"couldn't enable the local repository ['" . $qa_repo_name . "']";
+ my $message = N("couldn't enable the local repository ['") . $qa_repo_name . "']";
show_error_dialogue($message);
print_error($message);
$active_qa_repo = '';
@@ -488,7 +485,7 @@ sub enable_repo {
sub update_repo {
my $arch_type = $arch eq 'x86_64' ? '64' : '32';
if (system("$pkexec /usr/libexec/qarepo-helper update $arch_type") != 0) {
- my $message = __"couldn't update the local repository ['" . $qa_repo_name . "']";
+ my $message = N("couldn't update the local repository ['") . $qa_repo_name . "']";
show_error_dialogue($message);
print_error($message);
disable_repo();
@@ -500,7 +497,7 @@ sub clear_repo {
my @existing_rpms = grep { $_ =~ /$type/ } get_existing_rpms();
if (@existing_rpms) {
if (!unlink(map { "$qa_repo/$arch/$_" } @existing_rpms)) {
- my $message = __"couldn't delete existing RPMs in the local repository";
+ my $message = N("couldn't delete existing RPMs in the local repository");
show_error_dialogue($message, $fatal_message);
print_error($message, 'fatal');
}
@@ -510,7 +507,7 @@ sub clear_repo {
my @sync_errors;
sub sync_repo {
- $status->set_label(__"Updating");
+ $status->set_label(N("Updating"));
@sync_errors = ();
my $sync_file;
@@ -521,7 +518,7 @@ sub sync_repo {
} elsif ($mirror !~ /^\w+:/) {
$sync_file = \&sync_file_link;
} else {
- my $message = __"unsupported mirror URL type";
+ my $message = N("unsupported mirror URL type");
show_error_dialogue($message);
print_error($message);
return 0;
@@ -570,7 +567,7 @@ sub sync_repo {
});
if (!unlink("$download_dir/$synthesis")) {
- my $message = __"couldn't delete the downloaded synthesis file [" . $download_dir . '/' . $synthesis . "]";
+ my $message = N("couldn't delete the downloaded synthesis file [") . $download_dir . '/' . $synthesis . "]";
show_error_dialogue($message, $fatal_message);
print_error($message, 'fatal');
}
@@ -590,7 +587,7 @@ sub sync_repo {
$matched = 1;
}
}
- $matched or sync_error($request . __" was not found in the remote repository");
+ $matched or sync_error($request . N(" was not found in the remote repository"));
}
# avoid infinite loop if we haven't found a match
last if @sync_errors;
@@ -616,7 +613,7 @@ sub sync_repo {
my $old_pubkey = "$local_repo/media_info/pubkey";
if (-e $old_pubkey) {
if (!unlink($old_pubkey)) {
- my $message = __"couldn't delete the old pubkey in the local repository";
+ my $message = N("couldn't delete the old pubkey in the local repository");
show_error_dialogue($message, $fatal_message);
print_error($message, 'fatal');
}
@@ -641,10 +638,10 @@ sub sync_repo {
gtk_update();
if (@sync_errors) {
- print_error(__"failed to download all the files");
+ print_error(N("failed to download all the files"));
} else {
system("genhdlist2 --allow-empty-media $local_repo") == 0
- or sync_error(__"failed to update hdlist");
+ or sync_error(N("failed to update hdlist"));
}
if (@sync_errors) {
@@ -657,14 +654,14 @@ sub sync_repo {
sub sync_file_rsync {
my ($src_url, $dst_dir) = @_;
- print __"fetching " . $src_url . "\n";
+ print N("fetching ") . $src_url . "\n";
system("rsync -q $src_url $dst_dir") == 0
- or sync_error(__"failed to download file [" . $src_url . "]");
+ or sync_error(N("failed to download file [") . $src_url . "]");
}
sub sync_file_aria2 {
my ($src_url, $dst_dir) = @_;
- print __"fetching " . $src_url . "\n";
+ print N("fetching ") . $src_url . "\n";
system("aria2c -q -d $dst_dir $src_url") == 0
and return 1;
@@ -672,13 +669,13 @@ sub sync_file_aria2 {
my $dst_file = $dst_dir . '/' . basename($src_url);
unlink($dst_file) if -e $dst_file;
- sync_error(__"failed to download file [" . $src_url . "]");
+ sync_error(N("failed to download file [") . $src_url . "]");
}
sub sync_file_link {
my ($src_file, $dst_dir) = @_;
-e $src_file && symlink($src_file, $dst_dir . '/' . basename($src_file))
- or sync_error(__"failed to link to file [" . $src_file . "]");
+ or sync_error(N("failed to link to file [") . $src_file . "]");
}
sub sync_error {
@@ -691,7 +688,7 @@ sub sync_error {
sub downgrade_packages {
my $synthesis = "$qa_repo/$arch/media_info/synthesis.hdlist.cz";
if (! -e $synthesis) {
- my $message = __"no synthesis file found in the local repository";
+ my $message = N("no synthesis file found in the local repository");
show_error_dialogue($message);
print_error($message);
return 0;
@@ -712,7 +709,7 @@ sub downgrade_packages {
@packages = sort @packages;
show_downgrade_dialogue("urpmi --downgrade @packages");
} else {
- show_error_dialogue(__"none of the listed packages are installed");
+ show_error_dialogue(N("none of the listed packages are installed"));
}
}
@@ -733,16 +730,16 @@ sub wildcard_to_regexp {
}
sub show_downgrade_dialogue {
- $dialogue_window->set_title(__"Downgrade");
- $dialogue_label->set_text(__"The following command may be used to downgrade the listed packages:");
+ $dialogue_window->set_title(N("Downgrade"));
+ $dialogue_label->set_text(N("The following command may be used to downgrade the listed packages:"));
$dialogue_text->get_buffer()->set_text(join("\n", @_));
$dialogue_text->set_wrap_mode('GTK_WRAP_WORD_CHAR');
$dialogue_window->show_all();
}
sub show_error_dialogue {
- $dialogue_window->set_title(__"Error");
- $dialogue_label->set_text(__"The following error(s) occurred:");
+ $dialogue_window->set_title(N("Error"));
+ $dialogue_label->set_text(N("The following error(s) occurred:"));
$dialogue_text->get_buffer()->set_text(join("\n", @_));
$dialogue_text->set_wrap_mode('GTK_WRAP_NONE');
$dialogue_window->show_all();
@@ -750,7 +747,7 @@ sub show_error_dialogue {
sub print_error {
my ($message, $o_fatal) = @_;
- print __"ERROR: " . $message . ".\n";
+ print N("ERROR: ") . $message . ".\n";
$fatal_error = $o_fatal;
}
@@ -759,3 +756,11 @@ sub gtk_update {
Gtk3::main_iteration();
}
}
+
+# Use gettext to translate the text. Assume the returned string is UTF-8.
+sub N {
+ my ($text) = @_;
+ my $str = __($text);
+ utf8::decode($str);
+ $str;
+}