Giter VIP home page Giter VIP logo

transloco-keys-manager's Introduction

Important

The Transloco packages are now published under the @jsverse scope, update your dependencies to get the latest features πŸš€

πŸ¦„ The Key to a Better Translation Experience

Build Status NPM Version

Translation is a tiresome and repetitive task. Each time we add new text, we need to create a new entry in the translation file, find the correct placement for it, etc. Moreover, when we delete existing keys, we need to remember to remove them from each translation file.

To make the process less burdensome, we've created two tools for the Transloco library, which will do the monotonous work for you.

🍻Features

  • βœ… Β Extract Translate Keys
  • βœ… Β Scopes Support
  • βœ… Β Webpack Plugin
  • βœ… Β Find Missing and Extra Keys

πŸ“– Table of Contents

🌩 Installation

Schematics

Assuming you've already added Transloco to your project, run the following schematics command:

ng g @jsverse/transloco:keys-manager

At this point, you'll have to choose whether you want to use the CLI, Webpack Plugin, or both. The project will be updated according to your choice.

Note: if you're going to use the Webpack plugin, and you've already defined other Webpack plugins in your project, you should manually add the Keys Manager plugin to the list, rather than using the schematics command.

Manual

Install the Transloco keys manager package via yarn or npm by running:

npm i -D @jsverse/transloco-keys-manager
yarn add -D @jsverse/transloco-keys-manager

Add the following scripts to your package.json file:

{
  "i18n:extract": "transloco-keys-manager extract",
  "i18n:find": "transloco-keys-manager find"
}

The following functionality is available once the installation is complete:

πŸ”‘ Keys Extractor

This tool extracts translatable keys from templates and typescript files. Transloco Keys Manager provides two ways of using it:

CLI Usage

If you chose the CLI option, you should see the following script in your project's package.json file:

{
  "i18n:extract": "transloco-keys-manager extract"
}

Run npm run i18n:extract, and it'll extract translatable keys from your project.

Webpack Plugin

The TranslocoExtractKeysWebpackPlugin provides you with the ability to extract the keys during development, while you're working on the project.

The angular-cli doesn't support adding a custom Webpack config out of the box.

In case you already have support for a custom Webpack config just add the TranslocoExtractKeysWebpackPlugin in your plugin list.

In case you need to add the support, you can use the keys manager schematics command, and it will do the work for you. (choose the Webpack Plugin option)

You should see a new file named webpack-dev.config.js configured with TranslocoExtractKeysWebpackPlugin:

// webpack-dev.config.js
import { TranslocoExtractKeysWebpackPlugin } from '@jsverse/transloco-keys-manager';

export default {
  plugins: [
    new TranslocoExtractKeysWebpackPlugin(config?),
  ]
};

Also, you should see an updated definition of the npm start command:

{
  "start": "ng serve --extra-webpack-config webpack-dev.config.js"
}

Now run npm start and it'll generate new keys whenever a save is made to the project.

Scopes Support

The extractor supports scopes out of the box. When you define a new scope in the providers array:

import { TRANSLOCO_SCOPE, provideTranslocoScope } from '@jsverse/transloco';

@Component({
  templateUrl: './admin-page.component.html',
  providers: [
      { provide: TRANSLOCO_SCOPE, useValue: 'admin' },
      provideTranslocoScope('todo'),
      provideTranslocoScope(['another', {scope: 'reallyLong', alias: 'rl'}]),
  ]
})
export class AdminPageComponent {}
<ng-container *transloco="let t">{{ t('admin.title') }}</ng-container>

It'll extract the scope (admin in our case) keys into the relevant folder:

πŸ“¦ assets
 β”— πŸ“‚ i18n
 ┃ ┣ πŸ“‚ admin
 ┃ ┃ ┣ πŸ“œ en.json
 ┃ ┃ β”— πŸ“œ es.json
 ┃ ┣ πŸ“œ en.json
 ┃ β”— πŸ“œ es.json

Inline Loaders

Let's say that we're using the following inline loader:

export const loader = ['en', 'es'].reduce((acc, lang) => {
  acc[lang] = () => import(`../i18n/${lang}.json`);
  return acc;
}, {});

@NgModule({
  imports: [TranslocoModule],
  providers: [
    {
      provide: TRANSLOCO_SCOPE,
      useValue: {
        scope: 'scopeName',
        loader
      }
    }
  ],
  declarations: [YourComponent],
  exports: [YourComponent]
})
export class FeatureModule {}

We can add it to the scopePathMap key in the transloco.config.js file:

module.exports = {
  langs: ['en', 'es'],
  scopePathMap: {
    scopeName: 'src/app/feature/i18n'
  }
};

Now, it'll create the files in the provided folder.

Dynamic Keys

There are times when we need to extract keys with values that may change during runtime. One example can be when you need to use a dynamic expression:

import { TranslocoService } from '@jsverse`/transloco';

class MyComponent {
  someMethod() {
    const value = translocoService.translate(`key.${type}.postfix`);
  }
}

To support such cases, you can add a special comment to your code, which tells the CLI to extract it. It can be added to Typescript files:

import { TranslocoService } from '@jsverse/transloco';

class MyComponent {
  /**
   * t(key.typeOne.postfix, key.typeTwo.postfix)
   * t(this.will.be.extracted)
   */
  someMethod() {
    const value = translocoService.translate(`key.${type}.postfix`);
  }
}

Or to templates:

<!-- t(I.am.going.to.extract.it, this.is.cool) -->
<ng-container *transloco="let t">...</ng-container>

When using comments in the templates they will also inherit the prefix input value (if exists), and will be prefixed with it:

<!-- t(this.is.cool) -->
<ng-container *transloco="let m; prefix: 'messages'">
  ...
  <!-- t(success, error) -->
  <ng-container *transloco="let g; prefix: 'general'">
    ...
    <!-- t(ok, cancel) -->
  </ng-container>
</ng-container>

The extracted keys for the code above will be:

{
  "this.is.cool": "",
  "messages.success": "",
  "messages.error": "",
  "general.ok": "",
  "general.cancel": ""
}

Notes:

  1. When using a Typescript file, you must have @jsverse/transloco present somewhere in the file, if it's an import or simply adding a comment // @jsverse/transloco.
  2. When using comments in your HTML files, they must contain only the markers without additional text. Here's an example for invalid comment: <!-- For dropdown t(dynamic.1, dynamic.2) -->

Marker function

If you want to extract some standalone strings that are not part of any translation call (via the template or service) you can wrap them with the marker function to tell the keys manager to extract them:

import { marker } from '@jsverse/transloco-keys-manager';

class MyClass {
  static titles = {
    username: marker('auth.username'), // ==> 'auth.username'
    password: marker('auth.password') // ==> 'auth.password'
  };
...
}

The marker function will return the string which was passed to it. You can alias the marker function if needed:

import { marker as _ } from '@jsverse/transloco-keys-manager';

class MyClass {
  static titles = {
    username: _('auth.username'),
    password: _('auth.password')
  };
...
}

Extra Support

  • Supports for the prefix input:
<ng-container *transloco="let t; prefix: 'dashboard'">
  <h1>{{ t('title') }}</h1>

  <p>{{ t('desc') }}</p>
</ng-container>

The extracted keys for the code above will be:

{
  "dashboard.title": "",
  "dashboard.desc": ""
}
  • Supports static ternary operators:
<!-- Supported by the transloco pipe and structural directive -->
<comp [placeholder]="condition ? 'keyOne' : 'keyTwo' | transloco"></comp>
<h1>{{ condition ? 'keyOne' : 'keyTwo' | transloco }}</h1>

<comp *transloco="let t; prefix: 'ternary'">
  <h1>{{ t(condition ? 'keyOne' : 'keyTwo') }}</h1>
</comp>

πŸ•΅ Keys Detective

This tool detects two things: First, it detects any key that exists in one of your translation files but is missing in any of the others. Secondly, it detects any key that exists in the translation files but is missing from any of the templates or typescript files. After installing the library, you should see the following script in your project's package.json file:

{
  "i18n:find": "transloco-keys-manager find"
}

Run npm run i18n:find, and you'll get a lovely list that summarizes the keys found.

πŸ•Ή Options

  • project*: The targeted project (default is defaultProject). The sourceRoot of this project will be extracted from the angular.json file and will prefix the input, output, and translationPath properties. In addition, the transloco config file will be searched in the project's sourceRoot (unless the config option is passed):
transloco-keys-manager extract --project first-app

Note: If no angular.json file is present, sourceRoot will be src.

  • config: The root search directory for the transloco config file: (default is process.cwd())
transloco-keys-manager extract --config src/my/path
transloco-keys-manager extract -c src/my/path
  • input: The source directory for all files using the translation keys: (default is ['app'])
transloco-keys-manager extract --input src/my/path
transloco-keys-manager extract --input src/my/path,project/another/path
transloco-keys-manager extract -i src/my/path

Note: If a project is provided the default input value will be determined by the projectType, when given a library the default input value will be ['lib'].

  • output: The target directory for all generated translation files: (default is assets/i18n)
transloco-keys-manager extract --output my/path
transloco-keys-manager extract -o my/path
  • fileFormat: The translation file format 'json' | 'pot': (default is json)
