New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Building blocks for ivy/i18n + demo #22654
Building blocks for ivy/i18n + demo #22654
Conversation
import {Identifiers as R3} from './r3_identifiers'; | ||
import {_I18N_ATTR, _I18N_ATTR_PREFIX} from "../i18n/extractor_merger"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate ? (extractor_merger will be removed)
}; | ||
|
||
const template = ` | ||
import * as $g1$ from 'goog'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we should not import (assume it is available globally)
const template = ` | ||
import * as $g1$ from 'goog'; | ||
… | ||
const $c1$ = ['title', $g1$.getMsg('introduction')]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and generate goog.getMsg(...)
enforce "goog".
Also I think we should generate:
// There might be a comment here to add description and meaning
const UPPER_CASE_NAME = goog.getMsg('...');
const $c1$ = ['title', UPPER_CASE_NAME];
@Component({ | ||
selector: 'my-component', | ||
template: \` | ||
<div i18n i18n-title title="introduction">Hello <b>{{name}}<i>!</i><i>!</i></b></div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update to only translate:
- static text,
- static attributes.
For this first version we will not handle html nor expression nor ICU
const $c1$ = ['title', $g1$.getMsg('introduction')]; | ||
… | ||
template: function MyComponent_Template(ctx: IDENT, cm: IDENT) { | ||
const $r1$ = {b:[2], i:[4, 6]}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
placeholder names should be quoted (else they might get renamed by Closure)
I have added some inline comments. As a general rule please add commits with finer granularity:
It is easier to start with multiple commits and to squash them if there are too many rather than split commits afterwards. Having multiple commits ease the reviewer job - and we will probably have multiple rounds of review here. Thanks. |
2361137
to
d3fdd3b
Compare
You can preview d790f3f at https://pr22654-d790f3f.ngbuilds.io/. |
@@ -327,6 +338,11 @@ class TemplateDefinitionBuilder implements TemplateAstVisitor, LocalResolver { | |||
private _valueConverter: ValueConverter; | |||
private unsupported = unsupported; | |||
private invalid = invalid; | |||
private _phMaps: {[name: string]: number[]}[] = [{}]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_phMaps
vs _placeholderRegistry
be consistent with naming please.
A comment on phMaps
(and other props) would certainly be helpful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove placeholderRegistry
since I don't need it anymore (it's a leftover from previous code).
None of the other props has comments on it, that's why I didn't add comments on those either (you usually tell me to remove the comments that you find useless)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remember what you told me this morning about the lack of comments ;)
const elementIndex = this.allocateDataSlot(); | ||
let componentIndex: number|undefined = undefined; | ||
const referenceDataSlots = new Map<string, number>(); | ||
let astAttrs = ast.attrs; | ||
|
||
/** Start i18n **/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Start i18n" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small placeholder to help me find my code for now :D
I'll remove it since I found out about bookmarks on webstorm!
this._phMapIndex += 1; | ||
this._phMaps[this._phMapIndex] = {}; | ||
this._placeholderRegistry = new PlaceholderRegistry(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else ?
if(attr.name === I18N_ATTR) { | ||
this._inI18n = true; | ||
this._i18nBlockMeta = this.parseI18nMeta(attr.value); | ||
inI18nNode = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vs in18n
?
Maybe inI18nNode
vs isI18nNode
would be clearer ?
|
||
if(this._inI18n) { | ||
if(!inI18nNode) { | ||
const phName = ast.name.toLowerCase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ast.name.toLowerCase()
could lead to collisions.
How are those handled ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same way they are handled in src/i18n/serializers/placeholder.ts right now: they're not
a tag name is the same thing in lowercase and in uppercase (ie <DIV>
and <div>
are equivalent), I don't think that there is a risk of collision here, unless there's a special case I'm not aware of?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tag names are case sensitive in angular.
removing the merge label until we can make the CircleCI build pass |
3d92a9f
to
a29a3ed
Compare
You can preview a29a3ed at https://pr22654-a29a3ed.ngbuilds.io/. |
Runtime i18n, is this now supported i rc5, is there an example on how this works with properties files etc not only the testcase? |
You can set |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Type
What kind of change does this PR introduce?
What is the new behavior?
Runtime i18n
Does this PR introduce a breaking change?