transloco-keys-manager icon indicating copy to clipboard operation
transloco-keys-manager copied to clipboard

Find/Extract do not detect keys in .html files - in angular NX MonoRepo with Shared Root Transloco Config

Open seadonk opened this issue 4 years ago • 6 comments

Current behavior

In our NX monorepo, we use a root transloco.config file for all apps/libraries, with the translations sitting at <project>/src/assets/i18n. Transloco-keys-manager FIND and EXTRACT methods do not detect any keys in the template (.html) files and will show them as extra keys.

Expected behavior

All keys in .html files for both libs and apps should be detected by the FIND and EXTRACT commands.

Steps To Reproduce

Here is an example based off your transloco-with-nx-libs repo. https://github.com/seadonk/transloco-with-nx-libs

Screenshots

Behavior in an APP: If you run transloco-keys-manager find --project transloco-holder, it will correctly identify the existing keys and also missing key and extra key.

$ transloco-keys-manager find --project transloco-holder

 � �  Staring Search For Missing Keys � �

√ Extracting Template and Component Keys �
√ Checking for missing keys ✨
√ Summary

┌───────────┬───────────────┬────────────┐
│ File Name │ Missing Keys  │ Extra Keys │
├───────────┼───────────────┼────────────┤
│ en        │ 'missing key' │ 'extraKey' │
├───────────┼───────────────┼────────────┤
│ es        │ 'missing key' │ --         │
└───────────┴───────────────┴────────────┘

Behavior in an LIB: If you run yarn find --project transloco-lib-a, it will identify extra key, but not missing key, and it will incorrectly think that gps is an extra key because it does not see it in the template.

$ transloco-keys-manager find --project transloco-lib-a

 � �  Staring Search For Missing Keys � �

√ Extracting Template and Component Keys �
√ Checking for missing keys ✨
√ Summary

┌───────────┬──────────────┬────────────┐
│ File Name │ Missing Keys │ Extra Keys │
├───────────┼──────────────┼────────────┤
│ en        │ --           │ 'gps'      │
│           │              │ 'extraKey' │
├───────────┼──────────────┼────────────┤
│ es        │ --           │ 'gps'      │
└───────────┴──────────────┴────────────┘

Keys manager config

const availableLangs =['en', 'de', 'es', 'fr', 'it', 'hi', 'ja', 'zh', 'ar'];
module.exports = {
  langs: availableLangs,
  keysManager: {
    sort: true,
    output: 'assets/i18n', // used only for extract, relative path to the translations files from root
    translationFilesPath: 'assets/i18n', // relative path to the translations files from root
    defaultValue: 'Missing Translation: {{key}}',
    unflat: true
  }
};

Environment

- Keys manager version: 2.7.1
- Node version: 14.15.4
- Platform:  Windows

Debug logs

Additional context

Add any other context about the problem here.

Contribution

I would like to make a pull request for this feature: [ ] Yes! 🚀 [ ] Maybe next time

seadonk avatar Feb 08 '21 21:02 seadonk

@seadonk Can you please share a small reproduction? would you like to make a PR for it? 🙂

shaharkazaz avatar Oct 07 '21 06:10 shaharkazaz

@shaharkazaz I was actually just looking into this. It seems to be failing in some of our libraries. In some cases it seems to be a scoping issue, in others not. The https://github.com/seadonk/transloco-with-nx-libs repo should be the reproduction of the issue. If I can narrow it down I'll attempt a PR.

seadonk avatar Oct 07 '21 19:10 seadonk

The find command is not picking up the template keys from the libraries, and thus shows "gps" as an Extra Key and does NOT show "missing key" as a Missing Key.

Here are the two commands: image

image

I bet it is related to how I am using the TRANSLOCO_SCOPE

seadonk avatar Oct 07 '21 21:10 seadonk

I'm facing the same issue, did you find a solution @seadonk ?

jbchr avatar Jan 10 '22 16:01 jbchr

@jbchr No, sorry. I haven't had time to look into it. If I get a chance I'll make a new minimal reproduction.

seadonk avatar Jan 10 '22 21:01 seadonk

@jbchr You are welcome to give it a shoot as well 🙂

shaharkazaz avatar Jan 22 '22 08:01 shaharkazaz