transloco-keys-manager extract --file-format pot
transloco-keys-manager extract -f pot
  • langs: The languages files to generate: (default is [en])
transloco-keys-manager extract --langs en es it
transloco-keys-manager extract -l en es it
  • marker: The marker sign for dynamic values: (default is t)
transloco-keys-manager extract --marker _
transloco-keys-manager extract -m  _
  • sort: Whether to sort the keys using JS sort() method: (default is false)
transloco-keys-manager extract --sort
  • unflat: Whether to unflat instead of flat: (default is flat)
transloco-keys-manager extract --unflat
transloco-keys-manager extract -u

If you are using unflat files keep in mind that β€œparent” keys won't be usable for a separate translation value, i.e. if you have two keys first and first.second you cannot assign a value to first as the translation file will look like { "first": { "second": "…" } }.

During key extraction you will get a warning with a list of concerned keys you have to check for.

  • defaultValue: The default value of a generated key: (default is Missing value for {{key}})
transloco-keys-manager extract --default-value missingValue
transloco-keys-manager extract -d "{{key}} translation is missing"

There are several placeholders that are replaced during extraction:

  1. {{key}} - complete key including the scope.
  2. {{keyWithoutScope}} - key value without the scope.
  3. {{scope}} - the key's scope.
  • replace: Replace the contents of a translation file (if it exists) with the generated one (default value is false, in which case files are merged)
transloco-keys-manager extract --replace
transloco-keys-manager extract -r
  • removeExtraKeys: Remove extra keys from existing translation files (defaults to false)
transloco-keys-manager extract --remove-extra-keys
transloco-keys-manager extract -R
  • addMissingKeys: Add missing keys that were found by the detective (default is false)
transloco-keys-manager find --add-missing-keys
transloco-keys-manager find -a
  • emitErrorOnExtraKeys: Emit an error and exit the process if extra keys were found (default is false)
    Extra keys are keys that exist in your translations but are no usages of them in the code.
transloco-keys-manager find --emit-error-on-extra-keys
transloco-keys-manager find -e
  • translationsPath: The path for the root directory of the translation files (default is assets/i18n)
transloco-keys-manager find --translations-path my/path
transloco-keys-manager find -p my/path
  • help:
transloco-keys-manager --help
transloco-keys-manager -h

Transloco Config File

One more option to define the config object for this library is to create a transloco.config.js file in the project's root folder and add the configuration in it:

// transloco.config.js
module.exports = {
  rootTranslationsPath?: string;
  langs?: string[];
  keysManager: {
    input?: string | string[];
    output?: string;
    fileFormat?: 'json' | 'pot';
    marker?: string;
    addMissingKeys?: boolean;
    emitErrorOnExtraKeys?: boolean;
    replace?: boolean;
    defaultValue?: string | undefined;
    unflat?: boolean;
  };
}

🐞 Debugging

You can extend the keys manager default logs by setting the DEBUG environment variable:

{
  "i18n:extract": "DEBUG=* transloco-keys-manager extract",
  "i18n:find": "DEBUG=* transloco-keys-manager find"
}

Supported namespaces: *|config|paths|scopes|extraction, setting * will print all the debugger logs.

You can also chain several namespaces:

{
  "i18n:extract": "DEBUG=config,paths transloco-keys-manager extract"
}

Contributors ✨

Thank goes to all these wonderful people who contributed ❀️

transloco-keys-manager's People

Contributors

abdealiloko avatar bkleiner avatar darkv avatar endykaufman avatar evanfuture avatar itayod avatar jellebruisten avatar jerrydoubleu avatar jonathanwilke avatar justinpierce avatar kekel87 avatar lukechi1219 avatar maleet avatar migiside avatar mikedabrowski avatar netanelbasal avatar orestisioakeimidis avatar rhuitl avatar seadonk avatar serrulien avatar shaharkazaz avatar vkrol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

transloco-keys-manager's Issues

Question about defaultValue configuration option

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[x] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Tried to change defaultValue configuration option to generate text for non-existing keys, but could't get missing key inside message

Expected behavior

Some way to reference key value

Minimal reproduction of the problem with instructions

Changed transloco.config.js file to:

module.exports = {
	rootTranslationsPath: 'src/assets/i18n/',
	langs: ['en', 'lv'],
	keysManager: {
		input: 'src/app',
		translationsPath: 'src/assets/i18n',
		sort: true,
		addMissingKeys: true,
		defaultValue: 'No trans {key}', // tried {{key}}, `No trans ${key}`
		replace: true
	}
};

Generated missing key text doesn't contain property names with key, only text like:

{
  "search.title": "No trans {key}"
}

Environment


Angular version: 8.2.12


For Tooling issues:
- Node version: v12.13.1  
- Platform:  Windows 7 Ultimate 

Wrong JSON format with Webpack plugin

Hi guys

We are using Transloco with the Webpack Plugin (thanks for that!) for extracting keys during development in combination with dynamic keys.

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

As you can see we have a different output format of the json file. This only happens during development with the Webpack plugin, a manual run with transloco-keys-manager extract works as expected for both languages.

Output
de.json (As expected)
"security": { "error": { "1": "xxxx", "2": "xxxx", "3": "xxx" ...... } }

en.json (Wrong)
"security": { "error": [ null, "Missing value for 'security.error.1'", "Missing value for 'security.error.2'" ] }

Expected behavior

Same format for both language - like de.json

Minimal reproduction of the problem with instructions

Setup
Dynamic keys definition inside *.ts
/** * t(security.error.wrong-credentials, security.error.no-connection, security.error.old-app-version, * security.error.1, security.error.2, security.error.3, security.error.4, security.error.5, security.error.6, * security.error.7, security.error.8, security.error.9, security.error.10, security.error.11, security.error.12, * security.error.13, security.error.14, security.error.15, security.error.16, security.error.17, security.error.18, * security.error.19, security.error.20, security.error.21, security.error.22, security.error.23, security.error.24, * security.error.25, security.error.26, security.error.27, security.error.28, security.error.29, security.error.30, * security.error.31, security.error.32, security.error.33, security.error.34, security.error.35, security.error.36, * security.error.37, security.error.38, security.error.39, security.error.40, security.error.41, security.error.42, * security.error.43) */

transloco.config.js:
module.exports = { rootTranslationsPath: 'assets/i18n/', langs: ['de', 'en'], keysManager: { emitErrorOnExtraKeys: true, unflat: true, }, };

extra-webpack.config.ts contains
config.plugins.push(new TranslocoExtractKeysWebpackPlugin({}));

What is the motivation / use case for changing the behavior?

Using Transloco during development with automated key extraction.

Environment


Angular version: 9.1.11
 
For Tooling issues:
- Node version: 12.5.0
- Platform:  Windows

Keys manager does not extract all keys from ts files

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

A few translation keys from one particular ts service are not being extracted. This file has other keys as well which are being extracted successfully.

Not extracting:

    let progressbarId = this.progressbarsService.createProgressbar(this.translocoService.translate("record.ImportingData"), 0);


      progressbarId = this.progressbarsService.createProgressbar(this.translocoService.translate("LoadingData"), 0); 

This part below is interesting because the key record.ImportStarted is being extracted and record.ImportStartedDontNavigateMessage is not

    if (!(options && options.skipSuccessToast)) {
      this.toastsService.showToast({
        severity: "warn",
        summary: this.translocoService.translate("record.ImportStarted"),
        detail: this.translocoService.translate("record.ImportStartedDontNavigateMessage"),
      });
    }

I do not have much experience with node cli but I did try to debug the keys-manager and I think the problem is with this regexs.translationCalls based on its matches within this file

Environment


ngular version: 7.3.9

 
For Tooling issues:
- Node version: 13.0.1  
- Platform: Linux  

Others:

Alias in cliOptions must be single character

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

In version 1.3.0 the project CLI option is added in cliOptions.js. It has a alias pr ( 2 characters ) but the command-line-args package gives a error there: INVALID_DEFINITIONS: Invalid option definition: an alias must be a single character.

Expected behavior

The alias needs to have a single character alias, now the transloco-keys-manager command will trow a error and will nowt work

Minimal reproduction of the problem with instructions

ng g @ngneat/transloco:keys-manager (version 1.3.0)

run any transloco-keys-manager command

you will get a error INVALID_DEFINITIONS: Invalid option definition: an alias must be a single character.

Support Inline Loaders

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

When the project use Inline Loaders (a scope with loader), then I get error by find and extract commands.

Expected behavior

Finder should find keys in lazy loaded modules and extractor should extract keys in the correct folder.

Environment


Angular CLI: 8.3.14
Node: 12.3.1
OS: win32 x64
Angular: 8.2.12

 
- Platform:   Windows 


Extract command breaks translation files

I'm submitting a...

[X] Bug report

Current behavior

When runing transloco-keys-manager extract with this template markup, it outputs message in console and breaks existing translation JSON files. Same problem as here #32. [inlineSVG] is directive from library https://github.com/arkon/ng-inline-svg

Bad

<span class="my-span-class another-class also-span-class"
  [inlineSVG]="'some/path/to/image.svg'"
  data-e2e="DataAttributeValue"
  matTooltipClass="my-tooltip-class"
  matTooltip="{{ 'MY_MODULE.MY_SUBMODULE.MY_COMPONENT.MY_TRANSLATION_KEY' | transloco }}">
