Skip to content
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

Closed

Conversation

ocombe
Copy link
Contributor

@ocombe ocombe commented Mar 8, 2018

PR Type

What kind of change does this PR introduce?

[x] Feature

What is the new behavior?

Runtime i18n

Does this PR introduce a breaking change?

[x] No

@ocombe ocombe added state: WIP area: i18n target: major This PR is targeted for the next major release comp: ivy labels Mar 8, 2018
@ocombe ocombe requested review from vicb and chuckjaz March 8, 2018 15:54
import {Identifiers as R3} from './r3_identifiers';
import {_I18N_ATTR, _I18N_ATTR_PREFIX} from "../i18n/extractor_merger";
Copy link
Contributor

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';
Copy link
Contributor

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')];
Copy link
Contributor

@vicb vicb Mar 8, 2018

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>
Copy link
Contributor

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]};
Copy link
Contributor

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)

@vicb
Copy link
Contributor

vicb commented Mar 8, 2018

I have added some inline comments.

As a general rule please add commits with finer granularity:

  • refactor(ivy): removed unused exports,
  • fix(ivy): ...,

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.

@ocombe ocombe force-pushed the feat/ivy/generate-i18n-template-code branch 4 times, most recently from 2361137 to d3fdd3b Compare March 9, 2018 16:23
@angular angular deleted a comment from mary-poppins Mar 9, 2018
@angular angular deleted a comment from mary-poppins Mar 9, 2018
@angular angular deleted a comment from mary-poppins Mar 9, 2018
@angular angular deleted a comment from mary-poppins Mar 9, 2018
@angular angular deleted a comment from mary-poppins Mar 9, 2018
@angular angular deleted a comment from mary-poppins Mar 9, 2018
@angular angular deleted a comment from ngbot bot Mar 9, 2018
@mary-poppins
Copy link

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[]}[] = [{}];
Copy link
Contributor

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

Copy link
Contributor Author

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)

Copy link
Contributor

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 **/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Start i18n" ?

Copy link
Contributor Author

@ocombe ocombe Mar 13, 2018

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();
}
Copy link
Contributor

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;
Copy link
Contributor

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();
Copy link
Contributor

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 ?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@angular angular deleted a comment from mary-poppins Mar 22, 2018
@angular angular deleted a comment from mary-poppins Mar 22, 2018
@angular angular deleted a comment from mary-poppins Mar 22, 2018
@angular angular deleted a comment from mary-poppins Mar 22, 2018
@angular angular deleted a comment from mary-poppins Mar 22, 2018
@angular angular deleted a comment from mary-poppins Mar 22, 2018
@angular angular deleted a comment from mary-poppins Mar 22, 2018
@angular angular deleted a comment from mary-poppins Mar 22, 2018
@angular angular deleted a comment from mary-poppins Mar 22, 2018
@ocombe ocombe removed the action: merge The PR is ready for merge by the caretaker label Mar 22, 2018
@ocombe
Copy link
Contributor Author

ocombe commented Mar 22, 2018

removing the merge label until we can make the CircleCI build pass

@vicb vicb force-pushed the feat/ivy/generate-i18n-template-code branch from 3d92a9f to a29a3ed Compare March 22, 2018 19:28
@mary-poppins
Copy link

You can preview a29a3ed at https://pr22654-a29a3ed.ngbuilds.io/.

@vicb vicb added the action: merge The PR is ready for merge by the caretaker label Mar 22, 2018
@matsko matsko closed this in 204ba9d Mar 22, 2018
matsko pushed a commit that referenced this pull request Mar 22, 2018
@ocombe ocombe deleted the feat/ivy/generate-i18n-template-code branch March 23, 2018 13:09
leo6104 pushed a commit to leo6104/angular that referenced this pull request Mar 25, 2018
leo6104 pushed a commit to leo6104/angular that referenced this pull request Mar 25, 2018
@vicb vicb mentioned this pull request Mar 26, 2018
3 tasks
@ronnykristiansen
Copy link

Runtime i18n, is this now supported i rc5, is there an example on how this works with properties files etc not only the testcase?

@ocombe
Copy link
Contributor Author

ocombe commented Apr 24, 2018

You can set enableIvy to true in the angularCompilerOptions of your tsconfig.json to make it work, but for now it's only static string translations (for text and attributes).
Otherwise it works exactly the same as before, with the i18n attribute on the elements that you want to translate.
The extraction doesn't work with enableIvy (the PR hasn't been merged yet), but you can set it to false, extract, and set it to true again, the old translations files should work for ivy (the only difference in generated translation files right now is the info about the location in the template, but it's only optional stuff for translation tools).

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: i18n cla: yes target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants