Skip to content

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

Merged
merged 8 commits into from
Feb 8, 2017

Conversation

cladera
Copy link
Contributor

@cladera cladera commented Dec 1, 2016

Implement i18n messages extractor. Contrary to @angular/complier-cli's command it will not throw an error if a resource is not found.

get: (s: string) => {
if (!host.fileExists(s)) {
// Return empty string to avoid extractor stop processing
return Promise.resolve('');
Copy link
Contributor Author

@cladera cladera Dec 1, 2016

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?

Copy link
Contributor

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.

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

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?

Copy link
Contributor

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.

Copy link
Contributor

@hansl hansl left a 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']);
Copy link
Contributor

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.

@cladera cladera force-pushed the extract-i18n-command branch from 2996b2b to 279d32a Compare December 2, 2016 09:38
@cladera
Copy link
Contributor Author

cladera commented Dec 2, 2016

Replaced acceptance tests by e2e tests. Let me know if they satisfy your requirements.

@hansl
Copy link
Contributor

hansl commented Dec 6, 2016

Could you rebase on the latest master? I think those e2e tests are failing because of an old error.

@cladera cladera force-pushed the extract-i18n-command branch from 279d32a to 1347999 Compare December 6, 2016 18:57
@cladera
Copy link
Contributor Author

cladera commented Dec 6, 2016

Done!

case 'xliff':
case 'xlf':
default:
const htmlParser = new compiler.I18NHtmlParser(new compiler.HtmlParser());
Copy link
Contributor

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.

@cladera cladera force-pushed the extract-i18n-command branch from 1347999 to 0e75cf6 Compare December 7, 2016 11:06
@cladera
Copy link
Contributor Author

cladera commented Dec 7, 2016

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.

@hansl
Copy link
Contributor

hansl commented Dec 7, 2016

@vicb Did we change the interface of the Extractor?

@vicb
Copy link

vicb commented Dec 8, 2016

The Serializer interface has changed in 2.3

@cladera
Copy link
Contributor Author

cladera commented Dec 13, 2016

@vicb How new Serializer's interface affects to resource loading?

@Hawkzfan
Copy link

Hawkzfan commented Jan 2, 2017

Hi @cladera
Hi @vicb

what is the current state of this pull request? How would you have to rewrite this task...
Thank you so much!

@hansl
Copy link
Contributor

hansl commented Jan 6, 2017

@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.

@cladera cladera force-pushed the extract-i18n-command branch 5 times, most recently from 9b8d75f to 70f1372 Compare January 27, 2017 09:13
export default function() {
const testComponentDir = join('src/app', 'i18n-test');
return ng('generate', 'component', 'i18n-test')
.then(() => deleteFile(join(testComponentDir, 'i18n-test.component.html')))
Copy link
Contributor

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

Choose a reason for hiding this comment

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

See above.

export default function() {
const testComponentDir = join('src/app', 'i18n-test');
return ng('generate', 'component', 'i18n-test')
.then(() => deleteFile(join(testComponentDir, 'i18n-test.component.html')))
Copy link
Contributor

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

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.

Copy link
Contributor Author

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.

@cladera cladera force-pushed the extract-i18n-command branch from 70f1372 to 5a0fbd6 Compare January 31, 2017 08:44
Implement i18n messages extractor. Contrary to @angular/complier-cli's command it will not throw an error if a resource is not found.
@cladera cladera force-pushed the extract-i18n-command branch from 5a0fbd6 to 18adc30 Compare February 7, 2017 09:18
@hansl
Copy link
Contributor

hansl commented Feb 8, 2017

Thank you so much, @cladera. This is great!

@hansl hansl merged commit 8602536 into angular:master Feb 8, 2017
MRHarrison pushed a commit to MRHarrison/angular-cli that referenced this pull request Feb 9, 2017
Implement i18n messages extractor. Contrary to @angular/complier-cli's command it will not throw an error if a resource is not found.
@JohannesHoppe
Copy link
Contributor

ng i18n is avalailable in @angular/cli: 1.0.0-beta.31
but i don't see any entry for this in the changelog?

anyway, thanks! very convenient! 👍

asnowwolf pushed a commit to asnowwolf/angular-cli that referenced this pull request Apr 12, 2017
Implement i18n messages extractor. Contrary to @angular/complier-cli's command it will not throw an error if a resource is not found.
@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 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants