mirror of
https://codeberg.org/PGPainless/vks-java.git
synced 2024-11-24 08:22:05 +01:00
Add support for i18n using resource bundles
This commit is contained in:
parent
f349c701fa
commit
e37921b4d4
14 changed files with 145 additions and 26 deletions
|
@ -11,8 +11,12 @@ import picocli.CommandLine;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
@CommandLine.Command(name = "get", description = "Retrieve an OpenPGP certificate from the key server")
|
||||
@CommandLine.Command(
|
||||
name = "get",
|
||||
resourceBundle = "msg_get")
|
||||
public class GetCmd implements Runnable {
|
||||
|
||||
@CommandLine.Mixin
|
||||
|
@ -22,16 +26,22 @@ public class GetCmd implements Runnable {
|
|||
Exclusive by;
|
||||
|
||||
static class Exclusive {
|
||||
@CommandLine.Option(names = {"-f", "--by-fingerprint"}, description = "Retrieve a key by its fingerprint (NOT prefixed with '0x')")
|
||||
@CommandLine.Option(names = {"-f", "--by-fingerprint"})
|
||||
String fingerprint;
|
||||
|
||||
@CommandLine.Option(names = {"-i", "--by-keyid"}, description = "Retrieve a key by its decimal key ID or that of one of its subkeys.")
|
||||
@CommandLine.Option(names = {"-i", "--by-keyid"})
|
||||
Long keyId;
|
||||
|
||||
@CommandLine.Option(names = {"-e", "--by-email"}, description = "Retrieve a key by email address.")
|
||||
@CommandLine.Option(names = {"-e", "--by-email"})
|
||||
String email;
|
||||
}
|
||||
|
||||
private final ResourceBundle msg;
|
||||
|
||||
public GetCmd() {
|
||||
msg = ResourceBundle.getBundle("msg_get", Locale.getDefault());
|
||||
}
|
||||
|
||||
public void run() {
|
||||
VKS vks;
|
||||
try {
|
||||
|
@ -50,7 +60,7 @@ public class GetCmd implements Runnable {
|
|||
} else if (by.email != null) {
|
||||
inputStream = get.byEmail(by.email);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Missing --by-* option.");
|
||||
throw new IllegalArgumentException(msg.getString("error.missing_by_option"));
|
||||
}
|
||||
|
||||
int read;
|
||||
|
|
|
@ -12,23 +12,32 @@ import java.io.IOException;
|
|||
import java.net.MalformedURLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
@CommandLine.Command(name = "request-verification", description = "Request verification for unverified user-ids")
|
||||
@CommandLine.Command(
|
||||
name = "request-verification",
|
||||
resourceBundle = "msg_request_verification")
|
||||
public class RequestVerificationCmd implements Runnable {
|
||||
|
||||
@CommandLine.Mixin
|
||||
VKSCLI.KeyServerMixin keyServerMixin;
|
||||
|
||||
@CommandLine.Option(names = {"-t", "--token"}, description = "Access token. Can be retrieved by uploading the certificate.",
|
||||
@CommandLine.Option(names = {"-t", "--token"},
|
||||
required = true, arity = "1", paramLabel = "TOKEN")
|
||||
String token;
|
||||
|
||||
@CommandLine.Option(names = {"-l", "--locale"}, description = "Locale for the verification mail")
|
||||
@CommandLine.Option(names = {"-l", "--locale"})
|
||||
List<String> locale = Arrays.asList("en_US", "en_GB");
|
||||
|
||||
@CommandLine.Option(names = {"-e", "--email"}, description = "Email addresses to request a verification mail for", required = true, arity = "1..*")
|
||||
@CommandLine.Option(names = {"-e", "--email"}, required = true, arity = "1..*")
|
||||
String[] addresses = new String[0];
|
||||
|
||||
private final ResourceBundle msg;
|
||||
|
||||
public RequestVerificationCmd() {
|
||||
msg = ResourceBundle.getBundle("msg_request_verification", Locale.getDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -44,10 +53,9 @@ public class RequestVerificationCmd implements Runnable {
|
|||
RequestVerify.Response response = requestVerify
|
||||
.forEmailAddresses(addresses)
|
||||
.execute(token, locale);
|
||||
|
||||
System.out.println("Verification E-Mails for key " + response.getKeyFingerprint() + " have been sent.");
|
||||
System.out.println("Token: " + response.getToken());
|
||||
System.out.println("Status:");
|
||||
System.out.printf(msg.getString("output.mails_sent"), response.getKeyFingerprint());
|
||||
System.out.printf(msg.getString("output.token"), response.getToken());
|
||||
System.out.println(msg.getString("output.status"));
|
||||
for (String address : response.getStatus().keySet()) {
|
||||
System.out.println("\t" + address + "\t" + response.getStatus().get(address));
|
||||
}
|
||||
|
|
|
@ -15,17 +15,26 @@ import java.io.IOException;
|
|||
import java.net.MalformedURLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
@CommandLine.Command(name = "upload", description = "Upload an OpenPGP certificate to the key server")
|
||||
@CommandLine.Command(
|
||||
name = "upload",
|
||||
resourceBundle = "msg_upload")
|
||||
public class UploadCmd implements Runnable {
|
||||
|
||||
@CommandLine.Mixin
|
||||
VKSCLI.KeyServerMixin keyServerMixin;
|
||||
|
||||
@CommandLine.Option(names = {"-r", "--request-verification"},
|
||||
description = "Request verification mails for unpublished email addresses")
|
||||
@CommandLine.Option(names = {"-r", "--request-verification"})
|
||||
boolean requestVerification;
|
||||
|
||||
private final ResourceBundle msg;
|
||||
|
||||
public UploadCmd() {
|
||||
msg = ResourceBundle.getBundle("msg_upload", Locale.getDefault());
|
||||
}
|
||||
|
||||
public void run() {
|
||||
VKS vks;
|
||||
try {
|
||||
|
@ -51,11 +60,13 @@ public class UploadCmd implements Runnable {
|
|||
}
|
||||
}
|
||||
|
||||
System.out.println("Uploaded key " + response.getKeyFingerprint());
|
||||
System.out.println("Token: " + response.getToken());
|
||||
String msgUpload = String.format(msg.getString("output.uploaded_key"),
|
||||
response.getKeyFingerprint(), response.getToken());
|
||||
System.out.println(msgUpload);
|
||||
|
||||
String msgStatus = msg.getString("output.status");
|
||||
if (!requestVerification || unpublished.isEmpty()) {
|
||||
System.out.println("Status:");
|
||||
System.out.println(msgStatus);
|
||||
for (String address : response.getStatus().keySet()) {
|
||||
Status status = response.getStatus().get(address);
|
||||
System.out.format("%-" + maxMailLen + "s %s\n", address, status);
|
||||
|
@ -65,7 +76,7 @@ public class UploadCmd implements Runnable {
|
|||
|
||||
RequestVerify.Response verifyResponse = vks.requestVerification().forEmailAddresses(unpublished.toArray(new String[0]))
|
||||
.execute(response.getToken());
|
||||
System.out.println("Status:");
|
||||
System.out.println(msgStatus);
|
||||
for (String address : verifyResponse.getStatus().keySet()) {
|
||||
Status status = response.getStatus().get(address);
|
||||
System.out.format("%-" + maxMailLen + "s %s\n", address, status);
|
||||
|
|
|
@ -9,10 +9,12 @@ import pgp.vks.client.VKSImpl;
|
|||
import picocli.CommandLine;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
@CommandLine.Command(
|
||||
name = "vks",
|
||||
description = "Interact with Verifying Key Servers",
|
||||
resourceBundle = "msg_vks",
|
||||
subcommands = {
|
||||
CommandLine.HelpCommand.class,
|
||||
GetCmd.class,
|
||||
|
@ -32,14 +34,15 @@ public class VKSCLI {
|
|||
}
|
||||
|
||||
public static int execute(String[] args) {
|
||||
return new CommandLine(VKSCLI.class)
|
||||
.setExitCodeExceptionMapper(new CommandLine.IExitCodeExceptionMapper() {
|
||||
CommandLine cmd = new CommandLine(VKSCLI.class);
|
||||
cmd.setExitCodeExceptionMapper(new CommandLine.IExitCodeExceptionMapper() {
|
||||
@Override
|
||||
public int getExitCode(Throwable exception) {
|
||||
return 1;
|
||||
}
|
||||
})
|
||||
.setCommandName("vkscli")
|
||||
});
|
||||
cmd.getSubcommands().get("help").setResourceBundle(ResourceBundle.getBundle("msg_help", Locale.getDefault()));
|
||||
return cmd.setCommandName("vkscli")
|
||||
.execute(args);
|
||||
}
|
||||
|
||||
|
@ -53,7 +56,6 @@ public class VKSCLI {
|
|||
VKSCLI parent;
|
||||
|
||||
@CommandLine.Option(names = "--key-server",
|
||||
description = "Address of the Verifying Key Server.\nDefaults to 'https://keys.openpgp.org'",
|
||||
paramLabel = "KEYSERVER")
|
||||
public void setKeyServer(String keyServer) {
|
||||
parent.keyServer = keyServer;
|
||||
|
|
9
vks-java-cli/src/main/resources/msg_get.properties
Normal file
9
vks-java-cli/src/main/resources/msg_get.properties
Normal file
|
@ -0,0 +1,9 @@
|
|||
# SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
usage.header=Retrieve an OpenPGP certificate from the key server
|
||||
by-fingerprint=Retrieve a key by its fingerprint (NOT prefixed with '0x')
|
||||
by-keyid=Retrieve a key by its decimal key ID or that of one of its subkeys
|
||||
by-email=Retrieve a key by email address
|
||||
error.missing_by_option=Missing --by-* option.
|
||||
key-server=Address of the Verifying Key Server.%nDefaults to 'https://keys.openpgp.org'
|
12
vks-java-cli/src/main/resources/msg_get_de.properties
Normal file
12
vks-java-cli/src/main/resources/msg_get_de.properties
Normal file
|
@ -0,0 +1,12 @@
|
|||
# SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
usage.header=Empfange ein OpenPGP Zertifikat vom Schlüsselserver
|
||||
by-fingerprint=Finde das Zertifikat anhand seines Fingerabdrucks (OHNE Präfix '0x')
|
||||
by-keyid=Finde das Zertifikat anhand seiner Schlüssel-ID oder der eines seiner Unterschlüssel
|
||||
by-email=Finde das Zertifikat anhand einer E-Mail-Adresse
|
||||
error.missing_by_option=Fehlende --by-* Option.
|
||||
usage.synopsisHeading=Nutzung:\u0020
|
||||
usage.optionListHeading=Optionen:%n
|
||||
|
||||
key-server=Adresse des verifizierenden Schlüsselservers.%nStandardmäßig: 'https://keys.openpgp.org'
|
5
vks-java-cli/src/main/resources/msg_help.properties
Normal file
5
vks-java-cli/src/main/resources/msg_help.properties
Normal file
|
@ -0,0 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
usage.header=Displays help information about the specified command
|
||||
usage.synopsisHeading=Usage:\u0020
|
6
vks-java-cli/src/main/resources/msg_help_de.properties
Normal file
6
vks-java-cli/src/main/resources/msg_help_de.properties
Normal file
|
@ -0,0 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
usage.header=Zeige Hilfetext für den angegebenen Befehl
|
||||
usage.synopsisHeading=Nutzung:\u0020
|
||||
usage.optionListHeading=Optionen:%n
|
|
@ -0,0 +1,11 @@
|
|||
# SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
usage.header=Request verification for unverified user-ids
|
||||
token=Access token. Can be retrieved by uploading the certificate.
|
||||
locale=Locale (language) for the verification mail
|
||||
email=Email addresses to request a verification mail for
|
||||
output.mails_sent=Verification E-Mails for certificate %s have been sent.%n
|
||||
output.token=Token: %s%n
|
||||
output.status=Status:
|
||||
key-server=Address of the Verifying Key Server.%nDefaults to 'https://keys.openpgp.org'
|
|
@ -0,0 +1,14 @@
|
|||
# SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
usage.header=Fordere Verifikation von unveröffentlichten Nutzeridentitäten an
|
||||
token=Zugangstoken. Kann durch das Hochladen des Zertifikates erhalten werden.
|
||||
locale=Gebietsschema (Sprache) für die E-Mail-Verifikation
|
||||
email=E-Mail-Adresse für die eine Verifikation angefragt werden soll
|
||||
output.mails_sent=E-Mail-Verifikationen für Zertifikat %s wurden versendet.%n%n
|
||||
output.token=Zugangstoken: %s%n
|
||||
output.status=Status:
|
||||
usage.synopsisHeading=Nutzung:\u0020
|
||||
usage.optionListHeading=Optionen:%n
|
||||
|
||||
key-server=Adresse des verifizierenden Schlüsselservers.%nStandardmäßig: 'https://keys.openpgp.org'
|
8
vks-java-cli/src/main/resources/msg_upload.properties
Normal file
8
vks-java-cli/src/main/resources/msg_upload.properties
Normal file
|
@ -0,0 +1,8 @@
|
|||
# SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
usage.header=Upload an OpenPGP certificate to the key server
|
||||
request-verification=Request verification mails for unpublished email addresses
|
||||
output.uploaded_key=Uploaded key: %s%nToken: %s
|
||||
output.status=Status:
|
||||
key-server=Address of the Verifying Key Server.%nDefaults to 'https://keys.openpgp.org'
|
11
vks-java-cli/src/main/resources/msg_upload_de.properties
Normal file
11
vks-java-cli/src/main/resources/msg_upload_de.properties
Normal file
|
@ -0,0 +1,11 @@
|
|||
# SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
usage.header=Lade ein OpenPGP Zertifikat auf den Schlüsselserver hoch
|
||||
request-verification=Fordere E-Mailverifikation für unveröffentlichte E-Mail-Adressen an
|
||||
output.uploaded_key=Hochgeladenes Zertifikat: %s%nToken: %s
|
||||
output.status=Status:
|
||||
usage.synopsisHeading=Nutzung:\u0020
|
||||
usage.optionListHeading=Optionen:%n
|
||||
|
||||
key-server=Adresse des verifizierenden Schlüsselservers.%nStandardmäßig: 'https://keys.openpgp.org'
|
6
vks-java-cli/src/main/resources/msg_vks.properties
Normal file
6
vks-java-cli/src/main/resources/msg_vks.properties
Normal file
|
@ -0,0 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
usage.header=Interact with Verifying Key Servers
|
||||
usage.synopsisHeading=Usage:\u0020
|
||||
usage.commandListHeading=Commands:%n
|
6
vks-java-cli/src/main/resources/msg_vks_de.properties
Normal file
6
vks-java-cli/src/main/resources/msg_vks_de.properties
Normal file
|
@ -0,0 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
usage.header=Interagiere mit verifizierenden Schlüsselservern
|
||||
usage.synopsisHeading=Nutzung:\u0020
|
||||
usage.commandListHeading=Befehle:%n
|
Loading…
Reference in a new issue