angular / angular/angular-cli

i18n support in Angular libraries

Đang mở
#17,140 40 bình luận 35 reaction 0 người được giao Xem trên GitHub
devkit/build-angular:i18n devkit/build-angular:library feature feature: under consideration
Ngôn ngữ chính
TypeScript
Star
27k
Fork
11.8k
Merge trung bình
14 giờ 23 phút
Pull request đã merge (30 ngày)
162

Mô tả

# 🐞 Bug report

### Command (mark with an `x`)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [x] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

### Is this a regression?

No. Related functionaliy only available with new i18n capabilities of angular 9.

### Description

I want to use ng xi18n command to extract messages for i18n tags which are part of a library project which is part of a monrepo setup created by the cli. According to docs at
https://angular.io/cli/xi18n this is supposed to be possible

> ng xi18n \
> \ The name of the project to build. Can be an application or a library.

## 🔬 Minimal Reproduction

1. create project: `ng new lib-i18n`
1. add localize: `ng add @angular/localize`
1. generate library: `ng g library my-lib`
1. add i18n attribute in my-lib.component.ts
```


my-lib works!


```
1. run `ng xi18n my-lib`: Result will be
`An unhandled exception occurred: Project 'my-lib' does not support the 'extract-i18n' target.`
After adding corresponding extract-i18n target in angular.json, error output as below.

I created a minimal demo project which incorporates the scenario describe above. It is located here:
https://github.com/multimike77/lib-i18n-issue

Checkout and run `npm install`. Then run `ng xi18n my-lib` and it should produce error as below.

## 🔥 Exception or Error



An unhandled exception occurred: The "path" argument must be of type string. Received undefined

[error] TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
at validateString (internal/validators.js:117:11)
at Object.resolve (path.js:980:7)
at Object.getCommonConfig (/Users/.../lib-i18n/node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/common.js:390:24)
at /Users/.../lib-i18n/node_modules/@angular-devkit/build-angular/src/extract-i18n/index.js:91:27
at generateWebpackConfig (/Users/.../lib-i18n/node_modules/@angular-devkit/build-angular/src/utils/webpack-browser-config.js:62:22)
at async Object.generateBrowserWebpackConfigFromContext (/Users/.../lib-i18n/node_modules/@angular-devkit/build-angular/src/utils/webpack-browser-config.js:137:20)
at async execute (/Users/.../lib-i18n/node_modules/@angular-devkit/build-angular/src/extract-i18n/index.js:73:24)

## 🌍 Your Environment



Angular CLI: 9.0.4
Node: 12.16.1
OS: darwin x64

Angular: 9.0.4
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: Yes

Package Version
------------------------------------------------------------
@angular-devkit/architect 0.900.4
@angular-devkit/build-angular 0.900.4
@angular-devkit/build-ng-packagr 0.900.4
@angular-devkit/build-optimizer 0.900.4
@angular-devkit/build-webpack 0.900.4
@angular-devkit/core 9.0.4
@angular-devkit/schematics 9.0.4
@ngtools/webpack 9.0.4
@schematics/angular 9.0.4
@schematics/update 0.900.4
ng-packagr 9.0.2
rxjs 6.5.4
typescript 3.7.5
webpack 4.41.2

**Anything else relevant?**

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Tái hiện vấn đề trong dự án lib-i18n-issue được liên kết bằng npm install và ng xi18n my-lib. Bắt đầu bằng cách đọc @angular-devkit/build-angular/src/extract-i18n/index.js và đường dẫn common.js được tham chiếu trong stack trace. Hoàn thành khi xi18n chấp nhận một dự án thư viện và trích xuất các thông báo i18n của dự án đó mà không gặp lỗi target hoặc path.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
angular, node.js, typescript
Lĩnh vực
build-system, cli, internationalization
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
52/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.