Skip to content

Commit

Permalink
fixup! feat(ivy): i18n compiler support for i18nStart and i18nEnd ins…
Browse files Browse the repository at this point in the history
…tructions
  • Loading branch information
AndrewKushnir committed Oct 17, 2018
1 parent fe2b743 commit e58233d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ describe('i18n support in the view compiler', () => {
@Component({
selector: 'my-component',
template: \`
<div i18n="meaningA|descA@@idA">Hello world (in i18n section)!</div>
<div i18n-title="meaningB|descB@@idB" title="introduction">Hello world</div>
<div i18n="meaningA|descA@@idA">Content A</div>
<div i18n-title="meaningB|descB@@idB" title="Title B">Content B</div>
<div i18n-title="meaningC" title="Title C">Content C</div>
<div i18n-title="meaningD|descD" title="Title D">Content D</div>
<div i18n-title="meaningE@@idE" title="Title E">Content E</div>
<div i18n-title="@@idF" title="Title F">Content F</div>
\`
})
export class MyComponent {}
Expand All @@ -40,26 +44,63 @@ describe('i18n support in the view compiler', () => {

const template = `
/**
* @desc descA
* @desc [BACKUP_MESSAGE_ID:idA] descA
* @meaning meaningA
*/
const $MSG_APP_SPEC_TS_0$ = goog.getMsg("Hello world (in i18n section)!");
const $MSG_APP_SPEC_TS_0$ = goog.getMsg("Content A");
/**
* @desc descB
* @desc [BACKUP_MESSAGE_ID:idB] descB
* @meaning meaningB
*/
const $MSG_APP_SPEC_TS_1$ = goog.getMsg("introduction");
const $MSG_APP_SPEC_TS_1$ = goog.getMsg("Title B");
const $_c2$ = ["title", $MSG_APP_SPEC_TS_1$, 0];
/**
* @desc meaningC
*/
const $MSG_APP_SPEC_TS_3$ = goog.getMsg("Title C");
const $_c4$ = ["title", $MSG_APP_SPEC_TS_3$, 0];
/**
* @desc descD
* @meaning meaningD
*/
const $MSG_APP_SPEC_TS_5$ = goog.getMsg("Title D");
const $_c6$ = ["title", $MSG_APP_SPEC_TS_5$, 0];
/**
* @desc [BACKUP_MESSAGE_ID:idE] meaningE
*/
const $MSG_APP_SPEC_TS_7$ = goog.getMsg("Title E");
const $_c8$ = ["title", $MSG_APP_SPEC_TS_7$, 0];
/**
* @desc [BACKUP_MESSAGE_ID:idF]
*/
const $MSG_APP_SPEC_TS_9$ = goog.getMsg("Title F");
const $_c10$ = ["title", $MSG_APP_SPEC_TS_9$, 0];
template: function MyComponent_Template(rf, ctx) {
if (rf & 1) {
$r3$.ɵelementStart(0, "div");
$r3$.ɵi18nStart(1, MSG_APP_SPEC_TS_0);
$r3$.ɵi18nStart(1, $MSG_APP_SPEC_TS_0$);
$r3$.ɵi18nEnd();
$r3$.ɵelementEnd();
$r3$.ɵelementStart(2, "div");
$r3$.ɵi18nAttribute(3, _c2);
$r3$.ɵtext(4, "Hello world");
$r3$.ɵi18nAttribute(3, $_c2$);
$r3$.ɵtext(4, "Content B");
$r3$.ɵelementEnd();
$r3$.ɵelementStart(5, "div");
$r3$.ɵi18nAttribute(6, $_c4$);
$r3$.ɵtext(7, "Content C");
$r3$.ɵelementEnd();
$r3$.ɵelementStart(8, "div");
$r3$.ɵi18nAttribute(9, $_c6$);
$r3$.ɵtext(10, "Content D");
$r3$.ɵelementEnd();
$r3$.ɵelementStart(11, "div");
$r3$.ɵi18nAttribute(12, $_c8$);
$r3$.ɵtext(13, "Content E");
$r3$.ɵelementEnd();
$r3$.ɵelementStart(14, "div");
$r3$.ɵi18nAttribute(15, $_c10$);
$r3$.ɵtext(16, "Content F");
$r3$.ɵelementEnd();
}
}
Expand Down
9 changes: 5 additions & 4 deletions packages/compiler/src/constant_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,14 @@ function isVariable(e: o.Expression): e is o.ReadVarExpr {
return e instanceof o.ReadVarExpr;
}

// Converts i18n meta informations for a message (description, meaning) to a JsDoc statement
// formatted as expected by the Closure compiler.
// Converts i18n meta informations for a message (id, description, meaning)
// to a JsDoc statement formatted as expected by the Closure compiler.
function i18nMetaToDocStmt(meta: I18nMeta): o.JSDocCommentStmt|null {
const tags: o.JSDocTag[] = [];

if (meta.description) {
tags.push({tagName: o.JSDocTagName.Desc, text: meta.description});
if (meta.id || meta.description) {
const text = meta.id ? `[BACKUP_MESSAGE_ID:${meta.id}] ${meta.description}` : meta.description;
tags.push({tagName: o.JSDocTagName.Desc, text: text !.trim()});
}

if (meta.meaning) {
Expand Down
1 change: 0 additions & 1 deletion packages/compiler/src/render3/view/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export function parseI18nMeta(meta?: string): I18nMeta {
let description: string|undefined;

if (meta) {
// TODO(vicb): figure out how to force a message ID with closure ?
const idIndex = meta.indexOf(I18N_ID_SEPARATOR);
const descIndex = meta.indexOf(I18N_MEANING_SEPARATOR);
let meaningAndDesc: string;
Expand Down

0 comments on commit e58233d

Please sign in to comment.