Skip to content

Commit

Permalink
fixup! WIP: use closure for translations
Browse files Browse the repository at this point in the history
  • Loading branch information
ocombe committed Mar 9, 2018
1 parent d3fdd3b commit d790f3f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions packages/compiler/src/render3/r3_view_compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,7 @@ class TemplateDefinitionBuilder implements TemplateAstVisitor, LocalResolver {
// Add attributes array
const attributes: o.Expression[] = [];
for (let attr of astAttrs) {
let value = o.literal(attr.value, o.STRING_TYPE, attr.sourceSpan);
let i18nValue: o.InvokeFunctionExpr|null = null;
if(inI18nNode && i18nAttrs.indexOf(attr.name) !== -1) {
i18nValue = o.variable(GOOG_GET_MSG).callFn([value]);
}
attributes.push(o.literal(attr.name), i18nValue || value);
attributes.push(o.literal(attr.name), this.translate(attr));
}
parameters.push(
attributes.length > 0 ?
Expand Down Expand Up @@ -744,7 +739,7 @@ class TemplateDefinitionBuilder implements TemplateAstVisitor, LocalResolver {
// Text is defined in creation mode only.
this.instruction(
this._creationMode, ast.sourceSpan, R3.text, o.literal(this.allocateDataSlot()),
o.literal(ast.value));
this.translate(ast));
}

// These should be handled in the template or element directly
Expand Down Expand Up @@ -786,6 +781,14 @@ class TemplateDefinitionBuilder implements TemplateAstVisitor, LocalResolver {
private bind(implicit: o.Expression, value: AST, sourceSpan: ParseSourceSpan): o.Expression {
return this.convertPropertyBinding(implicit, value);
}

private translate(ast: TextAst|AttrAst): o.Expression {
const value = o.literal(ast.value, o.STRING_TYPE, ast.sourceSpan);
if(this._inI18n) {
return o.variable(GOOG_GET_MSG).callFn([value]);
}
return value;
}
}

function getQueryPredicate(query: CompileQueryMetadata, outputCtx: OutputContext): o.Expression {
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler/test/render3/r3_view_compiler_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ describe('r3_view_compiler', () => {
template: function MyComponent_Template(ctx: IDENT, cm: IDENT) {
if (cm) {
$r3$.ɵE(0, 'div', $r3$.ɵf1($c1$, goog.getMsg('introduction')));
$r3$.ɵT(1, 'Hello world');
$r3$.ɵT(1, goog.getMsg('Hello world'));
$r3$.ɵe();
$r3$.ɵE(2,'div');
$r3$.ɵT(3,'&');
$r3$.ɵe();
$r3$.ɵE(4,'div');
$r3$.ɵT(5,'farewell');
$r3$.ɵT(5, goog.getMsg('farewell'));
$r3$.ɵe();
}
}
Expand Down

0 comments on commit d790f3f

Please sign in to comment.