Bug when generating translation file using ng xi18nsteemCreated with Sketch.

in #utopian-io7 years ago (edited)

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.


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

Sort:  

Your contribution may not be approve yet.

Try and provide every possible detail to reproduce the bug.
Possibly using little video or gif.
You can contact us on Discord.
[utopian-moderator]

I'm pretty sure I provided everything to reproduce the bug, but I can try and make a video. Do I just reply here once again when it's ready?

Will be the best. Thanks alot

@drigweeu I've updated the post with the video.

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @callmetoxy I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.18
TRX 0.15
JST 0.029
BTC 62720.27
ETH 2447.07
USDT 1.00
SBD 2.64