internationalize function

List<TemplateAst> internationalize(
  1. StandaloneTemplateAst parent,
  2. I18nMetadata metadata,
  3. int? ngContentIndex
)

Internationalizes the children of a metadata-annotated parent node.

The children are converted to an internationalization-aware AST that handles rendering the translation for the current locale.

The provided ngContentIndex should match text within the parent's context.

Implementation

List<ng.TemplateAst> internationalize(
  ast.StandaloneTemplateAst parent,
  I18nMetadata metadata,
  int? ngContentIndex,
) {
  final i18nMessage = _message(parent.childNodes, metadata);
  if (i18nMessage == null) {
    CompileContext.current.reportAndRecover(BuildError.forSourceSpan(
      parent.sourceSpan,
      'Internationalized messages must contain text',
    ));
    return [];
  }
  return [
    ng.I18nTextAst(
      i18nMessage,
      ngContentIndex,
      _spanWithin(parent),
    )
  ];
}