</span>

Good (no message in console, extract successful)

<span class="my-span-class another-class also-span-class"
  matTooltip="{{ 'MY_MODULE.MY_SUBMODULE.MY_COMPONENT.MY_TRANSLATION_KEY' | transloco }}"
  [inlineSVG]="'some/path/to/image.svg'"
  data-e2e="DataAttributeValue"
  matTooltipClass="my-tooltip-class">
</span>

Expected behavior

Extract translation keys without breaking the existing translation files.

Minimal reproduction of the problem with instructions

For example add to any template:

<span class="my-span-class another-class also-span-class"
  [inlineSVG]="'some/path/to/image.svg'"
  data-e2e="DataAttributeValue"
  matTooltipClass="my-tooltip-class"
  matTooltip="{{ 'MY_MODULE.MY_SUBMODULE.MY_COMPONENT.MY_TRANSLATION_KEY' | transloco }}">
</span>

Then run from console transloco-keys-manager extract and see message in console and changes on your existing translation JSON files (defined in transloco.config.js).

What is the motivation / use case for changing the behavior?

To work transloco-keys-manager extract as intended and without breaking the existing translation files.

Environment

Angular: 9.1.11
Angular CLI: 9.1.8
Transloco: 2.17.2
Transloco keys manager: 2.1.0
ng-inline-svg: 10.1.0
 
For Tooling issues:
- Node: 14.4.0
- Platform: Windows 10

Key manager with webpack plugin question

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[x] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

I'm trying to use key manager to manage keys within my project with the webpack plugin. I have an english translation file (en.json) as my 'master' translation file and several other sample ones that aren't in sync with the master copy(the master copy would be periodically translated into various languages and merged back into my repo).

I want the plugin to manage the english translation file ONLY and not the other ones. Reason for this is that I have transloco configured to fallback to english if a specific translation key doesn't exist. When key manager manages other files it puts in the default value for the key which I don't want because I'll lose the english fallback. I have this configured in my transloco.config.js file and it works the first time I run ng serve. However, if I make changes to the project while the ng serve command is still running it then ignores this configuration and changes all the existing translation files.

Is there a way to make my use case work?

Here is my transloco.config.js file config:

module.exports = {
  rootTranslationsPath: 'src/assets/i18n/',
  langs: ['en'],
  keysManager: {
    defaultValue: 'Key Missing'
  },
  unflat: true,
  marker: 'dynamic-'
};

And here is my webpack-dev.config.js:

const { TranslocoExtractKeysWebpackPlugin } = require('@ngneat/transloco-keys-manager');
const translocoConfig  = require('./transloco.config.js')
module.exports = {
  plugins: [new TranslocoExtractKeysWebpackPlugin(translocoConfig)]
};

Expected behavior

That the key manager webpack plugin would respect the configuration in transloco.config.js even during code changes.

Environment

@angular-devkit/architect 0.803.19
@angular-devkit/build-angular 0.803.19
@angular-devkit/build-optimizer 0.803.19
@angular-devkit/build-webpack 0.803.19
@angular-devkit/core 8.3.19
@angular-devkit/schematics 8.3.19
@angular/cdk 8.2.3
@angular/cli 8.3.19
@angular/material 8.2.3
@ngtools/webpack 8.3.19
@schematics/angular 8.3.19
@schematics/update 0.803.19
rxjs 6.5.3
typescript 3.5.3
webpack 4.39.2

For Tooling issues:

  • Node version: 12.13.0
  • Platform: Mac

po file support

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Is there an option to extract the keys into po files instead of a json file?

Use keys-manager tools with a built angular project folder passed as input option

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[X] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

My team and I develop angular libraries (let's take one as an example and call it ngLib) that use Transloco very well (congrats for your job btw πŸ‘ ).
We published this library in our private npm repository.
Then we install ngLib in a classic angular project (call it ngClassic) via npm. So ngLib is a dependency of ngClassic (a node module).
We define JSON translation files inside ngClassic and ngLib consumes correctly translation files and display well translations thanks to a Transloco Root Module well configured in ngLib.

But the thing is that we can't use transloco-keys-manager tools in ngClassic project.
Actually, it's not possible to check keys defined in ngClassic and used in its ngLib dependency (node module).
This is due to the fact that ngLib dependency is build and so translations (template or typescript) are included in generated js files (for typescript translations) and apparently the ***.metadata.json file (for template translation).

IMPORTANT THING
In reality, in my team project, we will have multiple ngClassic projects. Each will use (or not) ngLib libraries we develop in different ways. It means that each ngClassic project has same translation files structure (= same keys) but not same translations.

SO : We can't have a single angular project with all libraries inside.

Expected behavior

It could be awesome if transloco-keys-manager tools could detect translation keys of a built angular project (in my case build angular library project).

Minimal reproduction of the problem with instructions

First possibility : Create an angular project with a library, install and configure transloco, add some tranlsations in JSON files and use it on template / typescript files.
Create a classic angular project that will have in dependency the previous angular library created (for that use npm link). Install transloco-keys-manager and configure it to check the node module library files in input of extract / find script.

Second possibity : Create a classic angular project, install and configure transloco, add some tranlsations in JSON files and use it on template / typescript files. Build it with ng build --prod. Install transloco-keys-manager and configure it to check the build result in dist project root folder as the input of extract / find script.

What is the motivation / use case for changing the behavior?

The main goal of the request is to allow keys checking and extraction in an angular project where its translation files are consumed by a an angular library dependency (node module).

Today, if we want to use transloco-keys-manager, we have to use it in the ngLib project :

  • define JSON translations files outside of the projects folder
  • install transloco-keys-manager and configure it
  • and it's working

But if all keys checking is ok, then we have to manually copy JSON translation files from ngLib to ngClassic.

Environment


Angular version: 9.1.4


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: 12.16.1  
- Platform:  Mac

Others:


Anyway, thank you for your excellent work on Transloco and its tools πŸ‘

Keys Detective does not find extra/missing Keys for Translation Files without a scope

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report 
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

The keys Detective does not find any extra or missing Keys in a Translation File without scopes

Expected behavior

All extra/missing Key's without scope's where founded by the keys Detective.

Minimal reproduction of the problem with instructions

You can reproduce this behavior in this repository.
Here I add a new key extra and removed an exsting key title from i18n/en.json.

  • run npm run i18n:find

Environment


Angular version: 8.2.14
 
For Tooling issues:
- Node version: 10.15.3
- Platform:  Mac

Detect keys from typescript files from extended TranslocoService

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

transloco-keys-manager find does not detect keys in typescript file unless used specifically by TranslocoService

Expected behavior

transloco-keys-manager find should detect keys in typescript file if used by either TranslocoService or an extended TranslocoService

Minimal reproduction of the problem with instructions

For bug reports please provide the STEPS TO REPRODUCE and if possible a MINIMAL DEMO of the problem, for that you could use our stackblitz example

What is the motivation / use case for changing the behavior?

The main motivation is to allow extending TranslocoService to each project specific needs.

A simple use case would be:

Want to manually load translations for the current scope and current language. So, I'm abstracting all the logic from TranslocoService for getting langChanges$ observable and calling the load() method into a single method (e.g. loadScopedTranslations(scope: string)).

This way, I just need to call this method in the components I need.

Environment


Angular version: 9.0.4


Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: 10.15.3 
- Platform: Windows 

Others:

Add support for Angular libraries to Keys Detective

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Angular's suggested folder structure is the following:

  • Root
    • node_modules
    • projects
      • lib1
      • lib2
    • src
      • app
      • assets

It's very common to need translation support in files inside the libraries. In our case, we have one unique file per language for all libraries and app inside the assets folder.

There's no problem with the keys extractor, but our problem is with the keys detective, since:

  • Running it with -i src will detect keys existing in projects as extra keys.
  • Running it with -i projects will detect keys existing in src/app as extra keys.
  • Running it with -i . will scan node_modules which is less than ideal and causes errors.

Expected behavior

We think either one of the following functionalities will solve the problem:

  • Add an option to exclude one or several folders, so folders like node_modules aren't scanned.
  • Add the option for adding multiple inputs folder.

Minimal reproduction of the problem with instructions

  • Create a new project using Angular CLI.
  • Add a new library using Angular CLI.
  • Add some translation keys in both the library and the app folder.
  • Try to use the Keys Detective.

What is the motivation / use case for changing the behavior?

Having the need for translation support in both an Angular application and libraries at the same time.

json files getting replaced not merged

I'm submitting a bug


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

First of all, thanks for this pretty cool translation tool.

The extract command replaces all values at the generated language json files. In the documentation is written that replace default is false but it is not working.
If i set replace to false at the transloco.config.js by my self it is also not working and replaces all key values at the json files instead of merging them.

module.exports = { rootTranslationsPath: 'src/assets/i18n/', langs: ['de', 'en', 'es'], keysManager: { replace: false } };

Expected behavior

The extract command should only add new translations key to the json files and do not replace all values.

Minimal reproduction of the problem with instructions

Set up new angular project install transloco and set up some translations, in my case with the structural directive.

What is the motivation / use case for changing the behavior?

Extraction without merging the new keys into the json is pretty annoying

Environment


Angular version: 8.2.11
@ngneat/transloco: 2.5.2
@ngneat/transloco-keys-manager: 1.0.0

For Tooling issues:
- Node version: v12.3.1
- Platform:  macOs 10.15

Others:

Keys detective doesn't show Missing/Extra keys correctly

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

When running keys detector on a project/i18n folder I always get the same result that all the keys for all langs are Extra keys and there's nothing in Missing keys section (even when I deliberately add a key only in one lang file).

Expected behavior

Extra keys should include only keys that are not used in the templates.
Missing keys should include keys that are in other i18n files and not in the current one.

Minimal reproduction of the problem with instructions

Create 2 i18n files with a key that isn't in the other file and use them in the HTML

Environment


Angular version: 8.2.3
Keys Manager: 1.3.2
Node version: 10.13.0
Platform: Mac

Maybe its also important to mention that my folder structure is angular's monorepo style (multiple apps and libs under projects folder).
I've tried:
npm run i18n:find -- --project="projectName"
npm run i18n:find -- -p projects/projectName/src/assets/i18n
and also npm run i18n:find with rootTranslationsPath pointing to a specific project

Sort keys and their comments for translators together

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

When using comments for translators, and then the key extractor (ie. transloco-keys-manager extract), the extractor reorders the json files, and moves the comments away from the key they are explaining.

So the following original json (some parts omitted)

{
    "form.comment": "Form field names/labels, which are in front of the inputs",
    "form": {
        "name": {
            "label": "Name"
        }
    },
    "otherStuff": {
        "other": "stuff"
    }
}

when the extractor adds new keys to sections which are omitted in the example, becomes the following

{
    "form": {
        "name": {
            "label": "Name"
        }
    },
    "otherStuff": {
        "other": "stuff"
    },
    "form.comment": "Form field names/labels, which are in front of the inputs"
}

Notice how form.comment was moved down, which makes it hard to spot if the key has a comment, because there might be a ton of lines between the comment and the actual key.

Requested behavior

Comments should be sorted together with their keys. Maybe the comments should be sorted before the keys, because in case when the comment is for a whole block, that is more readable, se the original example above.

Minimal reproduction of the problem with instructions

  1. Create some keys in templates, then have them extracted into the language files with transloco-keys-manager extract
  2. Add comments to some keys or blocks, see the examples above.
  3. Add some more keys in templates, then extract them with the same method
  4. => comments are sorted away from their keys

Our transloco config

package.json

{
  "scripts": {
    "i18n:extract": "transloco-keys-manager extract --project <project-in-the-angular-workspace>"
  }
}

transloco.config.js

module.exports = {
	rootTranslationsPath: 'projects/<project-in-the-angular-workspace>/src/assets/i18n/',
	langs: ['en', 'de', 'fr', 'it'],
	keysManager: {
		input: 'app',
		output: 'assets/i18n',
		defaultValue: '[-]{{key}}',
		unflat: true,
	},
};

What is the motivation / use case for changing the behavior?

We hand out the whole language files directly to translators, ie. we don't have any further mechanism to extract the not-yet-translated keys. They know how to search for the missing indicators and fill the translations in, but they have to search to check if a certain key has a comment, because they are sorted away.

Environment

I don't think the angular version is relevant, but just to be on the safe side, here are the deps:

    ...
    "@angular/animations": "~8.2.4",
    "@angular/cdk": "~8.2.3",
    "@angular/common": "~8.2.4",
    "@angular/compiler": "~8.2.4",
    "@angular/core": "~8.2.4",
    "@angular/forms": "~8.2.4",
    "@angular/material": "~8.2.3",
    "@angular/platform-browser": "~8.2.4",
    "@angular/platform-browser-dynamic": "~8.2.4",
    "@angular/router": "~8.2.4",
    "@ngneat/transloco": "^2.13.3",
    "@ngneat/transloco-locale": "^1.1.1",
    ...

and the dev deps:

    ...
    "@ngneat/transloco-keys-manager": "^2.2.1",
    "@ngneat/transloco-optimize": "^1.0.1",
    ...

For Tooling issues:

  • Node version: v10.16.3
  • Platform: MacOS 10.15.5 (19F101)

Keys Detective shouldn't mark comments as extra keys

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report 
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

The Keys Detective marks all of our comments for translators (i.e. all entries that are something.comment in our en.json file) as extra keys. It becomes a bit cumbersome to search for real extra keys in the output of the script.

Expected behavior

All comment entries shouldn't be marked as extra keys.

Minimal reproduction of the problem with instructions

Have the following content in an en.json file:

{
  "a": "this is content",
  "a.comment": "a comment about a"
}

Have the following content in a .ts file:

import {} from '@ngneat/transloco'

/**
 * t(a)
 */

What is the motivation / use case for changing the behavior?

With lots of comments, it becomes a bit hard to find all actual extra keys in the list that the Keys Detective provides.

Environment


Angular version: 9.1.12
Keys manager version: 2.2.1

For Tooling issues:
- Node version: 12.0.0 
- Platform:  Linux

Auto remove unused keys

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[x] Support request
[ ] Other... Please describe:

First thank you for awersome libs. =) Small question, is it possible to automatically remove unused keys from translation files during extraction with merge? Is it not implemented or I missed something?

