The Wayback Machine - https://web.archive.org/web/20201023163049/https://github.com/angular/angular-cli/issues/18885
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

Exclude directories from "ng xi18n" #18885

Open
schwitin opened this issue Feb 7, 2020 · 11 comments
Open

Exclude directories from "ng xi18n" #18885

schwitin opened this issue Feb 7, 2020 · 11 comments

Comments

@schwitin
Copy link

@schwitin schwitin commented Feb 7, 2020

🚀 Feature request

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Description

The tool parses imported third party modules in node_modules folder too and there is no way to exclude directories from parsing. For example:

create an new app
ng new repro-app

install a third party module
npm @ng-bootstrap/ng-bootstrap

import this module in the app.module.ts

import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
...
imports: [
    ...
      NgbModule
  ]
...

run xi18n
ng xi18n --output-path src/locale --i18n-locale=de

look in the generated messages.xlf

<trans-unit id="ngb.alert.close" datatype="html">
	<source>Close</source>
	<context-group purpose="location">
		<context context-type="sourcefile">node_modules/@ng-bootstrap/ng-bootstrap/alert/alert.d.ts</context>
		<context context-type="linenumber">3</context>
	</context-group>
</trans-unit>

As you cas see the file contains translation units from a third party module although we don,t use it in our templates.

Describe the solution you'd like

A command line parameter --exclude=path/one,path/two will solve my problem. Alternatively (or at once) the parameter --include=path/one, path/two will be helpful.

Describe alternatives you've considered

I could postprocess the messages.xlf with a custom tool to remove unwanted translation units.

@filipesilva
Copy link
Member

@filipesilva filipesilva commented Feb 7, 2020

I think this falls within the purview of the extractor itself, so I'll move it to the angular/angular repo where that package is.

@filipesilva filipesilva transferred this issue from angular/angular-cli Feb 7, 2020
@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Feb 7, 2020

That sounds right. Also we are working on a new i18n extractor that understands $localize calls so we should consider this request in our design of that...

@aslubsky
Copy link

@aslubsky aslubsky commented Aug 17, 2020

Hi, @petebacondarwin is there any ETA for this feature?

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Aug 17, 2020

The new standalone extractor binary can already handle this, since you can point it at the compiled JS files that you care about. Using this binary, the proposed approach is to simply compile the application code using ngc, which outputs a single JS file for each TS file. You can then run the extractor over those files using a glob pattern to choose the JS files that you care about. Note that this approach would not extract messages from 3rd party libraries.

We should include this discussion here in the RFC for Ivy Library Distribution: angular/angular#38366.

@aslubsky
Copy link

@aslubsky aslubsky commented Aug 17, 2020

@petebacondarwin Sorry, did you mean xi18n as "new standalone extractor binary" or something else? For xi18n I can't find any way to set glob pattern. It only use Angular CLI project name as input parameter.

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Aug 17, 2020

@aslubsky - sorry not to be clearer. There is a new message extractor in @angular/localize. It is currently being integrated into the CLI (and will replace the current ng xi18n implementation). But in the meantime you can access this new extractor via a standalone binary called localize-extract. See angular/angular#32912 (comment) for an example of how you might use it.

@aslubsky
Copy link

@aslubsky aslubsky commented Aug 17, 2020

got it, thanks

@sankumar
Copy link

@sankumar sankumar commented Aug 27, 2020

Hi Team, How to exclude node_modules while extract strings in i18n

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Aug 27, 2020

Have you tried using the latest pre-release versions of Angular and the CLI (i.e. 10.1.0-rc.0)? I am not sure if the new implementation of ng xi18n ignores node_modules or not. To use the new extractor you need to provide the --ivy flag for now.

@vengababu5
Copy link

@vengababu5 vengababu5 commented Aug 27, 2020

@petebacondarwin I am using angular 6 version , how can exclude node_modules extract strings in i18n?

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Aug 27, 2020

@vengababu5 - I don't think you can in v6.

@alan-agius4 alan-agius4 transferred this issue from angular/angular Sep 25, 2020
@ngbot ngbot bot added this to the Backlog milestone Sep 25, 2020
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Sep 25, 2020
With this option users will be able to exclude modules from localize extraction.

The `exclude` option accept an array of strings and/or RegExp.

Closes angular#18885
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Sep 25, 2020
With this option users will be able to exclude modules from localize extraction.

The `exclude` option accept an array of strings and/or RegExp.

Closes angular#18885
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Sep 25, 2020
With this option users will be able to exclude modules from localize extraction.

The `exclude` option accept an array of strings and/or RegExp.

Closes angular#18885
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Sep 25, 2020
With this option users will be able to exclude modules from localize extraction.

The `exclude` option accept an array RegExp.

Closes angular#18885
@alan-agius4 alan-agius4 linked a pull request that will close this issue Sep 25, 2020
@alan-agius4 alan-agius4 removed a link to a pull request Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants
You can’t perform that action at this time.