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

test(ivy): make sure goog.getMsg() is defined before being used #22998

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -27,7 +27,7 @@
"name": "HelloWorld"
},
{
"name": "INeedToExistEvenThoughtIAmNotNeeded"
"name": "INeedToExistEvenThoughIAmNotNeeded"
},
{
"name": "Immediate"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/bundling/hello_world/index.ts
Expand Up @@ -14,7 +14,7 @@ export class HelloWorld {
// TODO(misko): Forgetting to export HelloWorld and not having NgModule fails silently.

@NgModule({declarations: [HelloWorld]})
export class INeedToExistEvenThoughtIAmNotNeeded {
export class INeedToExistEvenThoughIAmNotNeeded {
}
// TODO(misko): Package should not be required to make this work.

Expand Down
12 changes: 7 additions & 5 deletions packages/core/test/bundling/hello_world_i18n/BUILD.bazel
Expand Up @@ -14,7 +14,12 @@ ivy_ng_module(

ng_rollup_bundle(
name = "bundle",
# Remove once #22913 lands
# TODO(alexeagle): This is inconsistent.
# We try to teach users to always have their workspace at the start of a
# path, to disambiguate from other workspaces.
# Here, the rule implementation is looking in an execroot where the layout
# has an "external" directory for external dependencies.
# This should probably start with "angular/" and let the rule deal with it.
entry_point = "packages/core/test/bundling/hello_world_i18n/index.js",
deps = [
":hello_world_i18n",
Expand All @@ -29,8 +34,5 @@ ts_devserver(
":bundle.min.js",
"index.html",
],
deps = [
# fix for ibazel until https://github.com/angular/angular/pull/22912 gets merged
"//packages/compiler",
],
deps = [],
)
22 changes: 15 additions & 7 deletions packages/core/test/bundling/hello_world_i18n/index.html
Expand Up @@ -8,11 +8,11 @@
<!-- The Angular application will be bootstrapped into this element. -->
<hello-world></hello-world>

<!--
<!--
Script tag which bootstraps the application. Use `?debug` in URL to select
the debug version of the script.
There are two scripts sources: `bundle.min.js` and `bundle.min_debug.js` You can

There are two scripts sources: `bundle.min.js` and `bundle.min_debug.js` You can
switch between which bundle the browser loads to experiment with the application.

- `bundle.min.js`: Is what the site would serve to their users. It has gone
Expand All @@ -23,9 +23,17 @@
property renaming.
-->
<script>
document.write('<script src="' +
(document.location.search.endsWith('debug') ? '/bundle.min_debug.js' : '/bundle.min.js') +
'"></' + 'script>');
// `goog.getMsg()` will be provided by Closure
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused by the idea that Angular will depend on Closure library. That's not the case, right? If so, update this comment

Copy link
Contributor

Choose a reason for hiding this comment

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

no, it's only for g3, we haven't coded the service for the community yet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As Olivier said Angular will depend on Closure compiler for g3. The OSS edition will have an optional dep.

Runtime i18n (and ivy... and other things) are a WIP and will be updated as we make progress.

const translations = {
'Hello World!': 'Bonjour Monde!',
'Hello Title!': 'Bonjour Titre!',
};
window.goog = window.goog || {};
window.goog.getMsg = (key) => translations[key] || key;
Copy link
Contributor

Choose a reason for hiding this comment

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

extract all of this to another script tag instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it's your code !
I think it's good enough for now.


document.write('<script src="' +
(document.location.search.endsWith('debug') ? '/bundle.min_debug.js' : '/bundle.min.js') +
'"></' + 'script>');
</script>
</body>
</html>
</html>
11 changes: 1 addition & 10 deletions packages/core/test/bundling/hello_world_i18n/index.ts
Expand Up @@ -8,15 +8,6 @@

import {Component, NgModule, ɵrenderComponent as renderComponent} from '@angular/core';

// simulate translations for now
const translations: {[key: string]: string} = {
'Hello World!': 'Bonjour Monde!',
'Hello Title!': 'Bonjour Titre!',
};

// simulate Google Closure getMsg for now
(window as any).goog = {getMsg: (key: string) => { return translations[key] || key; }};

@Component({
selector: 'hello-world',
template: `<div i18n i18n-title title="Hello Title!">Hello World!</div>`
Expand All @@ -26,7 +17,7 @@ export class HelloWorld {
// TODO(misko): Forgetting to export HelloWorld and not having NgModule fails silently.

@NgModule({declarations: [HelloWorld]})
export class INeedToExistEvenThoughtIAmNotNeeded {
export class INeedToExistEvenThoughIAmNotNeeded {
}
// TODO(misko): Package should not be required to make this work.

Expand Down