Skip to content

Commit

Permalink
Merge pull request adobe#541 from gideonthomas/updateStrings
Browse files Browse the repository at this point in the history
Change strings to not use placeholders for localizable words when possible
  • Loading branch information
gideonthomas committed Mar 9, 2016
2 parents f447767 + e2b478a commit 2c22e0f
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 64 deletions.
46 changes: 27 additions & 19 deletions locales/en-US/editor.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,32 @@ ERROR_OPENING_FILES=An error occurred when trying to open the following files:
ERROR_SAVING_FILE_TITLE=Error Saving File
# {0} will be replaced with a filename and {1} will be replaced by an error message
ERROR_SAVING_FILE=An error occurred when trying to save the file <span class='dialog-filename'>{0}</span>. {1}
# {0} will be replaced with the localized word "file" or "directory"
ERROR_RENAMING_FILE_TITLE=Error Renaming {0}
# {0} will be replaced with a filename and {1} will be replaced by an error message and {2} will be replaced by the localized word "file" or "directory"
ERROR_RENAMING_FILE=An error occurred when trying to rename the {2} <span class='dialog-filename'>{0}</span>. {1}
# {0} will be replaced with the localized word "file" or "directory"
ERROR_DELETING_FILE_TITLE=Error Deleting {0}
# {0} will be replaced with a filename and {1} will be replaced by an error message and {2} will be replaced by the localized word "file" or "directory"
ERROR_DELETING_FILE=An error occurred when trying to delete the {2} <span class='dialog-filename'>{0}</span>. {1}
# {0} will be replaced with the localized word "file" or "directory"
INVALID_FILENAME_TITLE=Invalid {0}
# {0} will be replaced with the localized word "Directory names" or "File names" and {1} will be replaced with an error message
INVALID_FILENAME_MESSAGE={0} cannot use any system reserved words, end with dots (.) or use any of the following characters: <code class='emphasized'>{1}</code>
ERROR_RENAMING_FILE_TITLE=Error Renaming File
ERROR_RENAMING_DIRECTORY_TITLE=Error Renaming Directory
# {0} will be replaced with a filename and {1} will be replaced by an error message
ERROR_RENAMING_FILE=An error occurred when trying to rename the file <span class='dialog-filename'>{0}</span>. {1}
# {0} will be replaced with a directory name and {1} will be replaced by an error message
ERROR_RENAMING_DIRECTORY=An error occurred when trying to rename the directory <span class='dialog-filename'>{0}</span>. {1}
ERROR_DELETING_FILE_TITLE=Error Deleting File
ERROR_DELETING_DIRECTORY_TITLE=Error Deleting Directory
# {0} will be replaced with a filename and {1} will be replaced by an error message
ERROR_DELETING_FILE=An error occurred when trying to delete the file <span class='dialog-filename'>{0}</span>. {1}
# {0} will be replaced with a directory name and {1} will be replaced by an error message
ERROR_DELETING_DIRECTORY=An error occurred when trying to delete the directory <span class='dialog-filename'>{0}</span>. {1}
INVALID_FILENAME_TITLE=Invalid File Name
INVALID_DIRNAME_TITLE=Invalid Directory Name
# {1} will be replaced with an error message
INVALID_FILENAME_MESSAGE=File names cannot use any system reserved words, end with dots (.) or use any of the following characters: <code class='emphasized'>{1}</code>
# {1} will be replaced with an error message
INVALID_DIRNAME_MESSAGE=Directory names cannot use any system reserved words, end with dots (.) or use any of the following characters: <code class='emphasized'>{1}</code>
# {0} will be replaced with a filename
ENTRY_WITH_SAME_NAME_EXISTS=A file or directory with the name <span class='dialog-filename'>{0}</span> already exists.
# {0} will be replaced with the localized word "file" or "directory"
ERROR_CREATING_FILE_TITLE=Error Creating {0}
# {0} will be replaced with the localized word "file" or "directory" and {1} will be replaced with a file or directory name
ERROR_CREATING_FILE=An error occurred when trying to create the {0} <span class='dialog-filename'>{1}</span>. {2}
ERROR_CREATING_FILE_TITLE=Error Creating File
ERROR_CREATING_DIRECTORY_TITLE=Error Creating Directory
# {1} will be replaced with a file name and {2} will be replaced by an error message
ERROR_CREATING_FILE=An error occurred when trying to create the file <span class='dialog-filename'>{1}</span>. {2}
# {1} will be replaced with a directory name and {2} will be replaced by an error message
ERROR_CREATING_DIRECTORY=An error occurred when trying to create the directory <span class='dialog-filename'>{1}</span>. {2}

