Skip to content

Bug when generating translation file using ng xi18n #8885

Closed

Description

@nathpaiement

The issue

I'm currently working on making our UI translatable using the ng xi18n --outputPath [path] command. At first it worked, generating a messages.xlf file inside the given [path] until it suddenly stopped doing so. And worst of all: ng xi18n didn't complain why it couldn't generate a messages.xlf file, even though the project built properly.

https://www.youtube.com/watch?v=2MYmo52WX5U
Going through the issue on video.

Project structure

root
├─dist
├─node_modules
├─src
        ├─api 
        └─frontend (Angular stuff)
                ├─locale (where to put the .xlf files)
                ├─main.ts
                └─tsconfig.app.json
├─.angular-cli.json
├─package.json
└─tsconfig.json

Note: There's of course more to the structure that has been omitted.

Versions

Output from ng -v:

Angular CLI: 1.5.0
Node: 8.9.0
OS: linux x64
Angular: 5.0.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.5.0
@angular-devkit/build-optimizer: 0.0.32
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.35
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.0
typescript: 2.4.2
webpack: 3.8.1

Finding the cause of the problem

So after spending hours on end trying to find out why ng xi18n once worked and suddenly didn't, I stumbled on a recent change that was made to our root/tsconfig.json file:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
+ "allowJs": true, <-----------------   looks like a pretty innocent change
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

Now I'll have to ask my teammate the reason for the change, but that was apparently the cause why ng xi18n silently failed. When setting that same property to false in our root/src/frontend/tsconfig.app.json, and running ng build... ng xi18n started working again.

Conlusion

Now whether it is an intentional limitation of ng xi18n or not, to not extract the translation strings from the project when "allowJs" is set to true... Angular CLI should in any case return an error message of what failed.



Posted on Utopian.io - Rewarding Open Source Contributors

Activity

  1. added 3 commits that reference this issue on Dec 19, 2017
    06820b8
    0df9419
    feb7d5c
  2. added
    needs: investigation
    on Dec 19, 2017
  3. hansl commented on Dec 19, 2017

    @hansl
    Contributor

    @ocombe Could you take a look?

  4. ocombe commented on Dec 20, 2017

    @ocombe
    Contributor

    I will look into it, in the mean time @nathpaiement please update your cli version, ng xi18n will throw errors starting from 1.5.4 and 1.6.0-rc.0

  5. ocombe commented on Dec 20, 2017

    @ocombe
    Contributor

    I can reproduce the error, and the bug is not with ng xi18n but with the aot compilation, see the related cli issue: #8061 and the angular issue: angular/angular#19757
    I'm closing this one as it seems to be a duplicate.

  6. removed
    needs: investigation
    on Dec 20, 2017
  7. neoncube2 commented on Dec 26, 2017

    @neoncube2

    Hey guys! Just letting people know that I've posted a workaround here:
    angular/angular#19757 (comment)

  8. added 3 commits that reference this issue on Jan 31, 2018
    a5f350a
    51cc09f
    8771d86
  9. added 3 commits that reference this issue on Feb 1, 2018
    a61f5a6
    f560391
    fb38375
  10. added a commit that references this issue on Apr 23, 2018
    e6de79e
  11. angular-automatic-lock-bot commented on Sep 7, 2019

    @angular-automatic-lock-bot

    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.

  12. locked and limited conversation to collaborators on Sep 7, 2019
  13. added a commit that references this issue on May 29, 2026
    8094488
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions