refactor(localize): include text in original location of extracted messages (#38536)
When extracting messages, source-mapping information is used to find the original location of the message being extracted. This commit will now include the text from the original source in the message location so that it can be serialized into the translation file. PR Close #38536
This commit is contained in:
parent
23f855b300
commit
bdba1a062d
|
@ -5,7 +5,7 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* Use of this source code is governed by an MIT-style license that can be
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {AbsoluteFsPath, FileSystem, PathSegment} from '@angular/compiler-cli/src/ngtsc/file_system';
|
import {AbsoluteFsPath, FileSystem} from '@angular/compiler-cli/src/ngtsc/file_system';
|
||||||
import {Logger} from '@angular/compiler-cli/src/ngtsc/logging';
|
import {Logger} from '@angular/compiler-cli/src/ngtsc/logging';
|
||||||
import {SourceFile, SourceFileLoader} from '@angular/compiler-cli/src/ngtsc/sourcemaps';
|
import {SourceFile, SourceFileLoader} from '@angular/compiler-cli/src/ngtsc/sourcemaps';
|
||||||
import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize';
|
import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize';
|
||||||
|
@ -103,6 +103,11 @@ export class MessageExtractor {
|
||||||
const end = (originalEnd !== null && originalEnd.file === originalStart.file) ?
|
const end = (originalEnd !== null && originalEnd.file === originalStart.file) ?
|
||||||
{line: originalEnd.line, column: originalEnd.column} :
|
{line: originalEnd.line, column: originalEnd.column} :
|
||||||
start;
|
start;
|
||||||
return {file: originalStart.file, start, end};
|
const originalSourceFile =
|
||||||
|
sourceFile.sources.find(sf => sf?.sourcePath === originalStart.file)!;
|
||||||
|
const startPos = originalSourceFile.startOfLinePositions[start.line] + start.column;
|
||||||
|
const endPos = originalSourceFile.startOfLinePositions[end.line] + end.column;
|
||||||
|
const text = originalSourceFile.contents.substring(startPos, endPos);
|
||||||
|
return {file: originalStart.file, start, end, text};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue