提交 ea01d9f4 编写于 作者: J Josh Goldberg

Added pluralization checks to search's replace-all

Fixes #17146.
上级 e68ab660
......@@ -341,13 +341,11 @@ export class SearchViewlet extends Viewlet {
let occurrences = this.viewModel.searchResult.count();
let fileCount = this.viewModel.searchResult.fileCount();
let replaceValue = this.searchWidget.getReplaceValue() || '';
let afterReplaceAllMessage = replaceValue ? nls.localize('replaceAll.message', "Replaced {0} occurrences across {1} files with {2}.", occurrences, fileCount, replaceValue)
: nls.localize('removeAll.message', "Removed {0} occurrences across {1} files.", occurrences, fileCount);
let afterReplaceAllMessage = this.buildAfterReplaceAllMessage(occurrences, fileCount, replaceValue);
let confirmation = {
title: nls.localize('replaceAll.confirmation.title', "Replace All"),
message: replaceValue ? nls.localize('replaceAll.confirmation.message', "Replace {0} occurrences across {1} files with '{2}'?", occurrences, fileCount, replaceValue)
: nls.localize('removeAll.confirmation.message', "Remove {0} occurrences across {1} files?", occurrences, fileCount),
message: this.buildReplaceAllConfirmationMessage(occurrences, fileCount, replaceValue),
primaryButton: nls.localize('replaceAll.confirm.button', "Replace")
};
......@@ -365,6 +363,70 @@ export class SearchViewlet extends Viewlet {
}
}
private buildAfterReplaceAllMessage(occurrences: number, fileCount: number, replaceValue?: string) {
if (occurrences === 1) {
if (fileCount === 1) {
if (replaceValue) {
return nls.localize('replaceAll.occurrence.file.message', "Replaced {0} occurrence across {1} file with '{2}'.", occurrences, fileCount, replaceValue);
}
return nls.localize('removeAll.occurrence.file.message', "Replaced {0} occurrence across {1} file'.", occurrences, fileCount);
}
if (replaceValue) {
return nls.localize('replaceAll.occurrence.files.message', "Replaced {0} occurrence across {1} files with '{2}'.", occurrences, fileCount, replaceValue);
}
return nls.localize('removeAll.occurrence.files.message', "Replaced {0} occurrence across {1} files.", occurrences, fileCount);
}
if (fileCount === 1) {
if (replaceValue) {
return nls.localize('replaceAll.occurrences.file.message', "Replaced {0} occurrences across {1} file with '{2}'.", occurrences, fileCount, replaceValue);
}
return nls.localize('removeAll.occurrences.file.message', "Replaced {0} occurrences across {1} file'.", occurrences, fileCount);
}
if (replaceValue) {
return nls.localize('replaceAll.occurrences.files.message', "Replaced {0} occurrences across {1} files with '{2}'.", occurrences, fileCount, replaceValue);
}
return nls.localize('removeAll.occurrences.files.message', "Replaced {0} occurrences across {1} files.", occurrences, fileCount);
}
private buildReplaceAllConfirmationMessage(occurrences: number, fileCount: number, replaceValue?: string) {
if (occurrences === 1) {
if (fileCount === 1) {
if (replaceValue) {
return nls.localize('removeAll.occurrence.file.confirmation.message', "Replace {0} occurrence across {1} file with '{2}'?", occurrences, fileCount, replaceValue);
}
return nls.localize('replaceAll.occurrence.file.confirmation.message', "Replace {0} occurrence across {1} file'?", occurrences, fileCount);
}
if (replaceValue) {
return nls.localize('removeAll.occurrence.files.confirmation.message', "Replace {0} occurrence across {1} files with '{2}'?", occurrences, fileCount, replaceValue);
}
return nls.localize('replaceAll.occurrence.files.confirmation.message', "Replace {0} occurrence across {1} files?", occurrences, fileCount);
}
if (fileCount === 1) {
if (replaceValue) {
return nls.localize('removeAll.occurrences.file.confirmation.message', "Replace {0} occurrences across {1} file with '{2}'?", occurrences, fileCount, replaceValue);
}
return nls.localize('replaceAll.occurrences.file.confirmation.message', "Replace {0} occurrences across {1} file'?", occurrences, fileCount);
}
if (replaceValue) {
return nls.localize('removeAll.occurrences.files.confirmation.message', "Replace {0} occurrences across {1} files with '{2}'?", occurrences, fileCount, replaceValue);
}
return nls.localize('replaceAll.occurrences.files.confirmation.message', "Replace {0} occurrences across {1} files?", occurrences, fileCount);
}
private clearMessage(): Builder {
return this.messages.empty().show()
.asContainer().div({ 'class': 'message' })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册