Add missing display strings (GUIUtils, validations)

This commit is contained in:
Manfred Karrer 2017-03-12 02:16:35 -05:00
parent 055d505ba6
commit 05678353d7
12 changed files with 104 additions and 53 deletions

View File

@ -57,7 +57,7 @@ public class Res {
public static String get(String key) {
// TODO remove once translation done
// for testing missing translation strings
//if (true) return "#";
if (true) return "#";
try {
return resourceBundle.getString(key);
} catch (MissingResourceException e) {

View File

@ -78,11 +78,7 @@ public class GUIUtil {
public static void showFeeInfoBeforeExecute(Runnable runnable) {
String key = "miningFeeInfo";
if (!DevFlags.DEV_MODE && Preferences.INSTANCE.showAgain(key)) {
new Popup<>().information("Please be sure that the mining fee used at your external wallet is " +
"sufficiently high so that the funding transaction will be accepted by the miners.\n" +
"Otherwise the trade transactions cannot be confirmed and a trade would end up in a dispute.\n\n" +
"The recommended fee is about 120 Satoshi/Byte which is for an average transaction about 0.0005 BTC.\n\n" +
"You can check out the currently recommended fees at: https://bitcoinfees.21.co")
new Popup<>().information(Res.get("guiUtil.miningFeeInfo"))
.dontShowAgainId(key, Preferences.INSTANCE)
.onClose(runnable::run)
.useIUnderstandButton()
@ -98,16 +94,16 @@ public class GUIUtil {
Storage<ArrayList<PaymentAccount>> paymentAccountsStorage = new Storage<>(new File(directory));
paymentAccountsStorage.initAndGetPersisted(accounts, fileName);
paymentAccountsStorage.queueUpForSave();
new Popup<>().feedback("Trading accounts saved to path:\n" + Paths.get(directory, fileName).toAbsolutePath()).show();
new Popup<>().feedback(Res.get("guiUtil.accountExport.savedToPath", Paths.get(directory, fileName).toAbsolutePath())).show();
} else {
new Popup<>().warning("You don't have trading accounts set up for exporting.").show();
new Popup<>().warning(Res.get("guiUtil.accountExport.noAccountSetup")).show();
}
}
public static void importAccounts(User user, String fileName, Preferences preferences, Stage stage) {
FileChooser fileChooser = new FileChooser();
fileChooser.setInitialDirectory(new File(preferences.getDirectoryChooserPath()));
fileChooser.setTitle("Select path to " + fileName);
fileChooser.setTitle(Res.get("guiUtil.accountExport.selectPath", fileName));
File file = fileChooser.showOpenDialog(stage.getOwner());
if (file != null) {
String path = file.getAbsolutePath();
@ -122,18 +118,18 @@ public class GUIUtil {
final String id = paymentAccount.getId();
if (user.getPaymentAccount(id) == null) {
user.addPaymentAccount(paymentAccount);
msg.append("Trading account with id ").append(id).append("\n");
msg.append(Res.get("guiUtil.accountExport.tradingAccount", id));
} else {
msg.append("We did not import trading account with id ").append(id).append(" because it exists already.\n");
msg.append(Res.get("guiUtil.accountImport.noImport", id));
}
});
new Popup<>().feedback("Trading account imported from path:\n" + path + "\n\nImported accounts:\n" + msg).show();
new Popup<>().feedback(Res.get("guiUtil.accountImport.imported", path, msg)).show();
} else {
new Popup<>().warning("No exported trading accounts has been found at path: " + path + ".\n" + "File name is " + fileName + ".").show();
new Popup<>().warning(Res.get("guiUtil.accountImport.noAccountsFound", path, fileName)).show();
}
} else {
new Popup<>().warning("The selected file is not the expected file for import. The expected file name is: " + fileName + ".").show();
log.error("The selected file is not the expected file for import. The expected file name is: " + fileName + ".");
}
}
}
@ -161,15 +157,14 @@ public class GUIUtil {
} catch (RuntimeException | IOException e) {
e.printStackTrace();
log.error(e.getMessage());
new Popup().error("Exporting to CSV failed because of an error.\n" +
"Error = " + e.getMessage());
new Popup().error(Res.get("guiUtil.accountExport.exportFailed", e.getMessage()));
}
}
public static String getDirectoryFromChooser(Preferences preferences, Stage stage) {
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setInitialDirectory(new File(preferences.getDirectoryChooserPath()));
directoryChooser.setTitle("Select export path");
directoryChooser.setTitle(Res.get("guiUtil.accountExport.selectExportPath"));
File dir = directoryChooser.showDialog(stage);
if (dir != null) {
String directory = dir.getAbsolutePath();
@ -293,18 +288,13 @@ public class GUIUtil {
String key = "warnOpenURLWhenTorEnabled";
final Preferences preferences = Preferences.INSTANCE;
if (preferences.showAgain(key)) {
new Popup<>().information("You are going to open a web page " +
"in your system web browser.\n" +
"Do you want to open the web page now?\n\n" +
"If you are not using the \"Tor Browser\" as your default system web browser you " +
"will connect to the web page in clear net.\n\n" +
"URL: \"" + target)
.actionButtonText("Open the web page and don't ask again")
new Popup<>().information(Res.get("guiUtil.openWebBrowser.warning", target))
.actionButtonText(Res.get("guiUtil.openWebBrowser.doOpen"))
.onAction(() -> {
preferences.dontShowAgain(key, true);
doOpenWebPage(target);
})
.closeButtonText("Copy URL and cancel")
.closeButtonText(Res.get("guiUtil.openWebBrowser.copyUrl"))
.onClose(() -> Utilities.copyToClipboard(target))
.show();
} else {
@ -334,7 +324,7 @@ public class GUIUtil {
public static String getPercentageOfTradeAmount(Coin fee, Coin tradeAmount, BSFormatter formatter) {
return " (" + formatter.formatToPercentWithSymbol((double) fee.value / (double) tradeAmount.value) +
" of trade amount)";
" " + Res.get("guiUtil.ofTradeAmount") + ")";
}
public static <T> T getParentOfType(Node node, Class<T> t) {

View File

@ -53,7 +53,7 @@ public final class AccountNrValidator extends BankValidator {
if (isNumberInRange(input2, 15, 16))
return super.validate(input);
else
return new ValidationResult(false, "Account number must be of format: 03-1587-0050000-00");
return new ValidationResult(false, Res.get("validation.accountNrFormat", "03-1587-0050000-00"));
case "AU":
if (isNumberInRange(input, 4, 10))
return super.validate(input);
@ -75,7 +75,7 @@ public final class AccountNrValidator extends BankValidator {
if (isNumberInRange(input2, 9, 12))
return super.validate(input);
else
return new ValidationResult(false, "Account number must be of format: 005-231289-112");
return new ValidationResult(false, Res.get("validation.accountNrFormat", "005-231289-112"));
case "NO":
if (input != null) {
length = 11;
@ -96,7 +96,7 @@ public final class AccountNrValidator extends BankValidator {
return new ValidationResult(false, Res.get("validation.sortCodeNumber", getLabel(), length));
int lastDigit = Character.getNumericValue(input2.charAt(input2.length() - 1));
if (getMod11ControlDigit(input2) != lastDigit)
return new ValidationResult(false, "Kontonummer har feil sjekksum");
return new ValidationResult(false, "Kontonummer har feil sjekksum"); // not translated
else
return super.validate(input);
} else {

View File

@ -21,6 +21,7 @@ package io.bitsquare.gui.util.validation;
import io.bitsquare.gui.util.validation.altcoins.ByteballAddressValidator;
import io.bitsquare.gui.util.validation.params.IOPParams;
import io.bitsquare.gui.util.validation.params.PivxParams;
import io.bitsquare.locale.Res;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.params.MainNetParams;
@ -52,8 +53,10 @@ public final class AltCoinAddressValidator extends InputValidator {
// 1: With a regex checking the correct structure of an address
// 2: If the address contains a checksum, verify the checksum
ValidationResult wrongChecksum = new ValidationResult(false, "Address validation failed because checksum was not correct.");
ValidationResult regexTestFailed = new ValidationResult(false, "Address validation failed because it does not match the structure of a " + currencyCode + " address.");
ValidationResult wrongChecksum = new ValidationResult(false,
Res.get("validation.altcoin.wrongChecksum"));
ValidationResult regexTestFailed = new ValidationResult(false,
Res.get("validation.altcoin.wrongStructure", currencyCode));
switch (currencyCode) {
case "ETH":
@ -61,7 +64,7 @@ public final class AltCoinAddressValidator extends InputValidator {
if (!input.matches("^(0x)?[0-9a-fA-F]{40}$")) {
return regexTestFailed;
}
return new ValidationResult(true);
return new ValidationResult(true);
// Example for BTC, though for BTC we use the BitcoinJ library address check
case "BTC":
// taken form: https://stackoverflow.com/questions/21683680/regex-to-match-bitcoin-addresses
@ -78,8 +81,8 @@ public final class AltCoinAddressValidator extends InputValidator {
} else {
return regexTestFailed;
}
case "PIVX":
if (input.matches("^[D][a-km-zA-HJ-NP-Z1-9]{25,34}$")) {
case "PIVX":
if (input.matches("^[D][a-km-zA-HJ-NP-Z1-9]{25,34}$")) {
if (verifyChecksum(input)) {
try {
new Address(PivxParams.get(), input);
@ -113,7 +116,7 @@ public final class AltCoinAddressValidator extends InputValidator {
if (input.startsWith("t"))
return validationResult;
else
return new ValidationResult(false, "ZEC address need to start with t. Addresses starting with z are not supported.");
return new ValidationResult(false, Res.get("validation.altcoin.zAddressesNotSupported"));
// TODO test not successful
/*case "XTO":
@ -133,7 +136,7 @@ public final class AltCoinAddressValidator extends InputValidator {
case "GBYTE":
return ByteballAddressValidator.validate(input);
default:
log.debug("Validation for AltCoinAddress not implemented yet. currencyCode:" + currencyCode);
log.debug("Validation for AltCoinAddress not implemented yet. currencyCode: " + currencyCode);
return validationResult;
}
}
@ -141,7 +144,7 @@ public final class AltCoinAddressValidator extends InputValidator {
@NotNull
private String getErrorMessage(AddressFormatException e) {
return "Address is not a valid " + currencyCode + " address! " + e.getMessage();
return Res.get("validation.altcoin.invalidAddress", currencyCode, e.getMessage());
}
private boolean verifyChecksum(String input) {

View File

@ -17,6 +17,8 @@
package io.bitsquare.gui.util.validation;
import io.bitsquare.locale.Res;
import java.util.Locale;
/*
@ -51,20 +53,20 @@ public final class BICValidator extends InputValidator {
// check ensure length 8 or 11
if (!isStringWithFixedLength(input,8) && !isStringWithFixedLength(input,11))
return new ValidationResult(false, "Input length is neither 8 nor 11");
return new ValidationResult(false, Res.get("validation.bic.invalidLength"));
input = input.toUpperCase(Locale.ROOT);
// ensure Bank and Contry code to be letters only
for (int k=0; k<6; k++) {
if (!Character.isLetter(input.charAt(k)))
return new ValidationResult(false, "Bank and Country code must be letters");
return new ValidationResult(false, Res.get("validation.bic.letters"));
}
// ensure location code starts not with 0 or 1 and ends not with O
char ch = input.charAt(6);
if (ch == '0' || ch == '1' || input.charAt(7) == 'O')
return new ValidationResult(false, "BIC contains invalid location code");
return new ValidationResult(false, Res.get("validation.bic.invalidLocationCode"));
// check complete for 8 char BIC
if (input.length() == 8)
@ -73,7 +75,7 @@ public final class BICValidator extends InputValidator {
// ensure branch code does not start with X unless it is XXX
if (input.charAt(8) == 'X')
if (input.charAt(9) != 'X' || input.charAt(10) != 'X')
return new ValidationResult(false, "BIC contains invalid branch code");
return new ValidationResult(false, Res.get("validation.bic.invalidBranchCode"));
return new ValidationResult(true);
}

View File

@ -17,6 +17,7 @@
package io.bitsquare.gui.util.validation;
import io.bitsquare.locale.Res;
import io.bitsquare.user.Preferences;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.AddressFormatException;
@ -47,7 +48,7 @@ public final class BtcAddressValidator extends InputValidator {
new Address(preferences.getBitcoinNetwork().getParameters(), input);
return new ValidationResult(true);
} catch (AddressFormatException e) {
return new ValidationResult(false, "Invalid format of the bitcoin address.");
return new ValidationResult(false, Res.get("validation.btc.invalidFormat"));
}
}
}

View File

@ -77,7 +77,7 @@ public class BtcValidator extends NumberValidator {
else
return new ValidationResult(true);
} catch (Throwable t) {
return new ValidationResult(false, "Invalid input: " + t.getMessage());
return new ValidationResult(false, Res.get("validation.invalidInput", t.getMessage()));
}
}
}

View File

@ -34,13 +34,15 @@ package io.bitsquare.gui.util.validation;
*
*/
import io.bitsquare.locale.Res;
public final class EmailValidator extends InputValidator {
///////////////////////////////////////////////////////////////////////////////////////////
// Public methods
///////////////////////////////////////////////////////////////////////////////////////////
private final ValidationResult invalidAddress = new ValidationResult(false, "Invalid address");
private final ValidationResult invalidAddress = new ValidationResult(false, Res.get("validation.email.invalidAddress"));
@Override
public ValidationResult validate(String input) {

View File

@ -17,6 +17,8 @@
package io.bitsquare.gui.util.validation;
import io.bitsquare.locale.Res;
import java.math.BigInteger;
import java.util.Locale;
@ -42,12 +44,12 @@ public final class IBANValidator extends InputValidator {
// check if country code is letters and checksum numeric
if (!( Character.isLetter(input.charAt(0)) && Character.isLetter(input.charAt(1)) ))
return new ValidationResult(false, "Country code invalid");
return new ValidationResult(false, Res.get("validation.iban.invalidCountryCode"));
if (!( Character.isDigit(input.charAt(2)) && Character.isDigit(input.charAt(3)) ))
return new ValidationResult(false, "Checksum must be numeric");
return new ValidationResult(false, Res.get("validation.iban.checkSumNotNumeric"));
// reorder IBAN to format <account number> <country code> <checksum>
String input2 = new String(input.substring(4, input.length()) + input.substring(0,4));
String input2 = input.substring(4, input.length()) + input.substring(0, 4);
// check if input is alphanumeric and count included letters
int charCount = 0;
@ -57,7 +59,7 @@ public final class IBANValidator extends InputValidator {
if (Character.isLetter(ch))
charCount++;
else if (!Character.isDigit(ch))
return (new ValidationResult(false, "Non-alphanumeric character detected"));
return (new ValidationResult(false, Res.get("validation.iban.nonNumericChars")));
}
// create final char array for checksum validation
@ -79,10 +81,10 @@ public final class IBANValidator extends InputValidator {
if (result == 1)
return new ValidationResult(true);
else
return new ValidationResult(false, "IBAN checksum is invalid");
return new ValidationResult(false, Res.get("validation.iban.checkSumInvalid"));
}
// return new ValidationResult(false, BSResources.get("validation.accountNrChars", "15 - 34"));
return new ValidationResult(false, "Number must have length 15 to 34 chars.");
return new ValidationResult(false, Res.get("validation.iban.invalidLength"));
}

View File

@ -29,6 +29,8 @@ package io.bitsquare.gui.util.validation;
* They are to change in some future (according to the linked document around 2019/2020)
*/
import io.bitsquare.locale.Res;
public final class InteracETransferValidator extends InputValidator {
private static final String[] NPAS = {"204", "226", "236", "249", "250", "289", "306", "343", "365", "403", "416", "418", "431", "437", "438", "450", "506", "514", "519", "548", "579", "581", "587", "604", "613", "639", "647", "705", "709", "778", "780", "782", "807", "819", "825", "867", "873", "902", "905"};
@ -75,9 +77,9 @@ public final class InteracETransferValidator extends InputValidator {
if (inputAreaCode.compareTo(s) == 0)
return new ValidationResult(true);
}
return new ValidationResult(false, "Non-Canadian area code");
return new ValidationResult(false, Res.get("validation.interacETransfer.invalidAreaCode"));
} else {
return new ValidationResult(false, "Invalid phone number format and not an email address");
return new ValidationResult(false, Res.get("validation.interacETransfer.invalidPhone"));
}
}
}

View File

@ -63,7 +63,7 @@ public class SecurityDepositValidator extends BtcValidator {
else
return new ValidationResult(true);
} catch (Throwable t) {
return new ValidationResult(false, "Invalid input: " + t.getMessage());
return new ValidationResult(false, Res.get("validation.invalidInput", t.getMessage()));
}
}
}

View File

@ -1152,6 +1152,35 @@ systemTray.exit=Exit
systemTray.tooltip=bisq: The decentralized bitcoin exchange
####################################################################
# GUI Util
####################################################################
guiUtil.miningFeeInfo=Please be sure that the mining fee used at your external wallet is \
sufficiently high so that the funding transaction will be accepted by the miners.\n\
Otherwise the trade transactions cannot be confirmed and a trade would end up in a dispute.\n\n\
The recommended fee is about 120 Satoshi/Byte which is for an average transaction about 0.0005 BTC.\n\n\
You can check out the currently recommended fees at: https://bitcoinfees.21.co
guiUtil.accountExport.savedToPath=Trading accounts saved to path:\n{0}
guiUtil.accountExport.noAccountSetup=You don't have trading accounts set up for exporting.
guiUtil.accountExport.selectPath=Select path to {0}
guiUtil.accountExport.tradingAccount=Trading account with id {0}\n
guiUtil.accountImport.noImport=We did not import trading account with id {0} because it exists already.\n
guiUtil.accountExport.exportFailed=Exporting to CSV failed because of an error.\nError = {0}
guiUtil.accountExport.selectExportPath=Select export path
guiUtil.accountImport.imported=Trading account imported from path:\n{0}\n\nImported accounts:\n{1}
guiUtil.accountImport.noAccountsFound=No exported trading accounts has been found at path: {0}.\nFile name is {1}."
guiUtil.openWebBrowser.warning=You are going to open a web page \
in your system web browser.\n\
Do you want to open the web page now?\n\n\
If you are not using the \"Tor Browser\" as your default system web browser you \
will connect to the web page in clear net.\n\n\
URL: \"{0}\"
guiUtil.openWebBrowser.doOpen=Open the web page and don't ask again
guiUtil.openWebBrowser.copyUrl=Copy URL and cancel
guiUtil.ofTradeAmount=of trade amount
####################################################################
# Component specific
####################################################################
@ -1418,6 +1447,26 @@ validation.btc.amountBelowDust=The amount you would like to send is below the du
validation.integerOnly=Please enter integer numbers only.
validation.inputError=Your input caused an error\n{0}
#new
validation.invalidInput=Invalid input: {0}
validation.accountNrFormat=Account number must be of format: {0}
validation.altcoin.wrongChecksum=Address validation failed because checksum was not correct.
validation.altcoin.wrongStructure=Address validation failed because it does not match the structure of a {0} address.
validation.altcoin.zAddressesNotSupported=ZEC address need to start with t. Addresses starting with z are not supported.
validation.altcoin.invalidAddress=Address is not a valid {0} address! {1}
validation.bic.invalidLength=Input length is neither 8 nor 11
validation.bic.letters=Bank and Country code must be letters
validation.bic.invalidLocationCode=BIC contains invalid location code
validation.bic.invalidBranchCode=BIC contains invalid branch code
validation.btc.invalidFormat=Invalid format of the bitcoin address.
validation.email.invalidAddress=Invalid address=
validation.iban.invalidCountryCode=Country code invalid
validation.iban.checkSumNotNumeric=Checksum must be numeric
validation.iban.nonNumericChars=Non-alphanumeric character detected
validation.iban.checkSumInvalid=IBAN checksum is invalid
validation.iban.invalidLength=Number must have length 15 to 34 chars.
validation.interacETransfer.invalidAreaCode=Non-Canadian area code
validation.interacETransfer.invalidPhone=Invalid phone number format and not an email address