Skip to content

Commit 02f2a29

Browse files
committed
Stop combining already-translated strings
1 parent bcdfdd2 commit 02f2a29

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

src/compiler/diagnosticMessages.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3735,12 +3735,12 @@
37353735
"code": 95006
37363736
},
37373737

3738-
"enclosing scope": {
3738+
"Extract to {0} in enclosing scope": {
37393739
"category": "Message",
37403740
"code": 95007
37413741
},
37423742

3743-
"{0} scope": {
3743+
"Extract to {0} in {1} scope": {
37443744
"category": "Message",
37453745
"code": 95008
37463746
}

src/services/refactors/extractSymbol.ts

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace ts.refactor.extractSymbol {
4343
// Don't issue refactorings with duplicated names.
4444
// Scopes come back in "innermost first" order, so extractions will
4545
// preferentially go into nearer scopes
46-
const description = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Extract_to_0_in_1), [functionExtraction.description, functionExtraction.scopeDescription]);
46+
const description = functionExtraction.description;
4747
if (!usedFunctionNames.has(description)) {
4848
usedFunctionNames.set(description, true);
4949
functionActions.push({
@@ -58,7 +58,7 @@ namespace ts.refactor.extractSymbol {
5858
// Don't issue refactorings with duplicated names.
5959
// Scopes come back in "innermost first" order, so extractions will
6060
// preferentially go into nearer scopes
61-
const description = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Extract_to_0_in_1), [constantExtraction.description, constantExtraction.scopeDescription]);
61+
const description = constantExtraction.description;
6262
if (!usedConstantNames.has(description)) {
6363
usedConstantNames.set(description, true);
6464
constantActions.push({
@@ -524,7 +524,6 @@ namespace ts.refactor.extractSymbol {
524524

525525
interface Extraction {
526526
readonly description: string;
527-
readonly scopeDescription: string;
528527
readonly errors: ReadonlyArray<Diagnostic>;
529528
}
530529

@@ -542,23 +541,43 @@ namespace ts.refactor.extractSymbol {
542541
const { scopes, readsAndWrites: { functionErrorsPerScope, constantErrorsPerScope } } = getPossibleExtractionsWorker(targetRange, context);
543542
// Need the inner type annotation to avoid https://github.com/Microsoft/TypeScript/issues/7547
544543
const extractions = scopes.map((scope, i): ScopeExtractions => {
544+
const functionDescriptionPart = getDescriptionForFunctionInScope(scope);
545+
const constantDescriptionPart = getDescriptionForConstantInScope(scope);
546+
545547
const scopeDescription = isFunctionLikeDeclaration(scope)
546548
? getDescriptionForFunctionLikeDeclaration(scope)
547549
: isClassLike(scope)
548550
? getDescriptionForClassLikeDeclaration(scope)
549551
: getDescriptionForModuleLikeDeclaration(scope);
552+
553+
let functionDescription: string;
554+
let constantDescription: string;
555+
if (scopeDescription === SpecialScope.Global) {
556+
functionDescription = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Extract_to_0_in_1_scope), [functionDescriptionPart, "global"]);
557+
constantDescription = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Extract_to_0_in_1_scope), [constantDescriptionPart, "global"]);
558+
}
559+
else if (scopeDescription === SpecialScope.Module) {
560+
functionDescription = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Extract_to_0_in_1_scope), [functionDescriptionPart, "module"]);
561+
constantDescription = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Extract_to_0_in_1_scope), [constantDescriptionPart, "module"]);
562+
}
563+
else {
564+
functionDescription = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Extract_to_0_in_1), [functionDescriptionPart, scopeDescription]);
565+
constantDescription = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Extract_to_0_in_1), [constantDescriptionPart, scopeDescription]);
566+
}
567+
568+
// Customize the phrasing for the innermost scope to increase clarity.
569+
if (i === 0 && !isClassLike(scope)) {
570+
constantDescription = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Extract_to_0_in_enclosing_scope), [constantDescriptionPart]);
571+
}
572+
550573
return {
551574
functionExtraction: {
552-
description: getDescriptionForFunctionInScope(scope),
575+
description: functionDescription,
553576
errors: functionErrorsPerScope[i],
554-
scopeDescription,
555577
},
556578
constantExtraction: {
557-
description: getDescriptionForConstantInScope(scope),
579+
description: constantDescription,
558580
errors: constantErrorsPerScope[i],
559-
scopeDescription: (i === 0 && !isClassLike(scope))
560-
? getLocaleSpecificMessage(Diagnostics.enclosing_scope)
561-
: scopeDescription,
562581
},
563582
};
564583
});
@@ -627,10 +646,15 @@ namespace ts.refactor.extractSymbol {
627646
? `class '${scope.name.text}'`
628647
: scope.name ? `class expression '${scope.name.text}'` : "anonymous class expression";
629648
}
630-
function getDescriptionForModuleLikeDeclaration(scope: SourceFile | ModuleBlock): string {
649+
function getDescriptionForModuleLikeDeclaration(scope: SourceFile | ModuleBlock): string | SpecialScope {
631650
return scope.kind === SyntaxKind.ModuleBlock
632651
? `namespace '${scope.parent.name.getText()}'`
633-
: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics._0_scope), [scope.externalModuleIndicator ? "module" : "global"]);
652+
: scope.externalModuleIndicator ? SpecialScope.Module : SpecialScope.Global;
653+
}
654+
655+
const enum SpecialScope {
656+
Module,
657+
Global,
634658
}
635659

636660
function getUniqueName(baseName: string, fileText: string): string {

0 commit comments

Comments
 (0)