# Project max files Error strings

Expand Down Expand Up @@ -139,9 +147,9 @@ COLOR_EDITOR_ORIGINAL_COLOR_SWATCH_TIP=Original Color
COLOR_EDITOR_RGBA_BUTTON_TIP=RGBa Format
COLOR_EDITOR_HEX_BUTTON_TIP=Hex Format
COLOR_EDITOR_HSLA_BUTTON_TIP=HSLa Format
# {0} will be replaced by a color name (like "blue") and {1} will be replaced by a number
# {0} will be replaced by a CSS color name or HEX code (neither of which should be localized) and {1} will be replaced by a number
COLOR_EDITOR_USED_COLOR_TIP_SINGULAR={0} (Used {1} time)
# {0} will be replaced by a color name (like "blue") and {1} will be replaced by a number
# {0} will be replaced by a CSS color name or HEX code (neither of which should be localized) and {1} will be replaced by a number
COLOR_EDITOR_USED_COLOR_TIP_PLURAL={0} (Used {1} times)

# extensions/default/JavaScriptCodeHints
Expand Down Expand Up @@ -180,4 +188,4 @@ ERROR_MOVING_FILE_DIALOG_HEADER=Move Error
# {0} is the name of the file/folder being moved and {1} is the name of the folder it is being moved to
UNEXPECTED_ERROR_MOVING_FILE=An unexpected error occurred when attempting to move {0} to {1}
# {0} is the name of the file/folder being moved and {1} is the name of the folder it is being moved to
ERROR_MOVING_FILE_SAME_NAME=A file or folder with the name {0} already exists in {1}. Consider renaming either one to continue."
ERROR_MOVING_FILE_SAME_NAME=A file or folder with the name {0} already exists in {1}. Consider renaming either one to continue.
102 changes: 57 additions & 45 deletions src/project/ProjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ define(function (require, exports, module) {
ProjectModel = require("project/ProjectModel"),
FileTreeView = require("project/FileTreeView"),
ViewUtils = require("utils/ViewUtils");

// Needed to ensure that menus are set up when we need them.
// See #10115
require("command/DefaultMenus");
Expand Down Expand Up @@ -127,10 +127,10 @@ define(function (require, exports, module) {
* @type {jQueryObject}
*/
var $projectTreeContainer;

/**
* @private
*
*
* Reference to the container of the React component. Everything in this
* node is managed by React.
* @type {Element}
Expand Down Expand Up @@ -178,7 +178,7 @@ define(function (require, exports, module) {
var error = errorInfo.type,
isFolder = errorInfo.isFolder,
name = errorInfo.name;

if (error === FileSystemError.ALREADY_EXISTS) {
_showErrorDialog(ERR_TYPE_CREATE_EXISTS, isFolder, null, name);
} else if (error === ProjectModel.ERROR_INVALID_FILENAME) {
Expand All @@ -192,12 +192,12 @@ define(function (require, exports, module) {
}
}, 10);
}

/**
* @private
*
*
* Reverts to the previous selection (useful if there's an error).
*
*
* @param {string|File} previousPath The previously selected path.
* @param {boolean} switchToWorkingSet True if we need to switch focus to the Working Set
*/
Expand Down Expand Up @@ -519,10 +519,10 @@ define(function (require, exports, module) {
});
return d.promise();
}

/**
* @private
*
*
* Saves the project path.
*/
var _saveProjectPath = function () {
Expand Down Expand Up @@ -560,22 +560,34 @@ define(function (require, exports, module) {
message;
path = StringUtils.breakableUrl(path);

/*
* Bramble - We have modified this to use different strings for
* directories and files instead of replacing the word "file" or
* "directory" in the string itself due to different contexts with
* certain locales. However, we still pass the "file"/"directory"
* strings into the `format` function so that in case the placeholder
* for that is somehow present in the string (for locales we haven't
* translated yet), we won't break compatibility and instead fallback
* to the original localization strategy of replacing the placeholder
* with "file"/"directory"
*/

switch (errType) {
case ERR_TYPE_CREATE:
title = StringUtils.format(Strings.ERROR_CREATING_FILE_TITLE, titleType);
message = StringUtils.format(Strings.ERROR_CREATING_FILE, entryType, path, error);
title = StringUtils.format(Strings[isFolder ? "ERROR_CREATING_DIRECTORY_TITLE" : "ERROR_CREATING_FILE_TITLE"], titleType);
message = StringUtils.format(Strings[isFolder ? "ERROR_CREATING_DIRECTORY" : "ERROR_CREATING_FILE"], entryType, path, error);
break;
case ERR_TYPE_CREATE_EXISTS:
title = StringUtils.format(Strings.INVALID_FILENAME_TITLE, titleType);
title = StringUtils.format(Strings[isFolder ? "INVALID_DIRNAME_TITLE" : "INVALID_FILENAME_TITLE"], titleType);
message = StringUtils.format(Strings.ENTRY_WITH_SAME_NAME_EXISTS, path);
break;
case ERR_TYPE_RENAME:
title = StringUtils.format(Strings.ERROR_RENAMING_FILE_TITLE, titleType);
message = StringUtils.format(Strings.ERROR_RENAMING_FILE, path, error, entryType);
title = StringUtils.format(Strings[isFolder ? "ERROR_RENAMING_DIRECTORY_TITLE" : "ERROR_RENAMING_FILE_TITLE"], titleType);
message = StringUtils.format(Strings[isFolder ? "ERROR_RENAMING_DIRECTORY" : "ERROR_RENAMING_FILE"], path, error, entryType);
break;
case ERR_TYPE_DELETE:
title = StringUtils.format(Strings.ERROR_DELETING_FILE_TITLE, titleType);
message = StringUtils.format(Strings.ERROR_DELETING_FILE, path, error, entryType);
title = StringUtils.format(Strings[isFolder ? "ERROR_DELETING_DIRECTORY_TITLE" : "ERROR_DELETING_FILE_TITLE"], titleType);
message = StringUtils.format(Strings[isFolder ? "ERROR_DELETING_DIRECTORY" : "ERROR_DELETING_FILE"], path, error, entryType);
break;
case ERR_TYPE_LOADING_PROJECT:
title = Strings.ERROR_LOADING_PROJECT;
Expand All @@ -594,8 +606,8 @@ define(function (require, exports, module) {
message = StringUtils.format(Strings.OPEN_DIALOG_ERROR, error);
break;
case ERR_TYPE_INVALID_FILENAME:
title = StringUtils.format(Strings.INVALID_FILENAME_TITLE, isFolder ? Strings.DIRECTORY_NAME : Strings.FILENAME);
message = StringUtils.format(Strings.INVALID_FILENAME_MESSAGE, isFolder ? Strings.DIRECTORY_NAMES_LEDE : Strings.FILENAMES_LEDE, error);
title = StringUtils.format(Strings[isFolder ? "INVALID_DIRNAME_TITLE" : "INVALID_FILENAME_TITLE"], isFolder ? Strings.DIRECTORY_NAME : Strings.FILENAME);
message = StringUtils.format(Strings[isFolder ? "INVALID_DIRNAME_MESSAGE" : "INVALID_FILENAME_MESSAGE"], isFolder ? Strings.DIRECTORY_NAMES_LEDE : Strings.FILENAMES_LEDE, error);
break;
}

Expand All @@ -615,7 +627,7 @@ define(function (require, exports, module) {
* @private
*
* Rerender the file tree view.
*
*
* @param {boolean} forceRender Force the tree to rerender. Should only be needed by extensions that call rerenderTree.
*/
_renderTreeSync = function (forceRender) {
Expand Down Expand Up @@ -707,7 +719,7 @@ define(function (require, exports, module) {
deferred.reject();
}
});

return deferred.promise();
}

Expand All @@ -720,7 +732,7 @@ define(function (require, exports, module) {
// Last resort is Brackets source folder which is guaranteed to exist
deferred.resolve(FileUtils.getNativeBracketsDirectoryPath());
});

return deferred.promise();
}

Expand Down Expand Up @@ -824,7 +836,7 @@ define(function (require, exports, module) {

var projectPrefFullPath = (rootPath + SETTINGS_FILENAME),
file = FileSystem.getFileForPath(projectPrefFullPath);

//Verify that the project preferences file (.brackets.json) is NOT corrupted.
//If corrupted, display the error message and open the file in editor for the user to edit.
FileUtils.readAsText(file)
Expand Down Expand Up @@ -906,7 +918,7 @@ define(function (require, exports, module) {
var perfTimerName = PerfUtils.markStart("Load Project: " + rootPath);

_projectWarnedForTooManyFiles = false;

_setProjectRoot(rootEntry).always(function () {
model.setBaseUrl(PreferencesManager.getViewState("project.baseUrl", context) || "");

Expand Down Expand Up @@ -970,15 +982,15 @@ define(function (require, exports, module) {

/**
* Refresh the project's file tree, maintaining the current selection.
*
*
* Note that the original implementation of this returned a promise to be resolved when the refresh is complete.
* That use is deprecated and `refreshFileTree` is now a "fire and forget" kind of function.
*/
var refreshFileTree = function refreshFileTree() {
FileSystem.clearAllCaches();
return new $.Deferred().resolve().promise();
};

refreshFileTree = _.debounce(refreshFileTree, _refreshDelay);

/**
Expand Down Expand Up @@ -1124,7 +1136,7 @@ define(function (require, exports, module) {
FileSyncManager.syncOpenDocuments();

model.handleFSEvent(entry, added, removed);

// @TODO: DocumentManager should implement its own fsChange handler
// we can clean up the calls to DocumentManager.notifyPathDeleted
// and privatize DocumentManager.notifyPathDeleted as well
Expand All @@ -1133,7 +1145,7 @@ define(function (require, exports, module) {
if (removed) {
removed.forEach(function (file) {
// The call to syncOpenDocuemnts above will not nofify
// document manager about deleted images that are
// document manager about deleted images that are
// not in the working set -- try to clean that up here
DocumentManager.notifyPathDeleted(file.fullPath);
});
Expand All @@ -1156,37 +1168,37 @@ define(function (require, exports, module) {
function forceFinishRename() {
actionCreator.performRename();
}

/**
* @private
*
*
* Sets the width of the selection bar in the file tree.
*
*
* @param {int} width New width value
*/
function _setFileTreeSelectionWidth(width) {
model.setSelectionWidth(width);
_renderTree();
}

// Initialize variables and listeners that depend on the HTML DOM
AppInit.htmlReady(function () {
$projectTreeContainer = $("#project-files-container");
$projectTreeContainer.addClass("jstree jstree-brackets");
$projectTreeContainer.css("overflow", "auto");
$projectTreeContainer.css("position", "relative");

fileTreeViewContainer = $("<div>").appendTo($projectTreeContainer)[0];

model.setSelectionWidth($projectTreeContainer.width());

$(".main-view").click(function (jqEvent) {
if (!jqEvent.target.classList.contains("jstree-rename-input")) {
forceFinishRename();
actionCreator.setContext(null);
}
});

$("#working-set-list-container").on("contentChanged", function () {
$projectTreeContainer.trigger("contentChanged");
});
Expand All @@ -1202,7 +1214,7 @@ define(function (require, exports, module) {
$projectTreeContainer.on("contextmenu", function () {
forceFinishRename();
});

// When a context menu item is selected, we need to clear the context
// because we don't get a beforeContextMenuClose event since Bootstrap
// handles this directly.
Expand All @@ -1219,9 +1231,9 @@ define(function (require, exports, module) {
// we need to render the tree without a delay to not cause selection extension issues (#10573)
_renderTreeSync();
});

_renderTree();

ViewUtils.addScrollerShadow($projectTreeContainer[0]);
});

Expand Down Expand Up @@ -1256,7 +1268,7 @@ define(function (require, exports, module) {
return null;
}


EventDispatcher.makeEventDispatcher(exports);

// Init default project path to welcome project
Expand All @@ -1277,7 +1289,7 @@ define(function (require, exports, module) {
EventDispatcher.on_duringInit(FileViewController, "documentSelectionFocusChange", _documentSelectionFocusChange);
EventDispatcher.on_duringInit(FileViewController, "fileViewFocusChange", _fileViewControllerChange);
EventDispatcher.on_duringInit(MainViewManager, "currentFileChange", _currentFileChange);

// Commands
CommandManager.register(Strings.CMD_OPEN_FOLDER, Commands.FILE_OPEN_FOLDER, openProject);
CommandManager.register(Strings.CMD_PROJECT_SETTINGS, Commands.FILE_PROJECT_SETTINGS, _projectSettings);
Expand All @@ -1288,7 +1300,7 @@ define(function (require, exports, module) {
.on("change", function () {
actionCreator.setSortDirectoriesFirst(PreferencesManager.get(SORT_DIRECTORIES_FIRST));
});

actionCreator.setSortDirectoriesFirst(PreferencesManager.get(SORT_DIRECTORIES_FIRST));

/**
Expand All @@ -1308,7 +1320,7 @@ define(function (require, exports, module) {
*/
renameItemInline = function (entry) {
var d = new $.Deferred();

model.startRename(entry)
.done(function () {
d.resolve();
Expand Down Expand Up @@ -1414,12 +1426,12 @@ define(function (require, exports, module) {
function rerenderTree() {
_renderTree(true);
}


// Private API helpful in testing
exports._actionCreator = actionCreator;
exports._RENDER_DEBOUNCE_TIME = _RENDER_DEBOUNCE_TIME;

// Private API for use with SidebarView
exports._setFileTreeSelectionWidth = _setFileTreeSelectionWidth;

Expand Down

0 comments on commit 2c22e0f

Please sign in to comment.