-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(extractor): add mapping between localization key and component
- Loading branch information
1 parent
ce5b7a6
commit a37894d
Showing
8 changed files
with
71 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './common'; | ||
export * from './config-doc'; | ||
export * from './localization'; | ||
export * from './parser-factory'; | ||
export * from './tsdoc'; | ||
export * from './validator'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import * as ts from 'typescript'; | ||
|
||
const localizationDecoratorName = 'Localization'; | ||
|
||
/** | ||
* Retrieve the localization json files from TS Code | ||
* | ||
* @param node TSNode of the angular component class | ||
* @param source Ts file source | ||
*/ | ||
export function getLocalizationFileFromAngularElement(node: ts.ClassDeclaration): string[] | undefined { | ||
const localizationPaths: string[] = []; | ||
node.forEachChild((item) => { | ||
if (!ts.isPropertyDeclaration(item)) { | ||
return; | ||
} | ||
|
||
item.forEachChild((decorator) => { | ||
if ( | ||
!ts.isDecorator(decorator) | ||
|| !ts.isCallExpression(decorator.expression) | ||
|| !ts.isIdentifier(decorator.expression.expression) | ||
|| decorator.expression.expression.escapedText !== localizationDecoratorName | ||
) { | ||
return; | ||
} | ||
|
||
const firstArg = decorator.expression.arguments[0]; | ||
if (!firstArg || !ts.isStringLiteral(firstArg)) { | ||
return; | ||
} | ||
|
||
localizationPaths.push(firstArg.text); | ||
}); | ||
}); | ||
|
||
return localizationPaths.length ? localizationPaths : undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters