Merge pull request #2737 from federicobond/localize-contrib

Add language hooks for Contribution Manager
This commit is contained in:
Ben Fry
2014-08-05 07:48:53 -04:00
7 changed files with 53 additions and 45 deletions
@@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.List;
import processing.app.Base;
import processing.app.Language;
import processing.core.PApplet;
@@ -86,7 +87,7 @@ class AvailableContribution extends Contribution {
tempFolder = type.createTempFolder();
} catch (IOException e) {
if (status != null)
status.setErrorMessage("Could not create a temporary folder to install.");
status.setErrorMessage(Language.text("contributions.errors.temporary_directory"));
return null;
}
Base.unzip(contribArchive, tempFolder);
@@ -115,7 +116,7 @@ class AvailableContribution extends Contribution {
tempFolder = enclosingFolder;
*/
if (status != null)
status.setErrorMessage(getName() + " needs to be repackaged according to the " + type.getTitle() + " guidelines.");
status.setErrorMessage(Language.interpolate("contributions.errors.needs_repackage", getName(), type.getTitle()));
//status.setErrorMessage("This " + type + " needs to be repackaged according to the guidelines.");
return null;
}
@@ -128,7 +129,7 @@ class AvailableContribution extends Contribution {
if (contribFolder == null) {
if (status != null)
status.setErrorMessage("Could not find a " + type + " in the downloaded file.");
status.setErrorMessage(Language.interpolate("contributions.errors.no_contribution_found", type));
} else {
File propFile = new File(contribFolder, type + ".properties");
@@ -180,7 +181,7 @@ class AvailableContribution extends Contribution {
} else {
if (status != null)
status.setErrorMessage("Error overwriting .properties file.");
status.setErrorMessage(Language.text("contributions.errors.overwriting_properties"));
}
}
@@ -307,4 +308,4 @@ class AvailableContribution extends Contribution {
}
return false;
}
}
}
@@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import processing.app.Language;
import processing.core.PApplet;
@@ -41,13 +41,6 @@ import processing.app.Base;
public class ContributionListPanel extends JPanel implements Scrollable, ContributionChangeListener {
static public final String INSTALL_FAILURE_TITLE = "Install Failed";
static public final String MALFORMED_URL_MESSAGE =
"The link fetched from Processing.org is not valid.\n" +
"You can still install this library manually by visiting\n" +
"the library's website.";
ContributionManagerDialog contribManager;
TreeMap<Contribution, ContributionPanel> panelByContribution;
@@ -140,7 +140,7 @@ public class ContributionManager {
download(url, contribZip, downloadProgress);
if (!downloadProgress.isCanceled() && !downloadProgress.isError()) {
installProgress.startTask("Installing...", ProgressMonitor.UNKNOWN);
installProgress.startTask(Language.text("contributions.progress.installing"), ProgressMonitor.UNKNOWN);
LocalContribution contribution =
ad.install(editor.getBase(), contribZip, false, status);
@@ -159,10 +159,10 @@ public class ContributionManager {
} catch (Exception e) {
e.printStackTrace();
status.setErrorMessage("Error during download and install.");
status.setErrorMessage(Language.text("contributions.errors.download_and_install"));
}
} catch (IOException e) {
status.setErrorMessage("Could not write to temporary directory.");
status.setErrorMessage(Language.text("contributions.errors.temporary_directory"));
}
}
}, "Contribution Installer").start();
@@ -498,10 +498,8 @@ public class ContributionManager {
static private void installOnStartUp(final Base base, final AvailableContribution availableContrib) {
if (availableContrib.link == null) {
Base.showWarning("Update on Restart of " + availableContrib.getName() + "failed",
"Your operating system "
+ "doesn't appear to be supported. You should visit the "
+ availableContrib.getType() + "'s library for more info.");
Base.showWarning(Language.interpolate("contributions.errors.update_on_restart_failed", availableContrib.getName()),
Language.text("contributions.unsupported_operating_system"));
return;
}
try {
@@ -510,8 +508,8 @@ public class ContributionManager {
ContributionManager.downloadAndInstallOnStartup(base, downloadUrl, availableContrib);
} catch (MalformedURLException e) {
Base.showWarning("Update on Restart of " + availableContrib.getName() + "failed",
ContributionListPanel.MALFORMED_URL_MESSAGE, e);
Base.showWarning(Language.interpolate("contributions.errors.update_on_restart_failed", availableContrib.getName()),
Language.text("contributions.errors.malformed_url"), e);
}
}
@@ -41,7 +41,7 @@ import processing.app.*;
public class ContributionManagerDialog {
static final String ANY_CATEGORY = "All";
static final String ANY_CATEGORY = Language.text("contributions.all");
JFrame dialog;
String title;
@@ -61,10 +61,8 @@ public class ContributionManagerDialog {
public ContributionManagerDialog(ContributionType type) {
if (type == null) {
title = "Update Manager";
filter = ContributionType.createUpdateFilter();
} else {
// title = type.getTitle() + " Manager";
filter = type.createFilter();
}
contribListing = ContributionListing.getInstance();
@@ -86,9 +84,9 @@ public class ContributionManagerDialog {
this.editor = editor;
if (dialog == null) {
dialog = new JFrame(title);
dialog = new JFrame(Language.text("contributions"));
restartButton = new JButton("Restart Processing");
restartButton = new JButton(Language.text("contributions.restart"));
restartButton.setVisible(false);
restartButton.addActionListener(new ActionListener() {
@@ -101,8 +99,8 @@ public class ContributionManagerDialog {
if (ed.getSketch().isModified()) {
int option = Base
.showYesNoQuestion(editor, title,
"Unsaved changes have been found",
"Are you sure you want to restart Processing without saving first?");
Language.text("contributions.unsaved_changes"),
Language.text("contributions.unsaved_changes.prompt"));
if (option == JOptionPane.NO_OPTION)
return;
@@ -158,11 +156,9 @@ public class ContributionManagerDialog {
updateCategoryChooser();
if (error) {
if (exception instanceof SocketTimeoutException) {
status.setErrorMessage("Connection timed out while " +
"downloading the contribution list.");
status.setErrorMessage(Language.text("contributions.errors.list_download.timeout"));
} else {
status.setErrorMessage("Could not download the list " +
"of available contributions.");
status.setErrorMessage(Language.text("contributions.errors.list_download"));
}
exception.printStackTrace();
}
@@ -512,4 +508,4 @@ public class ContributionManagerDialog {
public boolean hasAlreadyBeenOpened() {
return dialog != null;
}
}
}
@@ -50,16 +50,16 @@ import processing.app.Language;
*/
class ContributionPanel extends JPanel {
static public final String REMOVE_RESTART_MESSAGE =
"<i>Please restart Processing to finish removing this item.</i>";
String.format("<i>%s</i>", Language.text("contributions.messages.remove_restart"));
static public final String INSTALL_RESTART_MESSAGE =
"<i>Please restart Processing to finish installing this item.</i>";
String.format("<i>%s</i>", Language.text("contributions.messages.install_restart"));
static public final String UPDATE_RESTART_MESSAGE =
"<i>Please restart Processing to finish updating this item.</i>";
String.format("<i>%s</i>", Language.text("contributions.messages.update_restart"));
static public final String PROGRESS_BAR_CONSTRAINT = "Install/Remove Progress Bar Panel";
static public final String BUTTON_CONSTRAINT = "Install/Remvoe Button Panel";
private final ContributionListPanel listPanel;
@@ -570,14 +570,13 @@ class ContributionPanel extends JPanel {
description.append(REMOVE_RESTART_MESSAGE);
} else if (contrib.isRestartFlagged()) {
description.append(INSTALL_RESTART_MESSAGE);
}
else if (contrib.isUpdateFlagged()) {
} else if (contrib.isUpdateFlagged()) {
description.append(UPDATE_RESTART_MESSAGE);
}
else {
} else {
String sentence = contrib.getSentence();
if (sentence == null || sentence.isEmpty()) {
sentence = "<i>Description unavailable.</i>";
sentence = String.format("<i>%s</i>", Language.text("contributions.errors.description_unavailable"));
} else {
sentence = sanitizeHtmlTags(sentence);
sentence = toHtmlLinks(sentence);
@@ -719,8 +718,8 @@ class ContributionPanel extends JPanel {
listPanel.contribManager.status);
} catch (MalformedURLException e) {
Base.showWarning(ContributionListPanel.INSTALL_FAILURE_TITLE,
ContributionListPanel.MALFORMED_URL_MESSAGE, e);
Base.showWarning(Language.text("contributions.errors.install_failed"),
Language.text("contributions.errors.malformed_url"), e);
// not sure why we'd re-enable the button if it had an error...
// installRemoveButton.setEnabled(true);
}
@@ -262,9 +262,29 @@ editor.status.printing.canceled = Printing canceled.
# ---------------------------------------
# Contribution Panel
contributions = Contribution Manager
contributions.restart = Restart Processing
contributions.unsaved_changes = Unsaved changes have been found
contributions.unsaved_changes.prompt = Are you sure you want to restart Processing without saving first?
contributions.messages.remove_restart = Please restart Processing to finish removing this item.
contributions.messages.install_restart = Please restart Processing to finish installing this item.
contributions.messages.update_restart = Please restart Processing to finish updating this item.
contributions.errors.list_download = Could not download the list of available contributions.
contributions.errors.list_download.timeout = Connection timed out while downloading the contribution list.
contributions.errors.download_and_install = Error during download and install.
contributions.errors.description_unavailable = Description unavailable.
contributions.errors.malformed_url = "The link fetched from Processing.org is not valid.\nYou can still install this library manually by visiting\nthe library's website.
contributions.errors.needs_repackage = %s needs to be repackaged according to the %s guidelines.
contributions.errors.no_contribution_found = Could not find a %s in the downloaded file.
contributions.errors.overwriting_properties = Error overwriting .properties file.
contributions.errors.install_failed = Install failed.
contributions.errors.update_on_restart_failed = Update on restart of %s failed.
contributions.errors.temporary_directory = Could not write to temporary directory.
contributions.all = All
contributions.undo = Undo
contributions.remove = Remove
contributions.install = Install
contributions.progress.installing = Installing
contributions.progress.starting = Starting
contributions.progress.downloading = Downloading
contributions.download_error = An error occured while downloading the contribution.