-
Notifications
You must be signed in to change notification settings - Fork 12k
feature(i18n): implement xi18n command #3340
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
Conversation
get: (s: string) => { | ||
if (!host.fileExists(s)) { | ||
// Return empty string to avoid extractor stop processing | ||
return Promise.resolve(''); |
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.
This should solve the problem with SASS partials.
However, it will affect other cases so I wonder if is it the best solution.
I'd like to start a discussion here: Should the extractor stop if a resource is not found? Does not make more sense to keep processing files and perhaps showing a warning instead of throwing an error?
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.
Would it be useful to compile less/sass files? Also, please note that in the future we will support other format, even for templates (pug comes to mind).
Are you available on gitter right now? If so, contact me and we can review this interactively for fast tracking.
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 don't see the point of compiling less/sass files since they will never contain i18n messages, actually I rather ignore them. Templates, though, make a lot more sense.
return tmp.setup('./tmp').then(function() { | ||
process.chdir('./tmp'); | ||
}).then(function() { | ||
return ng(['new', 'foo', '--link-cli']); |
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.
ng new
should be executed with --skip-npm
and --skip-bower
flags. But if we do so, the extractor won't work. I guess it is because the extractor seems to compile the project. If the dependencies are not installed the command throws an exception because eventually a module will not be found.
If the beforeEach
has to install the dependencies it takes too much time. That's why I skipped the test because I though installing all vendors is unacceptable.
Any idea how to make this work?
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.
Bower should never install now, since we removed that code and those dependencies from Angular CLI.
I think this test would be better suited as an e2e test since you change files and do a lot of FS work. If you need help adding an e2e test, reach me out on gitter and/or by email. I'll help you.
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'm going to need some time to read this since I'm lacking a lot of information regarding i18n. At first look this looks good (outside of maybe minor nits).
Give me a few days for a full review please.
return tmp.setup('./tmp').then(function() { | ||
process.chdir('./tmp'); | ||
}).then(function() { | ||
return ng(['new', 'foo', '--link-cli']); |
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.
Bower should never install now, since we removed that code and those dependencies from Angular CLI.
I think this test would be better suited as an e2e test since you change files and do a lot of FS work. If you need help adding an e2e test, reach me out on gitter and/or by email. I'll help you.
2996b2b
to
279d32a
Compare
Replaced acceptance tests by e2e tests. Let me know if they satisfy your requirements. |
Could you rebase on the latest master? I think those e2e tests are failing because of an old error. |
279d32a
to
1347999
Compare
Done! |
case 'xliff': | ||
case 'xlf': | ||
default: | ||
const htmlParser = new compiler.I18NHtmlParser(new compiler.HtmlParser()); |
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.
If the format is not one we understand, we should just error out. That way the user will know there's a typo.
1347999
to
0e75cf6
Compare
Pushed a new version that throws an error if format argument is none of allowed. However, since 2.3.0-rc.0 compiler's Extractor no longer accepts a resourceLoader function as a parameter which changes completely this implementation. I'll have to take a look to new i18n extracting API. |
@vicb Did we change the interface of the Extractor? |
The Serializer interface has changed in 2.3 |
@vicb How new Serializer's interface affects to resource loading? |
@cladera Many changes came in 2.4.0. This PR basically needs to be redone, but it's not that big of a deal. We added a private API in Angular that can be used to extract stuff, without worrying about changes to the Extractor class. We probably wants to run through a full webpack build while doing the extraction so that we have a compilation and can build sass/less/pug files. Do you know how to do that? I can help you finish this PR. |
9b8d75f
to
70f1372
Compare
export default function() { | ||
const testComponentDir = join('src/app', 'i18n-test'); | ||
return ng('generate', 'component', 'i18n-test') | ||
.then(() => deleteFile(join(testComponentDir, 'i18n-test.component.html'))) |
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.
You don't need to delete it, since you're overwriting it. Also, you don't need to keep a variable for the path.
export default function() { | ||
const testComponentDir = join('src/app', 'i18n-test'); | ||
return ng('generate', 'component', 'i18n-test') | ||
.then(() => deleteFile(join(testComponentDir, 'i18n-test.component.html'))) |
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.
See above.
tests/e2e/tests/i18n/extract-xmb.ts
Outdated
export default function() { | ||
const testComponentDir = join('src/app', 'i18n-test'); | ||
return ng('generate', 'component', 'i18n-test') | ||
.then(() => deleteFile(join(testComponentDir, 'i18n-test.component.html'))) |
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.
See above.
private _make(compilation: any, cb: (err?: any, request?: any) => void) { | ||
this._compilation = compilation; | ||
if (this._compilation._ngToolsWebpackXi18nPluginInstance) { | ||
return cb(new Error('An @ngtools/webpack xi18n plugin already exist for ' + |
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.
You should also validate that we don't have a _ngToolsWebpackPluginInstance
, since that would seem to be an error.
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.
Changes pushed. Travis build failed though. I don't understand why it failed, can you take a look and let me know if I broke something.
70f1372
to
5a0fbd6
Compare
Implement i18n messages extractor. Contrary to @angular/complier-cli's command it will not throw an error if a resource is not found.
5a0fbd6
to
18adc30
Compare
Thank you so much, @cladera. This is great! |
Implement i18n messages extractor. Contrary to @angular/complier-cli's command it will not throw an error if a resource is not found.
anyway, thanks! very convenient! 👍 |
Implement i18n messages extractor. Contrary to @angular/complier-cli's command it will not throw an error if a resource is not found.
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. |
Implement i18n messages extractor. Contrary to @angular/complier-cli's command it will not throw an error if a resource is not found.