Thank you

Feature: support dynamic scope name

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

The key manager detects TRANSLATION_SCOPE_KEY instead of myTranslationScopeKey while parsing the module definition below.

const TRANSLATION_SCOPE _KEY = 'myTranslationScopeKey';

@NgModule({
  imports: [CommonModule, TranslocoModule],
  providers: [
    {
      provide: TRANSLOCO_SCOPE,
      useValue: {
        scope: TRANSLATION_SCOPE_KEY,
        loader: scopeLoader((language, root) => import(`./${root}/${language}.json`))
      }
    }
  ]
})
export class MyFeatureModule {}

Expected behavior

The key manager detects myTranslationScopeKey while parsing the module definition below.

Minimal reproduction of the problem with instructions

Run transloco-keys-manager extract

What is the motivation / use case for changing the behavior?

In my application the scope key is a constant in a separate file which is imported in different places (the feature module, a transloco testing module...)

Supporting Pug templates

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Keys extracted only from .ts and .html files

Expected behavior

Keys extracted from files specified by the user

What is the motivation / use case for changing the behavior?

In our project we use pug and earlier I can extract keys with help ngx-translate-extract from any files with using --pattern flag (for example --patterns /**/*.{pug,ts,js}).

Have you any plans about this?

Unflat files will loose keys on special conditions

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Having some translation keys like

  • top.middle
  • top.middle.last1
  • top.middle.last2

will create three corresponding entries in the translation files:

{
  "top.middle" : "a";
  "top.middle.last1" : "b";
  "top.middle.last2" : "c";
}

If you chose to use unflat files by setting the config to unflat: true this will be converted either to

{
  "top": {
    "middle": "a"
  }
}

or

{
  "top": {
    "middle": {
      "last1": "b",
      "last2": "c"
    }
  }
}

depending on the order of processing the keys and thus leading to a loss of information. This behavior is mainly related to the used lib flat. So in the current implementation the feature "unflat" can be very dangerous as the user won't notice that loss of keys because there is neither an error/warning output during key extraction nor a warning in the documentation.

Expected behavior

It has to be decided if the current behavior can be fixed by either trying to get a fix on the flat lib or by introducing some sort of preprocessor for unflat files to amend the keys so that flat will behave correctly. That preprocessor would detect such cases and modify a list of extracted keys like

{
  …
  "top.middle" : "a",
  "top.middle.last1" : "b",
  "top.middle.last2" : "c",
  …
}

to

{
  …
  "top.middle._" : "a",
  "top.middle.last1" : "b",
  "top.middle.last2" : "c",
  …
}

Then during reading those files back in the reverse processing has to be applied. This is just some sketchy idea and is meant as start of discussion on that topic.

Detective doesn't detect keys as extra keys if a read input has been added for keys added in template comments

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

I started with the following template:

<!-- t(de, en, zh) -->

After extracting keys, the following keys were added correctly:

  "de": "Missing value for 'de'",
  "en": "Missing value for 'en'",
  "zh": "Missing value for 'zh'",

Now I changed the template to:

<ng-container *transloco="let t; read: 'accountSettings'">
<!-- t(de, en, zh) -->
</ng-container>

Running key extraction resulted in:

  "accountSettings.de": "Missing value for 'accountSettings.de'",
  "accountSettings.en": "Missing value for 'accountSettings.en'",
  "accountSettings.zh": "Missing value for 'accountSettings.zh'",
  "de": "Missing value for 'de'",
  "en": "Missing value for 'en'",
  "zh": "Missing value for 'zh'",

Now comes the error: Running find doesn't yield any extra keys. However de, en and zh should have been detected.

A similar scenario where no comment keys are used but the {{ t('de') }} syntax, the detective correctly recognises the old keys as extra keys.

Expected behavior

de, en and zh should have been detected as extra keys.

Minimal reproduction of the problem with instructions

See steps above.

Environment

  • Node version: 13.7.0
  • Platform: Mac

Inline loader configuration does not generate keys according with scopePathMap path definition

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

I'm trying to make the key manager, according with its docs, to generate lazy modules keys under related xx.json files.

I'm using nx as monorepository manager and this is the structure:

