From 8d750ce02f00531871737e8afeb2805af6e221a3 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sat, 4 Nov 2023 17:42:08 +0000 Subject: Add support for i18n. --- Makefile | 5 +- po/Makefile | 32 +++++++++ po/POTFILES.in | 1 + po/qarepo.pot | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qarepo | 107 +++++++++++++++-------------- qarepo.desktop | 8 --- qarepo.desktop.in | 9 +++ 7 files changed, 304 insertions(+), 60 deletions(-) create mode 100644 po/Makefile create mode 100644 po/POTFILES.in create mode 100644 po/qarepo.pot delete mode 100644 qarepo.desktop create mode 100644 qarepo.desktop.in diff --git a/Makefile b/Makefile index c33f1e7..394163f 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,11 @@ NAME = qarepo -VERSION = 1.6 +VERSION = 1.7 DESTDIR= all: + make -C po + intltool-merge --utf8 po qarepo.desktop.in qarepo.desktop -d -u -c intltool-merge-cache sed -i "s/version = '.*';/version = 'v${VERSION}';/" qarepo check: @@ -20,6 +22,7 @@ install: install -m 0644 qarepo.desktop $(DESTDIR)/usr/share/applications install -m 0644 org.mageia.qarepo-helper.policy $(DESTDIR)/usr/share/polkit-1/actions install -m 0644 org.mageia.qarepo-helper.rules $(DESTDIR)/usr/share/polkit-1/rules.d + make -c po install dist: @git archive --prefix=$(NAME)-$(VERSION)/ HEAD | xz > $(NAME)-$(VERSION).tar.xz; diff --git a/po/Makefile b/po/Makefile new file mode 100644 index 0000000..d8bc7c9 --- /dev/null +++ b/po/Makefile @@ -0,0 +1,32 @@ +NAME = qarepo + +localedir = ${prefix}/share/locale + +PL_FILE = ../$(NAME) +DT_FILE = ../$(NAME).desktop.in + +POFILES = $(wildcard *.po) +MOFILES = $(POFILES:%.po=%.mo) +LANGS = $(POFILES:%.po=%) + +all: $(NAME).pot $(POFILES) $(MOFILES) + +%.mo: %.po + msgfmt -o $@ $< + +update: $(NAME).pot + +$(NAME).pot: $(PL_FILE) $(DT_FILE) + xgettext --language=perl --keyword=__ --output tmp1.pot $(PL_FILE) + intltool-update --pot --gettext-package tmp2 + msgcat --use-first tmp1.pot tmp2.pot > $@ + @rm -r tmp*.pot + +install: all + for l in $(LANGS); do \ + install -d $(localedir)/$$l/LC_MESSAGES; \ + install -m 644 $$l.mo $(localedir)/$$l/LC_MESSAGES/$(NAME).mo; \ + done + +clean: + @rm -rf *.mo $(POFILES:%=%t) diff --git a/po/POTFILES.in b/po/POTFILES.in new file mode 100644 index 0000000..91d6cca --- /dev/null +++ b/po/POTFILES.in @@ -0,0 +1 @@ +qarepo.desktop.in diff --git a/po/qarepo.pot b/po/qarepo.pot new file mode 100644 index 0000000..1459480 --- /dev/null +++ b/po/qarepo.pot @@ -0,0 +1,202 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-11-04 17:40+0000\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: ../qarepo:40 +msgid "Disabled" +msgstr "" + +#: ../qarepo:41 +msgid "Enabled" +msgstr "" + +#: ../qarepo:42 +msgid "Needs update" +msgstr "" + +#: ../qarepo:43 +msgid "Update failed" +msgstr "" + +#: ../qarepo:89 +msgid "*** application will terminate ***" +msgstr "" + +#: ../qarepo:100 +msgid "Mirror:" +msgstr "" + +#: ../qarepo:103 +msgid "Release:" +msgstr "" + +#: ../qarepo:106 +msgid "QA Repo:" +msgstr "" + +#: ../qarepo:109 +msgid "Arch:" +msgstr "" + +#: ../qarepo:112 +msgid "RPMs:" +msgstr "" + +#: ../qarepo:117 +msgid "Status:" +msgstr "" + +#: ../qarepo:120 +msgid "Quit" +msgstr "" + +#: ../qarepo:121 +msgid "Disable" +msgstr "" + +#: ../qarepo:122 ../qarepo:417 +msgid "Enable" +msgstr "" + +#: ../qarepo:123 +msgid "Clear" +msgstr "" + +#: ../qarepo:124 ../qarepo:734 +msgid "Downgrade" +msgstr "" + +#: ../qarepo:130 +msgid "" +"fuzzy\n" +"version" +msgstr "" + +#: ../qarepo:131 +msgid "" +"add\n" +"deps" +msgstr "" + +#: ../qarepo:252 +msgid "Dismiss" +msgstr "" + +#: ../qarepo:329 +msgid "This may enable unwanted packages to be installed." +msgstr "" + +#: ../qarepo:356 +msgid "This may stop some packages from being downgraded." +msgstr "" + +#: ../qarepo:381 +msgid "Some updates_testing media are enabled." +msgstr "" + +#: ../qarepo:382 +msgid "Please disable these media and try again." +msgstr "" + +#: ../qarepo:415 +msgid "Update" +msgstr "" + +#: ../qarepo:468 +msgid "couldn't disable the local repository ['" +msgstr "" + +#: ../qarepo:479 +msgid "couldn't enable the local repository ['" +msgstr "" + +#: ../qarepo:489 +msgid "couldn't update the local repository ['" +msgstr "" + +#: ../qarepo:501 +msgid "couldn't delete existing RPMs in the local repository" +msgstr "" + +#: ../qarepo:511 +msgid "Updating" +msgstr "" + +#: ../qarepo:522 +msgid "unsupported mirror URL type" +msgstr "" + +#: ../qarepo:571 +msgid "couldn't delete the downloaded synthesis file [" +msgstr "" + +#: ../qarepo:591 +msgid " was not found in the remote repository" +msgstr "" + +#: ../qarepo:617 +msgid "couldn't delete the old pubkey in the local repository" +msgstr "" + +#: ../qarepo:642 +msgid "failed to download all the files" +msgstr "" + +#: ../qarepo:645 +msgid "failed to update hdlist" +msgstr "" + +#: ../qarepo:658 ../qarepo:665 +msgid "fetching " +msgstr "" + +#: ../qarepo:660 ../qarepo:673 +msgid "failed to download file [" +msgstr "" + +#: ../qarepo:679 +msgid "failed to link to file [" +msgstr "" + +#: ../qarepo:692 +msgid "no synthesis file found in the local repository" +msgstr "" + +#: ../qarepo:713 +msgid "none of the listed packages are installed" +msgstr "" + +#: ../qarepo:735 +msgid "The following command may be used to downgrade the listed packages:" +msgstr "" + +#: ../qarepo:742 +msgid "Error" +msgstr "" + +#: ../qarepo:743 +msgid "The following error(s) occurred:" +msgstr "" + +#: ../qarepo:751 +msgid "ERROR: " +msgstr "" + +#: ../qarepo.desktop.in.h:1 +msgid "Tool for creating a local testing repository" +msgstr "" diff --git a/qarepo b/qarepo index 4c120ec..91f2338 100644 --- a/qarepo +++ b/qarepo @@ -1,7 +1,7 @@ #!/usr/bin/perl -# Copyright (C) 2018 Mageia -# Martin Whitaker +# Copyright (C) 2018-2023 Mageia +# Martin Whitaker # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,20 +22,25 @@ 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; my $version = '(devel)'; +setlocale(LC_MESSAGES, ''); + ############################################################################### # States and Status ############################################################################### my %status_text = ( - disabled => 'Disabled', - enabled => 'Enabled', - changed => 'Needs update', - failed => 'Update failed' + disabled => __"Disabled", + enabled => __"Enabled", + changed => __"Needs update", + failed => __"Update failed" ); my $state; @@ -81,7 +86,7 @@ my $active_qa_repo; my $last_release = $release; my $last_arch = ''; -my $fatal_message = '*** application will terminate ***'; +my $fatal_message = __"*** application will terminate ***"; my $fatal_error; ############################################################################### @@ -92,38 +97,38 @@ my $window = Gtk3::Window->new('toplevel'); my $grid = Gtk3::Grid->new(); -my $label1 = Gtk3::Label->new('Mirror:'); +my $label1 = Gtk3::Label->new(__"Mirror:"); my $entry1 = Gtk3::Entry->new(); -my $label2 = Gtk3::Label->new('Release:'); +my $label2 = Gtk3::Label->new(__"Release:"); my $entry2 = Gtk3::Entry->new(); -my $label3 = Gtk3::Label->new('QA Repo:'); +my $label3 = Gtk3::Label->new(__"QA Repo:"); my $entry3 = Gtk3::Entry->new(); -my $label4 = Gtk3::Label->new('Arch:'); +my $label4 = Gtk3::Label->new(__"Arch:"); my $entry4 = Gtk3::ComboBoxText->new(); -my $label5 = Gtk3::Label->new('RPMs:'); +my $label5 = Gtk3::Label->new(__"RPMs:"); my $entry5 = Gtk3::TextView->new(); my $scroll = Gtk3::ScrolledWindow->new(); -my $label6 = Gtk3::Label->new('Status:'); +my $label6 = Gtk3::Label->new(__"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(__"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 $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 $check4 = Gtk3::CheckButton->new_with_label("add\ndeps"); +my $check3 = Gtk3::CheckButton->new_with_label(__"fuzzy\nversion"); +my $check4 = Gtk3::CheckButton->new_with_label(__"add\ndeps"); $window->set_title("QA Repo $version"); $window->set_default_size(600, 400); @@ -244,7 +249,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(__"Dismiss"); $dialogue_window->set_default_size(600, 300); $dialogue_window->set_border_width(10); @@ -321,7 +326,7 @@ sub disable { } sub enable { - check_no_testing_media("This may enable unwanted packages to be installed.") + check_no_testing_media(__"This may enable unwanted packages to be installed.") or return; disable_buttons(); get_settings(); @@ -348,7 +353,7 @@ sub clear { } sub downgrade { - check_no_testing_media("This may stop some packages from being downgraded.") + check_no_testing_media(__"This may stop some packages from being downgraded.") or return; disable_buttons(); if ($active_qa_repo) { @@ -373,8 +378,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 = __"Some updates_testing media are enabled."; + my $message3 = __"Please disable these media and try again."; show_error_dialogue(($message1, $message2, $message3)); return 0; } @@ -407,9 +412,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(__"Update"); } else { - $button3->set_label('Enable'); + $button3->set_label(__"Enable"); } } @@ -460,7 +465,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 $qa_repo_name media"; + my $message = __"couldn't disable the local repository ['" . $qa_repo_name . "']"; show_error_dialogue($message, $fatal_message); print_error($message, 'fatal'); } @@ -471,7 +476,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 $qa_repo_name media"; + my $message = __"couldn't enable the local repository ['" . $qa_repo_name . "']"; show_error_dialogue($message); print_error($message); $active_qa_repo = ''; @@ -481,7 +486,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 $qa_repo_name media"; + my $message = __"couldn't update the local repository ['" . $qa_repo_name . "']"; show_error_dialogue($message); print_error($message); disable_repo(); @@ -493,7 +498,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 QA repo"; + my $message = __"couldn't delete existing RPMs in the local repository"; show_error_dialogue($message, $fatal_message); print_error($message, 'fatal'); } @@ -503,7 +508,7 @@ sub clear_repo { my @sync_errors; sub sync_repo { - $status->set_label('Updating'); + $status->set_label(__"Updating"); @sync_errors = (); my $sync_file; @@ -514,7 +519,7 @@ sub sync_repo { } elsif ($mirror !~ /^\w+:/) { $sync_file = \&sync_file_link; } else { - my $message = "unsupported mirror URL type"; + my $message = __"unsupported mirror URL type"; show_error_dialogue($message); print_error($message); return 0; @@ -563,7 +568,7 @@ sub sync_repo { }); if (!unlink("$download_dir/$synthesis")) { - my $message = "couldn't delete $download_dir/$synthesis in the QA repo"; + my $message = __"couldn't delete the downloaded synthesis file [" . $download_dir . '/' . $synthesis . "]"; show_error_dialogue($message, $fatal_message); print_error($message, 'fatal'); } @@ -583,7 +588,7 @@ sub sync_repo { $matched = 1; } } - $matched or sync_error("$request not found in the remote repository"); + $matched or sync_error($request . __" was not found in the remote repository"); } # avoid infinite loop if we haven't found a match last if @sync_errors; @@ -601,7 +606,7 @@ sub sync_repo { my @unwanted_rpms = difference2(\@existing_rpms, \@required_rpms); if (@unwanted_rpms) { if (!unlink(map { "$local_repo/$_" } @unwanted_rpms)) { - my $message = "couldn't delete unwanted RPMs in the QA repo"; + my $message = "couldn't delete unwanted RPMs in the local repository"; show_error_dialogue($message, $fatal_message); print_error($message, 'fatal'); } @@ -609,7 +614,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 old pubkey in the QA repo"; + my $message = __"couldn't delete the old pubkey in the local repository"; show_error_dialogue($message, $fatal_message); print_error($message, 'fatal'); } @@ -634,10 +639,10 @@ sub sync_repo { gtk_update(); if (@sync_errors) { - print_error('failed to download all the files'); + print_error(__"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(__"failed to update hdlist"); } if (@sync_errors) { @@ -650,14 +655,14 @@ sub sync_repo { sub sync_file_rsync { my ($src_url, $dst_dir) = @_; - print "fetching $src_url\n"; + print __"fetching " . $src_url . "\n"; system("rsync -q $src_url $dst_dir") == 0 - or sync_error("failed to download $src_url"); + or sync_error(__"failed to download file [" . $src_url . "]"); } sub sync_file_aria2 { my ($src_url, $dst_dir) = @_; - print "fetching $src_url\n"; + print __"fetching " . $src_url . "\n"; system("aria2c -q -d $dst_dir $src_url") == 0 and return 1; @@ -665,13 +670,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 $src_url"); + sync_error(__"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 $src_file"); + or sync_error(__"failed to link to file [" . $src_file . "]"); } sub sync_error { @@ -684,7 +689,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 local repository"; + my $message = __"no synthesis file found in the local repository"; show_error_dialogue($message); print_error($message); return 0; @@ -705,7 +710,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(__"none of the listed packages are installed"); } } @@ -726,16 +731,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(__"Downgrade"); + $dialogue_label->set_text(__"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(__"Error"); + $dialogue_label->set_text(__"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(); @@ -743,7 +748,7 @@ sub show_error_dialogue { sub print_error { my ($message, $o_fatal) = @_; - print "ERROR: $message.\n"; + print __"ERROR: " . $message . ".\n"; $fatal_error = $o_fatal; } diff --git a/qarepo.desktop b/qarepo.desktop deleted file mode 100644 index bb4bdcb..0000000 --- a/qarepo.desktop +++ /dev/null @@ -1,8 +0,0 @@ -[Desktop Entry] -Name=QA Repo -Comment=Tool for creating a local testing repository -Type=Application -Terminal=false -Icon=mageia -Exec=/usr/bin/qarepo -Categories=Utility;X-MageiaLinux-CrossDesktop; diff --git a/qarepo.desktop.in b/qarepo.desktop.in new file mode 100644 index 0000000..f70bd72 --- /dev/null +++ b/qarepo.desktop.in @@ -0,0 +1,9 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=QA Repo +_Comment=Tool for creating a local testing repository +Type=Application +Terminal=false +Icon=mageia +Exec=/usr/bin/qarepo +Categories=Utility;X-MageiaLinux-CrossDesktop; -- cgit v1.2.1