ng extract-i18n does not work properly with ESbuild
blazekv opened this issue · comments
Steps to reproduce:
- Create new project with Angular CLI 17 -
ng new ngx-env-test
- Add localization -
ng add @angular/localize
- Add ngx-env builder -
ng add @ngx-env/builder
- Create localization in AppComponent
title = $localize`Hello world`
- Use ESbuild in Angular.json -
"builder": "@ngx-env/builder:application"
- Run extraction
ng extract-i18n --output-path src/locale
angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"cli": {
"packageManager": "pnpm"
},
"newProjectRoot": "projects",
"projects": {
"ngx-env-test": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@ngx-env/builder:application",
"options": {
"outputPath": "dist/ngx-env-test",
"index": "src/index.html",
"browser": "src/main.ts",
"polyfills": [
"zone.js"
],
"tsConfig": "tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@ngx-env/builder:dev-server",
"configurations": {
"production": {
"buildTarget": "ngx-env-test:build:production"
},
"development": {
"buildTarget": "ngx-env-test:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@ngx-env/builder:extract-i18n",
"options": {
"buildTarget": "ngx-env-test:build:production"
}
},
"test": {
"builder": "@ngx-env/builder:karma",
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"tsConfig": "tsconfig.spec.json",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
}
}
}
}
}
}
It looks like something is wrong because according to output is seems that ESbuild is not run at all. Output is here
But if I switch to webpack build by setting "builder": "@ngx-env/builder:browser"
message are extracted.
And also without ngx-env builder with ESbuild by setting "builder": "@angular-devkit/build-angular:application"
everything works OK.
Thanks for reporting the issue.
Could you please give @ngx-env/builder@17.2.0 a try?
@chihab I tried it and output is still same. I tried it on different project (not blank one). I could try it also on that sample project I created for reproduction tomorrow.
Output with @ngx-env/builder:application
Extraction Complete. (Messages: 0)
If i switched to @ngx-env/builder:browser output is
Extraction Complete. (Messages: 1172)
Fixed in @ngx-env/builder@17.2.1, my bad.
Thank you for that fast response. @chihab I am not sure if it is already fixed. I tried it in my real project and I got this message:
Extraction Complete. (Messages: 413)
but as I wrote before without @ngx-env/builder or with @ngx-env/builder:browser I got:
Extraction Complete. (Messages: 1172)
I am not sure if I find time to investigate difference today. I will probably look at it at monday and let you know.
Something has been fixed at least since you now get 413 messages :)
Re-opening the issue, I'll see if I can reproduce your use case, your investigation would help.
Based on that numbers I had a hunch. It seems that for some reason extraction from templates did not work properly. I tried that on that simple project and here are numbers and examples.
3 translation strings
- Localization in component
- Localization HTML element content
- Localization of HTML attribute
Component:
export class AppComponent {
title = $localize`ngx-env-test`;
}
Template
<div i18n i18n-title title="Attribute string">
element string
</div>
1st case with standard builder settings:
projects.architect.build.builder = @angular-devkit/build-angular:application
projects.architect.extract-i18n.builder = @angular-devkit/build-angular:extract-i18n
I had 3 extracted messages with this output:
Extraction Complete. (Messages: 3)
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en-US" datatype="plaintext" original="ng2.template">
<body>
<trans-unit id="156685006078229661" datatype="html">
<source>Attribute string</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.html</context>
<context context-type="linenumber">2,3</context>
</context-group>
</trans-unit>
<trans-unit id="5176180191114202338" datatype="html">
<source> element string
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.html</context>
<context context-type="linenumber">3,5</context>
</context-group>
</trans-unit>
<trans-unit id="7459501857900893879" datatype="html">
<source>ngx-env-test</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">13</context>
</context-group>
</trans-unit>
</body>
</file>
</xliff>
2nd case with non-standard builder settings:
(I know this is probably wrong setting but just to test all cases)
projects.architect.build.builder = @ngx-env/builder:application
projects.architect.extract-i18n.builder = @angular-devkit/build-angular:extract-i18n
Extraction Complete. (Messages: 0)
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en-US" datatype="plaintext" original="ng2.template">
<body>
</body>
</file>
</xliff>
3rd case with @ngx-env/builder for extract-i18n:
And finally these two settings has same output:
projects.architect.build.builder = @ngx-env/builder:application
projects.architect.extract-i18n.builder = @ngx-env/builder:extract-i18n
projects.architect.build.builder = @angular-devkit/build-angular:application
projects.architect.extract-i18n.builder =@ngx-env/builder:extract-i18n
Extraction Complete. (Messages: 1)
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en-US" datatype="plaintext" original="ng2.template">
<body>
<trans-unit id="7459501857900893879" datatype="html">
<source>ngx-env-test</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">13</context>
</context-group>
</trans-unit>
</body>
</file>
</xliff>
Fixed in latest update.
Could you please give it a try?
It works correctly in the latest version. Thank you.