project/
β”œβ”€β”€ apps/
β”‚   └── my-app/
β”‚       β”œβ”€β”€ src/
β”‚       |   |── app/
β”‚       |   |   └── features/
|       |   |       └── feature-one/
|       |   |           |── i18n/
|       |   |           |   └── en.json
|       |   |           |    
|       |   |           └── feature-one.module.ts
|       |   |
|       |   |── home.component.ts
|       |   └── app.module.ts
|       |    
|       └── assets/   
β”‚           └── i18n/
|               └── en.json
|
β”œβ”€β”€ transloco.config.js
└── etc...

This is the content of the transloco.config.file:

module.exports = {
  langs: ['en'],
  scopePathMap: {
    'feature-one': 'apps/my-app/src/app/features/feature-one/i18n'
  }
};

And this the feature-one.module.ts:

export const loader = ['en'].reduce((acc, lang) => {
  acc[lang] = () => import(`./i18n/${lang}.json`);
  return acc;
}, {});

@NgModule({
  imports: [TranslocoModule],
  providers: [
    {
      provide: TRANSLOCO_SCOPE,
      useValue: {
        scope: 'feature-one',
        loader
      }
    }
  ],
  declarations: [YourComponent],
  exports: [YourComponent]
})
export class FeatureOneModule {}

If I try to extract the translation keys all keys will be added to my-app/assets/i18n folder.

By the way, i've found this workaround for feature-one.module.ts definition:

 providers: [
    {
      provide: TRANSLOCO_SCOPE,
      useValue: 'feature-one',              // this will make the translation key manager work
    },
    {
      provide: TRANSLOCO_SCOPE,
      useValue: {
        scope: 'feature-one',
        loader
      }
    }
  ],

In this way the key manager separates the keys correctly in folder my-app/assets/i18n and in my-app/src/app/features/feature-one/i18n.

