Skip to content

feat(i18n): initial $localize functionality - #31609

Closed
petebacondarwin wants to merge 8 commits into
angular:masterfrom
petebacondarwin:i18n-localize-init
Closed

petebacondarwin wants to merge 8 commits into
angular:masterfrom
petebacondarwin:i18n-localize-init

Conversation

@petebacondarwin

@petebacondarwin petebacondarwin commented Jul 17, 2019 •

Copy link
Copy Markdown
Contributor

Blocked on #31943

TODOs

For this PR:

  • fix AOT tests to provide a runtime implementation of $localize
  • fix material legacy tests to update with @angular/localize etc (perhaps via a migration?)
  • fix integration tests to update with @angular/localize etc (perhaps via a migration?)

For next PR?

  • write the update migration schematic
  • write the new project schematic
  • write compile-time inliner (Babel plugin/standalone tool)

@petebacondarwin
petebacondarwin force-pushed the i18n-localize-init branch 2 times, most recently from fa4213d to 84eff89 Compare July 17, 2019 16:07
Comment thread tsconfig.json Outdated
Comment thread packages/i18n/localize/src/hash.ts Outdated
Comment thread packages/i18n/localize/src/hash.ts Outdated
@mhevery mhevery added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Jul 17, 2019
@googlebot

Copy link
Copy Markdown

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only "I consent." in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@matsko matsko added the area: i18n Issues related to localization and internationalization label Jul 17, 2019
@ngbot ngbot Bot added this to the needsTriage milestone Jul 17, 2019
@googlebot

Copy link
Copy Markdown

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot removed the cla: no label Jul 18, 2019
@googlebot

Copy link
Copy Markdown

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only "I consent." in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@googlebot

Copy link
Copy Markdown

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@petebacondarwin
petebacondarwin marked this pull request as ready for review July 18, 2019 20:25
@petebacondarwin
petebacondarwin requested a review from a team July 18, 2019 20:25
@petebacondarwin
petebacondarwin force-pushed the i18n-localize-init branch 2 times, most recently from 0b49661 to 416d8b6 Compare July 18, 2019 21:06
@petebacondarwin petebacondarwin added action: review The PR is still awaiting reviews from at least one requested reviewer and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews state: WIP labels Jul 18, 2019
Comment thread packages/core/src/render3/i18n.md Outdated
Comment thread packages/core/src/render3/i18n.ts Outdated
Comment thread packages/core/src/render3/i18n.ts Outdated
Comment thread packages/core/src/render3/i18n.ts Outdated
Comment thread packages/core/src/render3/i18n.ts Outdated
@petebacondarwin petebacondarwin added state: blocked and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Aug 8, 2019
@petebacondarwin
petebacondarwin force-pushed the i18n-localize-init branch 3 times, most recently from 16465bc to 79fe4fc Compare August 9, 2019 12:09

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should be able to not introduce these side effects, depending on the way the check is made.

@petebacondarwin
petebacondarwin force-pushed the i18n-localize-init branch 4 times, most recently from 89c9b11 to eba97c4 Compare August 10, 2019 06:39

@IgorMinar IgorMinar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

haven't reviewed everything, but this is what I've got so far.

Comment thread integration/_payload-limits.json Outdated
Comment thread modules/benchmarks/src/expanding_rows/index.ts Outdated
Comment thread integration/cli-hello-world-ivy-compat/package.json Outdated
Comment thread integration/cli-hello-world-ivy-compat/src/app/app.component.html Outdated
Comment thread integration/language_service_plugin/project/app/main.ts Outdated
Comment thread packages/compiler/package.json Outdated
Comment thread packages/core/package.json Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

right. this shouldn't be a peer dep because you'd be forcing everyone to install it or get a warning. I think we need to settle for a unspecified dependency - this is why we want the runtime and compile time warning about missing @angular/localize.

Comment thread packages/core/testing/src/testing.ts Outdated

@trotyl trotyl Aug 13, 2019 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This isn't a polyfill even when made global function, polyfills.ts is not the place to import arbitrary global libraries.

Zone.js can be considered a polyfill only because it has a stage-0 proposal.

Should user add jquery here if they want to access $ everywhere?

@petebacondarwin petebacondarwin Aug 16, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree it is not a polyfill.
The only requirement is that @angular/localize is imported before any use of the $localize tag.
So it would be perfectly reasonable to add this just before any import of @angular/core - but only if you will only use $localize in Angular templates or Angular application code. Therefore this could be added in main.ts instead.

But... @mhevery argued that since $localize is expected to be a general purpose i18n utility, it could be used in code before Angular is loaded, in which case putting it in polyfills.ts is safer, since $localzie is then guaranteed to be there before any of the application code runs.

One example of this is when using runtime inlining of the messages and loading the translations in a script that is executed in the browser before the main.ts.

A more semantically accurate approach would be to change the build pipeline to load a new file between polyfills.ts and main.ts, (e.g. localize.ts) which is responsible for importing @angular/localize and setting up translations. But we felt that this would be too large a change to accommodate for v9.

Comment thread integration/cli-hello-world-ivy-compat/src/polyfills.ts Outdated
Comment thread packages/localize/runtime/src/translate.ts Outdated
Comment thread packages/localize/runtime/src/translate.ts Outdated
@ocombe ocombe mentioned this pull request Aug 30, 2019
14 tasks
@ngbot

ngbot Bot commented Aug 30, 2019

Copy link
Copy Markdown

I see that you just added the PR action: merge label, but the following checks are still failing:
    failure conflicts with base branch "master"
    failure status "ci/circleci: legacy-unit-tests-saucelabs" is failing
    pending missing required status "ci/circleci: publish_snapshot"
    pending 2 pending code reviews

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken master, please try rebasing to master and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

The files in the pattern do not exist.
This commit changes the Angular compiler (ivy-only) to generate `$localize`
tagged strings for component templates that use `i18n` attributes.

BREAKING CHANGE

Since `$localize` is a global function, it must be included in any applications
that use i18n. This is achieved by importing the `@angular/localize` package
into an appropriate bundle, where it will be executed before the renderer
needs to call `$localize`. For CLI based projects, this is best done in
the `polyfills.ts` file.

```ts
import '@angular/localize';
```

For non-CLI applications this could be added as a script to the index.html
file or another suitable script file.
This has been replaced by the `$localize` tag.
This has been replaced by the `loadTranslations()` function in
`@angular/localize/run_time`.
This test uses localization in the `AppComponent` component:

* an `i18n` attribute in the template
* a call to the `$localize` tag in the component constructor
@mhevery

mhevery commented Aug 30, 2019

Copy link
Copy Markdown
Contributor

GLOBAL APPROVAL: misko

@mhevery

mhevery commented Sep 3, 2019 •

Copy link
Copy Markdown
Contributor

This needs to be reverted as it breaks g3.

/checkbox_logo.closure.js:47: ERROR - [JSC_UNDEFINED_VARIABLE] variable $localize is undeclared
    I18N_6 = $localize `User portrait`;
             ^^^^^^^^^

@angular-automatic-lock-bot

Copy link
Copy Markdown

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.

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 Issues related to localization and internationalization 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.

10 participants