Skip to content

Commit

Permalink
Complete internationalization in app/Sketch.java
Browse files Browse the repository at this point in the history
And remove accidental backslashes from PDE.properties
  • Loading branch information
joelmoniz committed Jun 18, 2015
1 parent 9950fa0 commit 0f3f6dc
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 76 deletions.
127 changes: 62 additions & 65 deletions app/src/processing/app/Sketch.java
Expand Up @@ -450,28 +450,27 @@ protected void nameCode(String newName) {
}

if (newName.startsWith(".")) {
Base.showWarning("Problem with rename",
"The name cannot start with a period.");
Base.showWarning(Language.text("name.messages.problem_renaming"),
Language.text("name.messages.starts_with_dot.description"));
return;
}

int dot = newName.lastIndexOf('.');
String newExtension = newName.substring(dot+1).toLowerCase();
if (!mode.validExtension(newExtension)) {
Base.showWarning("Problem with rename",
"\"." + newExtension + "\"" +
"is not a valid extension.");
Base.showWarning(Language.text("name.messages.problem_renaming"),
Language.interpolate("name.messages.invalid_extension.description",
newExtension));
return;
}

// Don't let the user create the main tab as a .java file instead of .pde
if (!mode.isDefaultExtension(newExtension)) {
if (renamingCode) { // If creating a new tab, don't show this error
if (current == code[0]) { // If this is the main tab, disallow
Base.showWarning("Problem with rename",
"The first tab cannot be a ." + newExtension + " file.\n" +
"(It may be time for you to graduate to a\n" +
"\"real\" programming environment, hotshot.)");
Base.showWarning(Language.text("name.messages.problem_renaming"),
Language.interpolate("name.messages.main_java_extension.description",
newExtension));
return;
}
}
Expand All @@ -495,9 +494,9 @@ protected void nameCode(String newName) {
// http://processing.org/bugs/bugzilla/543.html
for (SketchCode c : code) {
if (c != current && sanitaryName.equalsIgnoreCase(c.getPrettyName())) {
Base.showMessage("Nope",
"A file named \"" + c.getFileName() + "\" already exists at\n" +
"\"" + folder.getAbsolutePath() + "\"");
Base.showMessage(Language.text("name.messages.new_sketch_exists"),
Language.interpolate("name.messages.new_sketch_exists.description",
c.getFileName(), folder.getAbsolutePath()));
return;
}
}
Expand All @@ -511,16 +510,17 @@ protected void nameCode(String newName) {
String folderName = newName.substring(0, newName.indexOf('.'));
File newFolder = new File(folder.getParentFile(), folderName);
if (newFolder.exists()) {
Base.showWarning("Cannot Rename",
"Sorry, a sketch (or folder) named " +
"\"" + newName + "\" already exists.");
Base.showWarning(Language.text("name.messages.new_folder_exists"),
Language.interpolate("name.messages.new_folder_exists.description",
newName));
return;
}

// renaming the containing sketch folder
boolean success = folder.renameTo(newFolder);
if (!success) {
Base.showWarning("Error", "Could not rename the sketch folder.");
Base.showWarning(Language.text("name.messages.error"),
Language.text("name.messages.no_rename_folder.description"));
return;
}
// let this guy know where he's living (at least for a split second)
Expand All @@ -540,9 +540,9 @@ protected void nameCode(String newName) {
// This isn't changing folders, just changes the name
newFile = new File(newFolder, newName);
if (!current.renameTo(newFile, newExtension)) {
Base.showWarning("Error",
"Could not rename \"" + current.getFileName() +
"\" to \"" + newFile.getName() + "\"");
Base.showWarning(Language.text("name.messages.error"),
Language.interpolate("name.messages.no_rename_file.description",
current.getFileName(), newFile.getName()));
return;
}

Expand Down Expand Up @@ -572,9 +572,9 @@ protected void nameCode(String newName) {

} else { // else if something besides code[0]
if (!current.renameTo(newFile, newExtension)) {
Base.showWarning("Error",
"Could not rename \"" + current.getFileName() +
"\" to \"" + newFile.getName() + "\"");
Base.showWarning(Language.text("name.messages.error"),
Language.interpolate("name.messages.no_rename_file.description",
current.getFileName(), newFile.getName()));
return;
}
}
Expand All @@ -586,9 +586,10 @@ protected void nameCode(String newName) {
throw new IOException("createNewFile() returned false");
}
} catch (IOException e) {
Base.showWarning("Error",
"Could not create the file \"" + newFile + "\"\n" +
"in \"" + folder.getAbsolutePath() + "\"", e);
Base.showWarning(Language.text("name.messages.error"),
Language.interpolate("name.messages.no_create_file.description",
newFile, folder.getAbsolutePath()),
e);
return;
}
SketchCode newCode = new SketchCode(newFile, newExtension);
Expand Down Expand Up @@ -771,9 +772,8 @@ public boolean save() throws IOException {

if (isReadOnly()) {
// if the files are read-only, need to first do a "save as".
Base.showMessage("Sketch is read-only",
"Some files are marked \"read-only\", so you'll\n" +
"need to re-save this sketch to another location.");
Base.showMessage(Language.text("save_file.messages.is_read_only"),
Language.text("save_file.messages.is_read_only.description"));
// if the user cancels, give up on the save()
if (!saveAs()) return false;
}
Expand Down Expand Up @@ -846,9 +846,9 @@ protected boolean saveAs() throws IOException {
String sanitaryName = Sketch.checkName(newName);
File newFolder = new File(newParentDir, sanitaryName);
if (!sanitaryName.equals(newName) && newFolder.exists()) {
Base.showMessage("Cannot Save",
"A sketch with the cleaned name\n" +
"“" + sanitaryName + "” already exists.");
Base.showMessage(Language.text("save_file.messages.sketch_exists"),
Language.interpolate("save_file.messages.sketch_exists.description",
sanitaryName));
return false;
}
newName = sanitaryName;
Expand All @@ -865,9 +865,9 @@ protected boolean saveAs() throws IOException {
// resaved (with the same name) to another location/folder.
for (int i = 1; i < codeCount; i++) {
if (newName.equalsIgnoreCase(code[i].getPrettyName())) {
Base.showMessage("Nope",
"You can't save the sketch as \"" + newName + "\"\n" +
"because the sketch already has a tab with that name.");
Base.showMessage(Language.text("save_file.messages.tab_exists"),
Language.interpolate("save_file.messages.tab_exists.description",
newName));
return false;
}
}
Expand All @@ -885,9 +885,9 @@ protected boolean saveAs() throws IOException {
String oldPath = folder.getCanonicalPath() + File.separator;

if (newPath.indexOf(oldPath) == 0) {
Base.showWarning("How very Borges of you",
"You cannot save the sketch into a folder\n" +
"inside itself. This would go on forever.", null);
Base.showWarning(Language.text("save_file.messages.recursive_save"),
Language.text("save_file.messages.recursive_save.description"),
null);
return false;
}
} catch (IOException e) { }
Expand Down Expand Up @@ -1022,10 +1022,8 @@ public void handleAddFile() {
// if read-only, give an error
if (isReadOnly()) {
// if the files are read-only, need to first do a "save as".
Base.showMessage("Sketch is Read-Only",
"Some files are marked \"read-only\", so you'll\n" +
"need to re-save the sketch in another location,\n" +
"and try again.");
Base.showMessage(Language.text("add_file.messages.is_read_only"),
Language.text("add_file.messages.is_read_only.description"));
return;
}

Expand Down Expand Up @@ -1101,7 +1099,8 @@ public boolean addFile(File sourceFile) {
// check whether this file already exists
if (destFile.exists()) {
Object[] options = { Language.text("prompt.ok"), Language.text("prompt.cancel") };
String prompt = "Replace the existing version of " + filename + "?";
String prompt = Language.interpolate("add_file.messages.confirm_replace",
filename);
int result = JOptionPane.showOptionDialog(editor,
prompt,
"Replace",
Expand All @@ -1123,19 +1122,19 @@ public boolean addFile(File sourceFile) {
if (replacement) {
boolean muchSuccess = destFile.delete();
if (!muchSuccess) {
Base.showWarning("Error adding file",
"Could not delete the existing '" +
filename + "' file.", null);
Base.showWarning(Language.text("add_file.messages.error_adding"),
Language.interpolate("add_file.messages.cannot_delete.description",
filename),
null);
return false;
}
}

// make sure they aren't the same file
if ((codeExtension == null) && sourceFile.equals(destFile)) {
Base.showWarning("You can't fool me",
"This file has already been copied to the\n" +
"location from which where you're trying to add it.\n" +
"I ain't not doin nuthin'.", null);
Base.showWarning(Language.text("add_file.messages.same_file"),
Language.text("add_file.messages.same_file.description"),
null);
return false;
}

Expand All @@ -1149,8 +1148,10 @@ public boolean addFile(File sourceFile) {
Base.copyFile(sourceFile, destFile);

} catch (IOException e) {
Base.showWarning("Error adding file",
"Could not add '" + filename + "' to the sketch.", e);
Base.showWarning(Language.text("add_file.messages.error_adding"),
Language.interpolate("add_file.messages.cannot_add.description",
filename),
e);
return false;
}
}
Expand Down Expand Up @@ -1250,8 +1251,9 @@ public File makeTempFolder() {
// "Could not create a place to build the sketch.", null);
// }
} catch (IOException e) {
Base.showWarning("Build folder bad",
"Could not find a place to build the sketch.", e);
Base.showWarning(Language.text("temp_dir.messages.bad_build_folder"),
Language.text("temp_dir.messages.bad_build_folder.description"),
e);
}
return null;
}
Expand Down Expand Up @@ -1307,10 +1309,9 @@ public void prepareBuild(File targetFolder) throws SketchException {
public void ensureExistence() {
if (!folder.exists()) {
// Disaster recovery, try to salvage what's there already.
Base.showWarning("Sketch Disappeared",
"The sketch folder has disappeared.\n " +
"Will attempt to re-save in the same location,\n" +
"but anything besides the code will be lost.", null);
Base.showWarning(Language.text("ensure_exist.messages.missing_sketch"),
Language.text("ensure_exist.messages.missing_sketch.description"),
null);
try {
folder.mkdirs();
modified = true;
Expand All @@ -1321,11 +1322,9 @@ public void ensureExistence() {
calcModified();

} catch (Exception e) {
Base.showWarning("Could not re-save sketch",
"Could not properly re-save the sketch. " +
"You may be in trouble at this point,\n" +
"and it might be time to copy and paste " +
"your code to another text editor.", e);
Base.showWarning(Language.text("ensure_exist.messages.unrecoverable"),
Language.text("ensure_exist.messages.unrecoverable.description"),
e);
}
}
}
Expand Down Expand Up @@ -1526,9 +1525,7 @@ static public String checkName(String origName) {

if (!newName.equals(origName)) {
String msg =
"The sketch name had to be modified. Sketch names can only consist\n" +
"of ASCII characters and numbers (but cannot start with a number).\n" +
"They should also be less than 64 characters long.";
Language.text("check_name.messages.is_name_modified");
System.out.println(msg);
}
return newName;
Expand Down
54 changes: 50 additions & 4 deletions build/shared/lib/languages/PDE.properties
Expand Up @@ -369,23 +369,69 @@ editor.footer.console = Console

# New handler
new.messages.is_read_only = Sketch is Read-Only
new.messages.is_read_only.description = Some files are marked \"read-only\", so you will\nneed to re-save the sketch in another location,\nand try again.
new.messages.is_read_only.description = Some files are marked "read-only", so you will\nneed to re-save the sketch in another location,\nand try again.

# Rename handler
rename.messages.is_untitled = Sketch is Untitled
rename.messages.is_untitled.description = How about saving the sketch first\nbefore trying to rename it?
rename.messages.is_modified = Please save the sketch before renaming.
rename.messages.is_read_only = Sketch is Read-Only
rename.messages.is_read_only.description = Some files are marked \"read-only\", so you will\nneed to re-save the sketch in another location,\nand try again.
rename.messages.is_read_only.description = Some files are marked "read-only", so you will\nneed to re-save the sketch in another location,\nand try again.

# Naming handler
name.messages.problem_renaming = Problem with rename
name.messages.starts_with_dot.description = The name cannot start with a period.
name.messages.invalid_extension.description = ".%s" is not a valid extension.
name.messages.main_java_extension.description = The first tab cannot be a .%s file.\n(It may be time for you to graduate to a\n"real" programming environment, hotshot.)
name.messages.new_sketch_exists = Nope
name.messages.new_sketch_exists.description = A file named "%s" already exists at\n"%s"
name.messages.new_folder_exists = Cannot Rename
name.messages.new_folder_exists.description = Sorry, a sketch (or folder) named "%s" already exists.
name.messages.error = Error
name.messages.no_rename_folder.description = Could not rename the sketch folder.
name.messages.no_rename_file.description = Could not rename "%s" to "%s"
name.messages.no_create_file.description = Could not create the file "%s"\nin "%s"

# Delete handler
delete.messages.cannot_delete = Cannot Delete
delete.messages.cannot_delete.description = You cannot delete a sketch that has not been saved.
delete.messages.cannot_delete.file = Could not do it
delete.messages.cannot_delete.file.description = Could not delete
delete.messages.is_read_only = Sketch is Read-Only
delete.messages.is_read_only.description = Some files are marked \"read-only\", so you will\nneed to re-save the sketch in another location,\nand try again.

delete.messages.is_read_only.description = Some files are marked "read-only", so you will\nneed to re-save the sketch in another location,\nand try again.

# Save handler
save_file.messages.is_read_only = Sketch is read-only
save_file.messages.is_read_only.description = Some files are marked "read-only", so you'll\n need to re-save this sketch to another location.
save_file.messages.sketch_exists = Cannot Save
save_file.messages.sketch_exists.description = A sketch with the cleaned name\n“%s” already exists.
save_file.messages.tab_exists = Nope
save_file.messages.tab_exists.description = You can't save the sketch as "%s"\nbecause the sketch already has a tab with that name.
save_file.messages.recursive_save = How very Borges of you
save_file.messages.recursive_save.description = You cannot save the sketch into a folder\ninside itself. This would go on forever.

# Add handler
add_file.messages.is_read_only = Sketch is Read-Only
add_file.messages.is_read_only.description = Some files are marked "read-only", so you'll\nneed to re-save the sketch in another location,\nand try again.
add_file.messages.confirm_replace = Replace the existing version of %s?
add_file.messages.error_adding = Error adding file
add_file.messages.cannot_delete.description = Could not delete the existing '%s' file.
add_file.messages.cannot_add.description = Could not add '%s' to the sketch.
add_file.messages.same_file = You can't fool me
add_file.messages.same_file.description = This file has already been copied to the\nlocation from which where you're trying to add it.\nI ain't not doin nuthin'.

# Temp folder creator
temp_dir.messages.bad_build_folder = Build folder bad
temp_dir.messages.bad_build_folder.description = Could not find a place to build the sketch.

# Ensure Existance
ensure_exist.messages.missing_sketch = Sketch Disappeared
ensure_exist.messages.missing_sketch.description = The sketch folder has disappeared.\nWill attempt to re-save in the same location,\nbut anything besides the code will be lost.
ensure_exist.messages.unrecoverable = Could not re-save sketch
ensure_exist.messages.unrecoverable.description = Could not properly re-save the sketch. You may be in trouble at this point,\nand it might be time to copy and paste your code to another text editor.

# Check name
check_name.messages.is_name_modified = The sketch name had to be modified. Sketch names can only consist\nof ASCII characters and numbers (but cannot start with a number).\nThey should also be less than 64 characters long.

# ---------------------------------------
# Contributions
Expand Down

0 comments on commit 0f3f6dc

Please sign in to comment.