Also, key separation stops working if i do not use a "static value" for the TRANSLOCO_SCOPE like this ( maybe there's a problem with static evaluation? ):

 providers: [
    {
      provide: TRANSLOCO_SCOPE,
      useValue: FEATURE_ONE_SCOPE, 
    },
  ],

Expected behavior

Correct key separation according with scopePathMap parameter.

Environment


- transloco-keys-manager:  2.06

Support default language value as keys in the i18n bundle

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Maybe this is all by design and the direction of Transloco, but with ngx-translate we made the keys the default en-US value. So our string extraction process would automatically generate the en-US bundle straight out of the code. That reduced extra overhead of actually having to manually maintain the translation json bundle.

With transloco-keys-manager, I'm see the keys getting minified by the removal of spaces and other special characters like the following:
{"Processingarchive...": "Processingarchive..."}

Expected behavior

Is there a way to configure Transloco to work like ngx-translate in this regard?

Minimal reproduction of the problem with instructions

The above line in our bundle was generated from this block of code in one of our template files:

<edge-wizard-step [label]="'Restore Options' | transloco"
                      [validatingMessage]="'Processing archive...'|transloco"
                      [validate]="simulateRestore"
                      [useFormCtrlValidation]="profile">

transloco.config.js

module.exports = {
  rootTranslationsPath: 'src/assets/i18n/',
  langs: ['en'],
  keysManager: {
    defaultValue: "{{key}}"
  }
};

What is the motivation / use case for changing the behavior?

It's just less work on developers if they can use the english translated versions of text as the keys and default values.

Environment


Angular version: 8.2.14

Transloco Version: 2.12.4

Browser:
- [x] Chrome (desktop) version 79.0.3945.130 (MacOS)
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: 13.3.0
- Platform:  Mac

Others:

Problem with key extraction, edit.title is extracted as edititle

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

After running transloco-keys-manager extract there is wrong key generated.

I have added lazy loading module:

@NgModule({
	imports: [
		...
		TranslocoModule,
	],
	declarations: [
		...
	],
	providers: [{ provide: TRANSLOCO_SCOPE, useValue: 'property' }],
})
export class PropertyModule { }

And have component template:

<ng-container *transloco="let t; read: 'property'">
...
			<h3 class="modal-title">{{ t('edit.title') }}</h3>
			<div class="modal-body">
...

After running transloco-keys-manager extract, there is key generated (assets/i18n/property/en.json):

{
  "edititle": "Missing value for 'property.edititle'",
}

Tried workaround:

<ng-container *transloco="let t; read: 'property'">
	...
			<ng-container *transloco="let t; read: 'property.edit'">
				<h3 class="modal-title">{{ t('title') }}</h3>
			</ng-container>
        ...

Which generated correct key, but also generated two keys:

{
  "edit.title": "Missing value for 'property.edit.title'",
  "title": "Missing value for 'property.title'"
}

Expected behavior

Key should be named: "edit.title"

Environment


Angular version: 8.2.12

For Tooling issues:
- Node version: v12.13.1
- Platform:  Windows 7 Ultimate

Others:

Support for nested objects

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

HTML file


{{'todos.title1' | transloco}}  
{{'todos.title2' | transloco}}

then run transloco-keys-manager extract
It generates following json:


{
  "todos.title1": "Missing value for 'todos.title1'",
  "todos.title2": "Missing value for 'todos.title2'",
}

Expected behavior

It should generate nested JSON file, like this one:


{
  "todos" : {
    "title1": "Missing value for 'todos.title1'",
    "title2": "Missing value for 'todos.title2'"
  }
}

Environment



Angular CLI: 8.3.14
Node: 12.3.1
OS: win32 x64
Angular: 8.2.12

Extract command breaks translation files

I'm submitting a...

[X] Bug report

Current behavior

When runing transloco-keys-manager extract with this template markup, it outputs message in console and breaks existing translation JSON files.

Bad

<a [routerLink]="'MY_MODULE' | lowercase"
  [title]="'MY_MODULE.MY_COMPONENT.MY_TRANSLATION_KEY' | transloco">
  {{ 'MY_MODULE.MY_COMPONENT.MY_TRANSLATION_KEY' | transloco }}
</a>

Good (no message in console, extract successful)

<a [title]="'MY_MODULE.MY_COMPONENT.MY_TRANSLATION_KEY' | transloco"
  [routerLink]="'MY_MODULE' | lowercase">
  {{ 'MY_MODULE.MY_COMPONENT.MY_TRANSLATION_KEY' | transloco }}
</a>

So it depends on some order of element attributes or something else. Maybe issue with any other HTML elements or attributes.

Expected behavior

Extract translation keys without breaking the existing translation files.

Minimal reproduction of the problem with instructions

For example add to any template:

<a [routerLink]="'MY_MODULE' | lowercase"
  [title]="'MY_MODULE.MY_COMPONENT.MY_TRANSLATION_KEY' | transloco">
  {{ 'MY_MODULE.MY_COMPONENT.MY_TRANSLATION_KEY' | transloco }}
</a>

Then run from console transloco-keys-manager extract and see message in console and changes on your existing translation JSON files (defined in transloco.config.js).

What is the motivation / use case for changing the behavior?

To work transloco-keys-manager extract as intended and without breaking the existing translation files.

Environment

Angular version: 9.1.3
 
For Tooling issues:
- Node version: v14.0.0
- Platform: Windows 10

transloco-keys-manager don`t extract if "--project" provided with angular library

First of all, thanks to transloco team)

Maybe I`m doing something wrong... But little tired looking for a solution. So I'm writing an issue request.

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

In new angular project with generated library by ng g library library-name

Using command transloco-keys-manager extract --project library-name
Ouput: Input undefined

Expected behavior

Using command transloco-keys-manager extract --project library-name
should extract key into assets folder of parent project or into assets folder of library-name

Minimal reproduction of the problem with instructions

  1. Generate new Angular project with ng new project-name
  2. Generate library in it with ng g library library-name
  3. Add transloco to project-name with ng add @ngneat/transloco
    3.1 Answers for question: ru,en; no
  4. Add transloco-key-manager to project-name with ng g @ngneat/transloco:keys-manager
  5. Add script to project-name package.json "i18n:extract:library-name": "transloco-keys-manager extract --project library-name"
  6. Run with npm run i18n:extract:library-name

What is the motivation / use case for changing the behavior?

Using Transloco in Angular libraries and have the option to autoextract keys from it.

Environment


Angular version: 10.0.5

 
For Tooling issues:
- Node version: v12.18.1  
- Platform: Linux  



duplicated keys extracted for scoped translations

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Specifying comments for scoped dynamic keys results in keys added to both the scope translation file and the global file, with wrong and cluttering keys in global file

Expected behavior

keys are only included in i18n/library/en.json with the scope (library)+key(style.one) structure as library.style.one

Minimal reproduction of the problem with instructions

  1. I have defined a scope in my lazy loaded module routes as follow:
@NgModule({
  imports: [RouterModule.forChild(routes)],
  providers: [{ provide: TRANSLOCO_SCOPE, useValue: 'library' }],
  exports: [RouterModule]
})
export class LibraryRoutingModule { }
  1. I init the directive in templates adding comments for the dynamic keys as follow:
<div class="group-tags" *transloco="let t; read: 'library'">
        <!-- t(style.one, style.two, style.three) -->
</div>
  1. I run the transloco-keys-manager extract script

  2. I get keys included in i18n/library/en.json

[...]
"style": {
    "one": "Missing value for 'library.style.one'",
    "two": "Missing value for 'library.style.two'",
    "three": "Missing value for 'library.style.three'"
  },
[...]

and in i18n/en.json

  "style": {
    "one": "Missing value for 'style.one'",
    "two": "Missing value for 'style.two'",
    "three": "Missing value for 'style.three'"
  }

Environment


Angular version: 10.0.3
Transloco version: 2.17.4
Transloco keys manager version: 2.2.1

Feature: support ternary operator in structural directive

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

I have this in HTML

<app-card *transloco="let t; read: 'CREATE_COMPANY.ADD_LOGO'">
      <!-- t(CROP_IMAGE) -->
      <h1>{{ t(imgRead ? 'CROP_IMAGE' : 'UPLOAD') }}</h1>

And in en.json

"CREATE_COMPANY": {
  "ADD_LOGO": {
    "CROP_IMAGE": "Crop Image",
  }
}

When I run key-manager find I get:
image

Note that for 'de' there are two missing keys, and only the first one is correct - in fact it does not exist in de.json but it is present in en.json.
Same when I do not use ternary there. Key manager duplicates in a way that key. If I add CROP_IMAGE to en.json at top level finder returns all good, but the actual value that is displayed comes from nested CROP_IMAGE not top level one.

Expected behavior

Key manager finder to properly inherit 'read' and not duplicate keys

Minimal reproduction of the problem with instructions

Should be easily repro on any code, sadly I don't have time to prep stackblitz.

What is the motivation / use case for changing the behavior?

Environment


Angular version: 9.1+,
Keymgr: 2.0.7



For Tooling issues:
- Node version: 12.16.3
- Platform:  Win10

Nested keys and commented out keys generation bug

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

For module:

@NgModule({
	imports: [
		...
		TranslocoModule,
	],
	declarations: [
		...
	],
	providers: [{ provide: TRANSLOCO_SCOPE, useValue: 'property' }],
})
export class PropertyModule { }

And some component template in this module:

<ng-container *transloco="let t; read: 'property'">
			<ng-container *transloco="let t;">
				<h3 class="modal-title">{{ t('some.global.title1') }}</h3>
			</ng-container>

			<!-- <ng-container *transloco="let t;">
				<h3 class="modal-title">{{ t('some.global.key1') }}</h3>
			</ng-container> -->

                        <!-- <h3 class="modal-title">{{ t('propname') }}</h3> -->

There are extracted keys:
assets/i18n/en.json:

{
  "some.global.title1": "some.global.title1"
}

assets/i18n/property/en.json:

{
  "propname": "property.propname",
  "some.global.key1": "property.some.global.key1",
  "some.global.title1": "property.some.global.title1"
}

Expected behavior

There should be only one key generated in assets/i18n/en.json file 'some.global.title1' key.

So there is two problems:

  1. nested *transloco extract two keys, when there should be only one
  2. for some reason commented block keys is also generated, but only for outer *transloco directive

Environment


Angular version: 8.2.14
 
For Tooling issues:
- Node version: v12.13.1  
- Platform:  Windows 7

templateExtractor fails when an empty string is passed to transloco pipe

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

When an empty string is passed to transloco pipe, the cli crashes on find command with this error

TypeError: Cannot read property 'replace' of undefined
    at Object.forEachKey
    at forEach.e 
    at Array.forEach
    at templateExtractor
    at Object.extractKeys
    at Object.extractTemplateKeys
    at Object.buildKeys
    at Object.findMissingKeys
    at Object.<anonymous>
    at Module._compile

Also a side issue, the pipe regex in templateExtractor also look for keys in translocoCurrency pipe expressions. (in my project the empty string is passed to translocoCurrency pipe which caused the cli to crash)

Expected behavior

Ignore empty strings passed to transloco pipe
Fix pipe regex to ignore translocoCurrency pipe

Minimal reproduction of the problem with instructions

Pass an empty string to transloco or translocoCurrency pipes

Environment


Angular version: 9.1.0
Keys manager version: 2.0.3

Detect references to missing keys

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

One of the most useful features of Transloco is the ability to reference other keys within the same translation file. But when translation files are changed and some references can point to non-existent keys. This is not detected by the keys manager.

Expected behavior

References to non-existent keys are detected by the keys manager.

Minimal reproduction of the problem with instructions

Have the following en.json:

{ 
  "a": "Point to {{nonExistentKey}}"
}

Run the keys manager.

What is the motivation / use case for changing the behavior?

Changing translation files can result in references to non-existent keys.

Environment


Angular version: 9.1.12
Keys manager version: 2.2.1

For Tooling issues:
- Node version: 12.0.0 
- Platform:  Linux

Keys detective run endlessly when pointing to specific i18n file

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

When using --translations-path flag and pointing to a specific language file, the process runs endlessly in "Checking for missing keys" stage.

Expected behavior

finish the process and show the summary, or don't allow pointing to a specific file and fail the process with some explanation.

Minimal reproduction of the problem with instructions

run the command with --translations-path flag and point it to a specific json file

Environment


Angular version: 8.2.3
Keys Manager: 1.3.2
Node version: 10.13
Platform: Mac

"Cannot read property 'project' of undefined" when running with webpack plugin

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Running ng serve --extra-webpack-config webpack-dev.config.js throws:

[error] TypeError: Cannot read property 'project' of undefined
    at Object.resolveConfig (/Users/fengelmann/developement/labapp/client/node_modules/@ngneat/transloco-keys-manager/helpers/resolveConfig.js:1:597)
    at new TranslocoExtractKeysWebpackPlugin (/Users/fengelmann/developement/labapp/client/node_modules/@ngneat/transloco-keys-manager/webpack-plugin.js:1:722)
    at Object.<anonymous> (/Users/fengelmann/developement/labapp/client/webpack-dev.config.js:4:13)
    at Module._compile (internal/modules/cjs/loader.js:1151:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1040:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.transforms.<computed> [as webpackConfiguration] (/Users/fengelmann/developement/labapp/client/node_modules/ngx-build-plus/src/utils/index.js:56:38)
    at setup (/Users/fengelmann/developement/labapp/client/node_modules/@angular-devkit/build-angular/src/dev-server/index.js:115:46)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

Expected behavior

No error.

Minimal reproduction of the problem with instructions

  • Setup an angular project with transloco
  • Add the keys-manager ng g @ngneat/transloco:keys-manager and accept webpack plugin setup
  • Run the above command

Environment


Angular version: 9.0.7
Transloco versio: 2.19.1
 
For Tooling issues:
- Node version: v13.7.0
- Platform:  Mac

Feature: Add support for function marker (not in a comment)

In ngx-translate world exists key extractor https://github.com/biesbjerg/ngx-translate-extract#marker-function, this marker work in ts files

Example of DTO:

import { _ } from 'any import with _ function';

class SignInDto {
    static titles = {
        username: _('Username'),
        password: _('Password')
    };
    username: string;
    password: string;
}

Example use in a component:

@Component({
})
export class SignInComponent {
    titles = SignInDto.titles;
}

Example use in a template:

<input matInput formControlName="username" [placeholder]="titles.username | transloco" />
<input matInput formControlName="password" [placeholder]="titles.password | transloco" />

i try will use import { translate } from '@ngneat/transloco'; but this function not for this, it force translate, it not for current case

now I use stupid code as a workaround this problem

import { translate } from '@ngneat/transloco';

class SignInDto {
    static titles = {
        // tslint:disable-next-line: binary-expression-operand-order
        username: 'Username' || translate('Username'),
        // tslint:disable-next-line: binary-expression-operand-order
        password: 'Password' || translate('Password')
    };
    username: string;
    password: string;
}

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Expected behavior

Minimal reproduction of the problem with instructions

For bug reports please provide the STEPS TO REPRODUCE and if possible a MINIMAL DEMO of the problem, for that you could use our stackblitz example

What is the motivation / use case for changing the behavior?

Environment


Angular version: X.Y.Z


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

transloco-keys-manager extract Invalid regular expression

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

When I run transloco-keys-manager extract I get following message:

> [email protected] i18n:extract C:\Users\gulanf\Documents\translation
> transloco-keys-manager extract

C:\Users\gulanf\Documents\translation\node_modules\@ngneat\transloco-keys-manager\regexs.js:1
(function (exports, require, module, __filename, __dirname) { "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const sanitizeForRegex_1=require("./helpers/sanitizeForRegex");exports.regexs={templateKey:e=>new Re
gExp(`${e}\\((?![^,)+]*\\+)('|")(?<key>[^)"']*?)\\1`,"g"),directive:()=>new RegExp("\\stransloco\\s*=\\s*(\"|')(?<key>[^]+?)\\1","g"),directiveTernary:()=>new RegExp("\\s\\[transloco\\]\\s*=\\s*(\"|')[^\"'?]*\\?(?<key>[^]+?)\\1","
g"),pipe:()=>/(?:(?:\{\{(?![^^}\|+]*\+)[^}\|'"]*)|(?:\[[^\]]*\]=(?:"|')(?![^'"+]*\+)[^'"]*))('|")(?<key>[^'"[>=]*?)\1[^'"\|[}]*(?:('|")(?<key2>[^"'[>]*?)\3)?[^\|}>[]*?\|[^}>]*?transloco/g,fileLang:e=>new RegExp(`${sanitizeForRegex
_1.sanitizeForRegex(e)}\\/(?:(?<scope>(?:[^\\.]*)*)\\/)?(?<fileLang>[^./]*)\\.json`),serviceInjection:/[^]*(?=(?:private|protected|public)\s+(?<serviceName>[^,:()]+)\s*:\s*(?:TranslocoService\s*(?:,|\))))[^]*/,translationCalls:e=>
{const s

SyntaxError: Invalid regular expression: /[^]*(?=(?:private|protected|public)\s+(?<serviceName>[^,:()]+)\s*:\s*(?:TranslocoService\s*(?:,|\))))[^]*/: Invalid group
    at Object.<anonymous> (C:\Users\gulanf\Documents\translation\node_modules\@ngneat\transloco-keys-manager\regexs.js:1:194)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\gulanf\Documents\translation\node_modules\@ngneat\transloco-keys-manager\keysBuilder\getStructuralDirectiveBasedKeys.js:1:146)
    at Module._compile (module.js:653:30)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] i18n:extract: `transloco-keys-manager extract`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] i18n:extract script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\gulanf\AppData\Roaming\npm-cache\_logs\2019-11-18T10_28_04_726Z-debug.log

And debug log contains:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'i18n:extract' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prei18n:extract', 'i18n:extract', 'posti18n:extract' ]
5 info lifecycle [email protected]~prei18n:extract: [email protected]
6 info lifecycle [email protected]~i18n:extract: [email protected]
7 verbose lifecycle [email protected]~i18n:extract: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~i18n:extract: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\gulanf\Documents\translation\node_modules\.bin;C:\Users\gulanf\Documents\translation\node_modules\.bin;C:\ProgramData\DockerDesktop\version-bin;C:\Program Files\Docker\Docker\Resources\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\PuTTY\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Programs\apache-maven-3.6.2\bin;C:\ProgramData\chocolatey\bin;C:\Users\gulanf\.windows-build-tools\python27\;C:\Users\gulanf\AppData\Local\Microsoft\WindowsApps;C:\Users\gulanf\AppData\Roaming\npm;C:\Exercism;C:\Users\gulanf\AppData\Local\Microsoft\WindowsApps;C:\tools\dart-sdk\bin;C:\Users\gulanf\AppData\Roaming\Pub\Cache\bin;
9 verbose lifecycle [email protected]~i18n:extract: CWD: C:\Users\gulanf\Documents\translation
10 silly lifecycle [email protected]~i18n:extract: Args: [ '/d /s /c', 'transloco-keys-manager extract' ]
11 silly lifecycle [email protected]~i18n:extract: Returned: code: 1  signal: null
12 info lifecycle [email protected]~i18n:extract: Failed to exec i18n:extract script
13 verbose stack Error: [email protected] i18n:extract: `transloco-keys-manager extract`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:915:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid [email protected]
15 verbose cwd C:\Users\gulanf\Documents\translation
16 verbose Windows_NT 10.0.18362
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "i18n:extract"
18 verbose node v8.16.1
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] i18n:extract: `transloco-keys-manager extract`
22 error Exit status 1
23 error Failed at the [email protected] i18n:extract script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

## Expected behavior

Run transloco-keys-manager extract and get translations keys.

## Minimal reproduction of the problem with instructions

For bug reports please provide the _STEPS TO REPRODUCE_ and if possible a _MINIMAL DEMO_ of the problem, for that you could use our [stackblitz example](https://stackblitz.com/edit/transloco-example)

What is the motivation / use case for changing the behavior?

I want to use this lib in my project.

Environment


Angular version: 7.3.9


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: 8.16.1 
- Platform:  Windows 

Others:

Cant install @ngneat/transloco:keys-manager via yarn package mananger

I'm submitting a bug


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[x] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

in README there are installation instrudtions for ng, but the package name @ngneat/transloco:keys-manager with : is not working for yarn package manager

Expected behavior

Adding a script on how to add it via yarn package manager.

yarn global add @ngneat/transloco-keys-manager

Minimal reproduction of the problem with instructions

  1. following installation instruction and copying package name to yarn provide error

  2. yarn global add @ngneat/transloco:keys-manager

    β†’ yarn global add @ngneat/transloco:keys-manager
    yarn global v1.22.5
    [1/4] πŸ”  Resolving packages...
    error An unexpected error occurred: "https://registry.yarnpkg.com/@ngneat%2ftransloco:keys-manager: Not found".
    info If you think this is a bug, please open a bug report with the information provided in 
    "/Users/maciejsypien/.config/yarn/global/yarn-error.log".
    info Visit https://yarnpkg.com/en/docs/cli/global for documentation about this command.
    
  3. hen replacing : with - installation succeeded.

What is the motivation / use case for changing the behavior?

trying/installing transloco-keys-manager CLI without a need to have angular project installed (via ng)

Environment

For Tooling issues:

  • Node version: v10.21.0
  • Platform: MacOS 10.15.6 (19G2021)

Keys manager config

None

Dynamic Keys are not extracted correctly

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Dynamic keys are not extracted correctly

<!-- t('form.errorMessages.404', 'form.errorMessages.default') -->
<article *transloco="let t; read: 'auth.login'">

is extracted like this:

  "'form": {
    "errorMessages": {
      "404'": "null",
      "default'": "null"
    }
  }

Expected behavior

Should be extracted correctly and respect the read option in the directive

"login": {
      "form": {
        "errorMessages": {
          "404": "null",
          "default": "null"
        }
}

Environment


Angular version: 8.2.9

Empty defaultValue not respected when extracting keys

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

I wanted to have empty missing translation values so I passed -d "" to extract command. It was ignored - the default fell back to 'Missing value for...'.

Expected behavior

I'd expect empty defaultValue to be respected

Minimal reproduction of the problem with instructions

"i18n:extract": "transloco-keys-manager extract -u -l en de fr -d \"\"",

What is the motivation / use case for changing the behavior?

In our project we use BabelEdit to help translating the strings. BabelEdit detects empty strings and allows easy 'one-click' machine translation for all empty keys.

Environment

every

Possible bug location

https://github.com/ngneat/transloco-keys-manager/blob/060382f0ae479ccaae8b3608dc946185e1e6df35/src/keysBuilder/addKey.ts#L12-L14

Translations path error since release 2.x.x 'Translations path path provided doesn't exist!'

I'm submitting a...


[x] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

node script
transloco-keys-manager find --translations-path src/assets/i18n/ --langs de
throws
Translations path path provided doesn't exists!

Expected behavior

  1. translations path is given -> no error
  2. should show missing keys on console and return error code [1]
  3. error should show the inserted path to the developer

Minimal reproduction of the problem with instructions

package.json

{
 "scripts": {
 "i18n:find": "transloco-keys-manager find --translations-path src/assets/i18n/ --langs de" 
 }
}

project structure
πŸ“œpackage.json
β”— πŸ“‚src
┃ ┣ πŸ“‚assets
┃ ┃ β”— πŸ“‚i18n
┃ ┃ ┃ β”— πŸ“œde.json

STEPS TO REPRODUCE

  1. Update transloco-keys-manager from 1.3.2 -> 2.X.X
  2. run on console:
    $npm run i18n:find

What is the motivation / use case for changing the behavior?

To include the 'i18n:find' script into our ci pipeline for missing key detection.

Environment


Angular version:
Angular v9.1.5
 
For Tooling issues:
- Node version: v12.16.2
- Platform:  MacOS v10.14.6

Others:
Transloco v2.17.1
Transloco-keys-manager v2.0.6

Keys Detective's return code for automated validation

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

transloco-keys-manager find always ends with code 0 (no error).

Expected behavior

It would be useful if the transloco-keys-manager find would return some different exit code if missing keys would be found. This would enable to use this tool for validation in build/release tools like CI.

Minimal reproduction of the problem with instructions

Run the transloco-keys-manager find and see the exit code.

What is the motivation / use case for changing the behavior?

I would like to automate the process and make it easy for the developers and the CI to notice that some keys are missing (and not translated) in the extracted file.

Environment

For Tooling issues:

  • Node version: v12.16.2
  • Platform: Windows

"transloco-keys-manager find" support for dynamically created strings(keys) in html

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Dynamicly generated translation strings (for example

{{t(dynamicKey + '.title')}}) is not recognized by key-manager and "transloco-keys-manager find" sees those strings (inside i18n json files) as an extra ones. So In my app I have json structured like that:
{
"instagram": {"title": "Instram Title"},
"facebook": {"title": "Facebook Title"}
}

Expected behavior

Would be nice if there was a possibility either to suppress specific strings (keys) for key-manager or somehow make it see that they are actually used.

Minimal reproduction of the problem with instructions

Here is an example of such structure. (Unfortunately I don't how if it's possible to run key-manager somehow in stackblitz)
https://stackblitz.com/edit/ngneat-transloco-i1jga7

What is the motivation / use case for changing the behavior?

I use "transloco-keys-manager find -e" (so it throws an error) and thus it blocks my pipelines(CI) steps. I would like to keep this behivor but still be able to use dynamic keys.

Environment


Angular version: 9.1.11


Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: v14.2.0

- Platform:   Linux

Others:

Deep sorting of keys extractor result

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report 
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

After extracting keys by webpack plugin only first level keys are sorted in JSON file:

JSON:
{
    "login": {
        "password": "password",
        "sign in": "sign in"
        },
    "user": {
        "profile": "profile",
        "image": "image"
        }
}

Expected behavior

Deep sorting of second level keys - 'profile' and 'image' shoud be sorted as well as 'login' and 'user'

HTML:
<ng-container *transloco="let t; read: 'user'">
    <span>{{ t('image') }}</span>
    <span>{{ t('profile') }}</span>
</ng-container>

JSON:
{
    "login": {
        "password": "password",
        "sign in": "sign in"
        },
    "user": {
        "image": "image",
        "profile": "profile"
        }
}

Minimal reproduction of the problem with instructions

Starting app with --extra-webpack-config webpack-dev.config.js, then keys extractor generates keys which are sorted only on first level, nested keys are not sorted. This behavior causes merging problems, because nested keys are generated every time in different order.

Environment


Angular version: 8.2.3

For Tooling issues:
- Node version: v12.16.3
- Platform:  Windows 10

Others:
webpack-dev.config.js:
module.exports = {
  plugins: [new TranslocoExtractKeysWebpackPlugin({
    defaultValue: "{{key}}",
    langs: ["en"],
    unflat: true,
	sort: true
  })]
};

Detective dosn't detect keys with parentesis simbols

valores proporcionados I'm submitting a...


[ ] Regression
[x] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other

Current behavior

When you run the i18n:extract comand the keys with parentesis simbols are not found

Firts than anything: cngratulations on your excelet work

It may be not the best practice to choose words based keys approach, but in this case the manager doen't detect the keys with "(",")" simbols.

PD: sorry if my inglish it's not so good.

Environment

Angular version: 7.2.0

For Tooling issues:

  • Node version: 10.18.0
  • Platform: Linux

Find should be able to whitelist translation files like extract does

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Find check all json files in translations directory. Our client wanted to be able to see translation keys to help him do the translations so we used empty json file as one of the steps to enable such feature. Later we realized that using find now produces huge output detailing that all keys are missing from that empty json. I'm writing this as a feature request to just add similar config option as extract has, where we whitelist desired languages to check. However if there is some better way to toggle translation to translation keys (probably directly in transloco) please let me know.

Expected behavior

Find should have an option to whitelist languages that will be checked.

Minimal reproduction of the problem with instructions

Just add empty.json file next to files with translations and run 'find'

What is the motivation / use case for changing the behavior?

See at the beginning

Environment


Angular version: ~9.1.0
transloco: ^2.14.2,



For Tooling issues:
- Node version: 12.16.3
- Platform:  Windows 

Extracting from scoped library behaves differently in templates and .ts files

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Running the extraction on a library transloco-keys-manager extract --unflat -i src/lib behaves differently in templates and .ts files:

In the template, using {{'MY_LIBRARY.BUTTON' | transloco}} writes to the file projects/my-library/src/assets/i18n/my-library/en.json.


{
    "BUTTON": "Missing value for 'MY_LIBRARY.BUTTON'"
}

In the .ts files, using this.translationService.translate('MY_LIBRARY.BUTTON2') writes to the file projects/my-library/src/assets/i18n/en.json.


{
    "MY_LIBRARY": {
            "BUTTON2": "Missing value for 'MY_LIBRARY.BUTTON2'"
    }
}

Note:
In the library's module my-library.module.ts I have defined a Scope:


providers: [
    {
      provide: TRANSLOCO_SCOPE,
      useValue: { scope: 'my-library', alias: 'MY_LIBRARY' },
    },
    ...
],

Expected behavior

In both situation the translations should end up on the same file

Environment


Angular version: 8

Browser:
- [x ] Chrome (desktop) version 78
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: 10.16 
- Platform:  Mac

Throw error on missing keys

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

There is an option to emit an error on extra keys but no for missing keys.

Expected behavior

It would be useful if the transloco-keys-manager find would return exit code if missing keys would be found. This would enable to use this tool for validation in build/release tools like CI.

Minimal reproduction of the problem with instructions

Missing option so there is no possibility to reproduce it

What is the motivation / use case for changing the behavior?

I wouldn't like to push code with any missing keys.

Environment

For Tooling issues:

  • Node version: 12.18.1
  • Platform: Windows 10

Support multiple apps/libs in NX workspace

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

At the moment it is only possible to set one app within the rootTranslationsPath. I am using NX with multiple apps and libs.

Expected behavior

It should be possible to have multiple root translation paths / to support multiple apps.

Minimal reproduction of the problem with instructions

Create two projects within a NX workspace.

What is the motivation / use case for changing the behavior?

Make it usable within NX.

Error: Cannot find module 'fs-extra'

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Without karma installed an error occurs when using i18n:extract, i18n:find or webpack plugin:

> [project name removed]@0.0.0 i18n:extract [project path removed]
> transloco-keys-manager extract

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'fs-extra'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> ([project path removed]\node_modules\@ngneat\transloco-keys-manager\keysBuilder\buildTranslationFile.js:1:201)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] i18n:extract: `transloco-keys-manager extract`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] i18n:extract script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\[user name removed]\AppData\Roaming\npm-cache\_logs\2019-12-17T10_40_24_697Z-debug.log

Expected behavior

The tool should run without errors.

Minimal reproduction of the problem with instructions

For bug reports please provide the STEPS TO REPRODUCE and if possible a MINIMAL DEMO of the problem, for that you could use our stackblitz example

  • create new Angular Project
  • uninstall karma
  • install transloco
  • install transloco-keys-manager
  • run any of the commands npm start, npm run i18n:extract, npm run i18n:find

What is the motivation / use case for changing the behavior?

Environment


Angular CLI: 8.3.20
Node: 10.16.3
OS: win32 x64
Angular: 8.2.14
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.803.20
@angular-devkit/build-angular     0.803.20
@angular-devkit/build-optimizer   0.803.20
@angular-devkit/build-webpack     0.803.20
@angular-devkit/core              8.3.20
@angular-devkit/schematics        8.3.20
@angular/cli                      8.3.20
@ngtools/webpack                  8.3.20
@schematics/angular               8.3.20
@schematics/update                0.803.20
rxjs                              6.4.0
typescript                        3.5.3
webpack                           4.39.2


This bug probabbly was probabbly not discoved until now, becuase angular installs karma by default, which installs fs-extra. We removed karma, form our project, because we do not use it.
The fs-extra devDependency needs to be moved to the runtime dependencies.

Problem running transloco-keys-manager find on Windows

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

After installing tranloco and transloco key manager tried running: npm run i18n:find and got:

√ Extracting Template and Component Keys �
- Checking for missing keys ✨M:\Works\agro\agro-client\node_modules\@ngneat\transloco-keys-manager\helpers\getScopeAndLangFromFullPath.js:1
"use strict";function getScopeAndLangFromFullPath(e,t){!1===t.endsWith("/")&&(t=`${t}/`);const[n,o]=e.split(t),l=o.split("/");let p,r;return l.length>1?(r=l.pop().replace(".json",""),p=l.join("/")):r=l[0].replace(".json",""),{scope:p,lang:r}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.getScopeAndLangFromFullPath=getScopeAndLangFromFullPath;
                                                                                                                   ^

TypeError: Cannot read property 'split' of undefined
    at Object.getScopeAndLangFromFullPath (M:\Works\agro\agro-client\node_modules\←[4m@ngneat←[24m\transloco-keys-manager\helpers\getScopeAndLangFromFullPath.js:1:116)
    at Object.compareKeysToFiles (M:\Works\agro\agro-client\node_modules\←[4m@ngneat←[24m\transloco-keys-manager\keysDetective\compareKeysToFiles.js:1:1024)
    at Object.findMissingKeys (M:\Works\agro\agro-client\node_modules\←[4m@ngneat←[24m\transloco-keys-manager\keysDetective.js:1:835)
    at Object. (M:\Works\agro\agro-client\node_modules\←[4m@ngneat←[24m\transloco-keys-manager\index.js:2:744)
←[90m    at Module._compile (internal/modules/cjs/loader.js:959:30)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:815:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:727:14)←[39m
←[90m    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)←[39m
←[90m    at internal/main/run_main_module.js:17:11←[39m

Expected behavior

Lovely list that summarizes the keys found

Minimal reproduction of the problem with instructions

Executed:
ng add @ngneat/transloco
ng g @ngneat/transloco:keys-manager

Which generated scripts in package.json:

"i18n:extract": "transloco-keys-manager extract",
"i18n:find": "transloco-keys-manager find"

Executed:
npm run i18n:find

Tried to change transloco.config.js: keysManager.translationsPath to some other variants like: with /without ending slash, or with backslashes

Environment


Angular version: 8.2.12

For Tooling issues:
- Node version: v12.13.1
- Platform:  Windows 7 Ultimate

Others:
transloco.config.js:
module.exports = {
	rootTranslationsPath: 'src/assets/i18n/',
	langs: ['en', 'lv'],
	keysManager: {
		input: 'src/app',
		translationsPath: 'src/assets/i18n',
		sort: true,
		addMissingKeys: true,
		replace: true
	}
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.