mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-12 01:48:33 -05:00
Merge pull request #18936 from amcasey/GH18899
Localize more Extract Function/Constant strings
This commit is contained in:
@@ -3733,5 +3733,15 @@
|
||||
"Extract constant": {
|
||||
"category": "Message",
|
||||
"code": 95006
|
||||
},
|
||||
|
||||
"Extract to {0} in enclosing scope": {
|
||||
"category": "Message",
|
||||
"code": 95007
|
||||
},
|
||||
|
||||
"Extract to {0} in {1} scope": {
|
||||
"category": "Message",
|
||||
"code": 95008
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace ts.refactor.extractSymbol {
|
||||
const extractSymbol: Refactor = {
|
||||
name: "Extract Symbol",
|
||||
description: Diagnostics.Extract_symbol.message,
|
||||
description: getLocaleSpecificMessage(Diagnostics.Extract_symbol),
|
||||
getAvailableActions,
|
||||
getEditsForAction,
|
||||
};
|
||||
@@ -43,7 +43,7 @@ namespace ts.refactor.extractSymbol {
|
||||
// Don't issue refactorings with duplicated names.
|
||||
// Scopes come back in "innermost first" order, so extractions will
|
||||
// preferentially go into nearer scopes
|
||||
const description = formatStringFromArgs(Diagnostics.Extract_to_0_in_1.message, [functionExtraction.description, functionExtraction.scopeDescription]);
|
||||
const description = functionExtraction.description;
|
||||
if (!usedFunctionNames.has(description)) {
|
||||
usedFunctionNames.set(description, true);
|
||||
functionActions.push({
|
||||
@@ -58,7 +58,7 @@ namespace ts.refactor.extractSymbol {
|
||||
// Don't issue refactorings with duplicated names.
|
||||
// Scopes come back in "innermost first" order, so extractions will
|
||||
// preferentially go into nearer scopes
|
||||
const description = formatStringFromArgs(Diagnostics.Extract_to_0_in_1.message, [constantExtraction.description, constantExtraction.scopeDescription]);
|
||||
const description = constantExtraction.description;
|
||||
if (!usedConstantNames.has(description)) {
|
||||
usedConstantNames.set(description, true);
|
||||
constantActions.push({
|
||||
@@ -78,7 +78,7 @@ namespace ts.refactor.extractSymbol {
|
||||
if (functionActions.length) {
|
||||
infos.push({
|
||||
name: extractSymbol.name,
|
||||
description: Diagnostics.Extract_function.message,
|
||||
description: getLocaleSpecificMessage(Diagnostics.Extract_function),
|
||||
actions: functionActions
|
||||
});
|
||||
}
|
||||
@@ -86,7 +86,7 @@ namespace ts.refactor.extractSymbol {
|
||||
if (constantActions.length) {
|
||||
infos.push({
|
||||
name: extractSymbol.name,
|
||||
description: Diagnostics.Extract_constant.message,
|
||||
description: getLocaleSpecificMessage(Diagnostics.Extract_constant),
|
||||
actions: constantActions
|
||||
});
|
||||
}
|
||||
@@ -525,7 +525,6 @@ namespace ts.refactor.extractSymbol {
|
||||
|
||||
interface Extraction {
|
||||
readonly description: string;
|
||||
readonly scopeDescription: string;
|
||||
readonly errors: ReadonlyArray<Diagnostic>;
|
||||
}
|
||||
|
||||
@@ -543,23 +542,43 @@ namespace ts.refactor.extractSymbol {
|
||||
const { scopes, readsAndWrites: { functionErrorsPerScope, constantErrorsPerScope } } = getPossibleExtractionsWorker(targetRange, context);
|
||||
// Need the inner type annotation to avoid https://github.com/Microsoft/TypeScript/issues/7547
|
||||
const extractions = scopes.map((scope, i): ScopeExtractions => {
|
||||
const functionDescriptionPart = getDescriptionForFunctionInScope(scope);
|
||||
const constantDescriptionPart = getDescriptionForConstantInScope(scope);
|
||||
|
||||
const scopeDescription = isFunctionLikeDeclaration(scope)
|
||||
? getDescriptionForFunctionLikeDeclaration(scope)
|
||||
: isClassLike(scope)
|
||||
? getDescriptionForClassLikeDeclaration(scope)
|
||||
: getDescriptionForModuleLikeDeclaration(scope);
|
||||
|
||||
let functionDescription: string;
|
||||
let constantDescription: string;
|
||||
if (scopeDescription === SpecialScope.Global) {
|
||||
functionDescription = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Extract_to_0_in_1_scope), [functionDescriptionPart, "global"]);
|
||||
constantDescription = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Extract_to_0_in_1_scope), [constantDescriptionPart, "global"]);
|
||||
}
|
||||
else if (scopeDescription === SpecialScope.Module) {
|
||||
functionDescription = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Extract_to_0_in_1_scope), [functionDescriptionPart, "module"]);
|
||||
constantDescription = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Extract_to_0_in_1_scope), [constantDescriptionPart, "module"]);
|
||||
}
|
||||
else {
|
||||
functionDescription = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Extract_to_0_in_1), [functionDescriptionPart, scopeDescription]);
|
||||
constantDescription = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Extract_to_0_in_1), [constantDescriptionPart, scopeDescription]);
|
||||
}
|
||||
|
||||
// Customize the phrasing for the innermost scope to increase clarity.
|
||||
if (i === 0 && !isClassLike(scope)) {
|
||||
constantDescription = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Extract_to_0_in_enclosing_scope), [constantDescriptionPart]);
|
||||
}
|
||||
|
||||
return {
|
||||
functionExtraction: {
|
||||
description: getDescriptionForFunctionInScope(scope),
|
||||
description: functionDescription,
|
||||
errors: functionErrorsPerScope[i],
|
||||
scopeDescription,
|
||||
},
|
||||
constantExtraction: {
|
||||
description: getDescriptionForConstantInScope(scope),
|
||||
description: constantDescription,
|
||||
errors: constantErrorsPerScope[i],
|
||||
scopeDescription: (i === 0 && !isClassLike(scope))
|
||||
? "enclosing scope" // Like "global scope" and "module scope", this is not localized.
|
||||
: scopeDescription,
|
||||
},
|
||||
};
|
||||
});
|
||||
@@ -628,10 +647,15 @@ namespace ts.refactor.extractSymbol {
|
||||
? `class '${scope.name.text}'`
|
||||
: scope.name ? `class expression '${scope.name.text}'` : "anonymous class expression";
|
||||
}
|
||||
function getDescriptionForModuleLikeDeclaration(scope: SourceFile | ModuleBlock): string {
|
||||
function getDescriptionForModuleLikeDeclaration(scope: SourceFile | ModuleBlock): string | SpecialScope {
|
||||
return scope.kind === SyntaxKind.ModuleBlock
|
||||
? `namespace '${scope.parent.name.getText()}'`
|
||||
: scope.externalModuleIndicator ? "module scope" : "global scope";
|
||||
: scope.externalModuleIndicator ? SpecialScope.Module : SpecialScope.Global;
|
||||
}
|
||||
|
||||
const enum SpecialScope {
|
||||
Module,
|
||||
Global,
|
||||
}
|
||||
|
||||
function getUniqueName(baseName: string, fileText: string): string {
|
||||
|
||||
Reference in New Issue
Block a user