Skip to content

Commit 23e2188

Browse files
petebacondarwinjosephperrott
authored andcommitted
docs(localize): add public api markers for CLI integration (angular#39006)
This commit marks the functions and classes that are used by the CLI. PR Close angular#39006
1 parent 5903e8a commit 23e2188

File tree

13 files changed

+44
-8
lines changed

13 files changed

+44
-8
lines changed

packages/localize/src/tools/src/diagnostics.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export type DiagnosticHandlingStrategy = 'error'|'warning'|'ignore';
1414
/**
1515
* This class is used to collect and then report warnings and errors that occur during the execution
1616
* of the tools.
17+
*
18+
* @publicApi used by CLI
1719
*/
1820
export class Diagnostics {
1921
readonly messages: {type: 'warning'|'error', message: string}[] = [];

packages/localize/src/tools/src/extract/extraction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export interface ExtractionOptions {
2323
/**
2424
* Extracts parsed messages from file contents, by parsing the contents as JavaScript
2525
* and looking for occurrences of `$localize` in the source code.
26+
*
27+
* @publicApi used by CLI
2628
*/
2729
export class MessageExtractor {
2830
private basePath: AbsoluteFsPath;

packages/localize/src/tools/src/extract/translation_files/xliff1_translation_serializer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const LEGACY_XLIFF_MESSAGE_LENGTH = 40;
2323
* http://docs.oasis-open.org/xliff/v1.2/xliff-profile-html/xliff-profile-html-1.2.html
2424
*
2525
* @see Xliff1TranslationParser
26+
* @publicApi used by CLI
2627
*/
2728
export class Xliff1TranslationSerializer implements TranslationSerializer {
2829
constructor(

packages/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const MAX_LEGACY_XLIFF_2_MESSAGE_LENGTH = 20;
2222
* http://docs.oasis-open.org/xliff/xliff-core/v2.0/os/xliff-core-v2.0-os.html
2323
*
2424
* @see Xliff2TranslationParser
25+
* @publicApi used by CLI
2526
*/
2627
export class Xliff2TranslationSerializer implements TranslationSerializer {
2728
private currentPlaceholderId = 0;

packages/localize/src/tools/src/extract/translation_files/xmb_translation_serializer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {XmlFile} from './xml_file';
1818
* http://cldr.unicode.org/development/development-process/design-proposals/xmb
1919
*
2020
* @see XmbTranslationParser
21+
* @publicApi used by CLI
2122
*/
2223
export class XmbTranslationSerializer implements TranslationSerializer {
2324
constructor(private basePath: AbsoluteFsPath, private useLegacyIds: boolean) {}

packages/localize/src/tools/src/source_file_utils.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export function isNamedIdentifier(
3636

3737
/**
3838
* Is the given `identifier` declared globally.
39+
*
3940
* @param identifier The identifier to check.
41+
* @publicApi used by CLI
4042
*/
4143
export function isGlobalIdentifier(identifier: NodePath<t.Identifier>) {
4244
return !identifier.scope || !identifier.scope.hasBinding(identifier.node.name);
@@ -46,6 +48,7 @@ export function isGlobalIdentifier(identifier: NodePath<t.Identifier>) {
4648
* Build a translated expression to replace the call to `$localize`.
4749
* @param messageParts The static parts of the message.
4850
* @param substitutions The expressions to substitute into the message.
51+
* @publicApi used by CLI
4952
*/
5053
export function buildLocalizeReplacement(
5154
messageParts: TemplateStringsArray, substitutions: readonly t.Expression[]): t.Expression {
@@ -65,6 +68,7 @@ export function buildLocalizeReplacement(
6568
* to a helper function like `__makeTemplateObject`.
6669
*
6770
* @param call The AST node of the call to process.
71+
* @publicApi used by CLI
6872
*/
6973
export function unwrapMessagePartsFromLocalizeCall(call: NodePath<t.CallExpression>):
7074
[TemplateStringsArray, (ɵSourceLocation | undefined)[]] {
@@ -142,9 +146,11 @@ export function unwrapMessagePartsFromLocalizeCall(call: NodePath<t.CallExpressi
142146
return [ɵmakeTemplateObject(cookedStrings, rawStrings), rawLocations];
143147
}
144148

145-
146-
export function unwrapSubstitutionsFromLocalizeCall(call: NodePath<t.CallExpression>):
147-
[t.Expression[], (ɵSourceLocation | undefined)[]] {
149+
/**
150+
* Parse the localize call expression to extract the arguments that hold the substition expressions.
151+
*
152+
* @publicApi used by CLI
153+
*/
148154
const expressions = call.get('arguments').splice(1);
149155
if (!isArrayOfExpressions(expressions)) {
150156
const badExpression = expressions.find(expression => !expression.isExpression())!;
@@ -157,8 +163,11 @@ export function unwrapSubstitutionsFromLocalizeCall(call: NodePath<t.CallExpress
157163
];
158164
}
159165

160-
export function unwrapMessagePartsFromTemplateLiteral(elements: NodePath<t.TemplateElement>[]):
161-
[TemplateStringsArray, (ɵSourceLocation | undefined)[]] {
166+
/**
167+
* Parse the tagged template literal to extract the message parts.
168+
*
169+
* @publicApi used by CLI
170+
*/
162171
const cooked = elements.map(q => {
163172
if (q.node.value.cooked === undefined) {
164173
throw new BabelParseError(
@@ -172,9 +181,11 @@ export function unwrapMessagePartsFromTemplateLiteral(elements: NodePath<t.Templ
172181
return [ɵmakeTemplateObject(cooked, raw), locations];
173182
}
174183

175-
export function unwrapExpressionsFromTemplateLiteral(quasi: NodePath<t.TemplateLiteral>):
176-
[t.Expression[], (ɵSourceLocation | undefined)[]] {
177-
return [quasi.node.expressions, quasi.get('expressions').map(e => getLocation(e))];
184+
/**
185+
* Parse the tagged template literal to extract the interpolation expressions.
186+
*
187+
* @publicApi used by CLI
188+
*/
178189
}
179190

180191
/**
@@ -321,6 +332,7 @@ export interface TranslatePluginOptions {
321332
* Translate the text of the given message, using the given translations.
322333
*
323334
* Logs as warning if the translation is not available
335+
* @publicApi used by CLI
324336
*/
325337
export function translate(
326338
diagnostics: Diagnostics, translations: Record<string, ɵParsedTranslation>,

packages/localize/src/tools/src/translate/source_files/es2015_translate_plugin.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import {Diagnostics} from '../../diagnostics';
1313

1414
import {buildCodeFrameError, buildLocalizeReplacement, isBabelParseError, isLocalize, translate, TranslatePluginOptions, unwrapMessagePartsFromTemplateLiteral} from '../../source_file_utils';
1515

16+
/**
17+
* Create a Babel plugin that can be used to do compile-time translation of `$localize` tagged
18+
* messages.
19+
*
20+
* @publicApi used by CLI
21+
*/
1622
export function makeEs2015TranslatePlugin(
1723
diagnostics: Diagnostics, translations: Record<string, ɵParsedTranslation>,
1824
{missingTranslation = 'error', localizeName = '$localize'}: TranslatePluginOptions = {}):

packages/localize/src/tools/src/translate/source_files/es5_translate_plugin.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import {Diagnostics} from '../../diagnostics';
1313

1414
import {buildCodeFrameError, buildLocalizeReplacement, isBabelParseError, isLocalize, translate, TranslatePluginOptions, unwrapMessagePartsFromLocalizeCall, unwrapSubstitutionsFromLocalizeCall} from '../../source_file_utils';
1515

16+
/**
17+
* Create a Babel plugin that can be used to do compile-time translation of `$localize` tagged
18+
* messages.
19+
*
20+
* @publicApi used by CLI
21+
*/
1622
export function makeEs5TranslatePlugin(
1723
diagnostics: Diagnostics, translations: Record<string, ɵParsedTranslation>,
1824
{missingTranslation = 'error', localizeName = '$localize'}: TranslatePluginOptions = {}):

packages/localize/src/tools/src/translate/source_files/locale_plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {isLocalize, TranslatePluginOptions} from '../../source_file_utils';
2121
*
2222
* @param locale The name of the locale to inline into the code.
2323
* @param options Additional options including the name of the `$localize` function.
24+
* @publicApi used by CLI
2425
*/
2526
export function makeLocalePlugin(
2627
locale: string, {localizeName = '$localize'}: TranslatePluginOptions = {}): PluginObj {

packages/localize/src/tools/src/translate/translation_files/translation_parsers/simple_json_translation_parser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {ParseAnalysis, ParsedTranslationBundle, TranslationParser} from './trans
2525
* ```
2626
*
2727
* @see SimpleJsonTranslationSerializer
28+
* @publicApi used by CLI
2829
*/
2930
export class SimpleJsonTranslationParser implements TranslationParser<Object> {
3031
/**

0 commit comments

Comments
 (0)