Transloco: Scoped keys showing in global JSON and used keys in TypeScript marked as unused

Discussão em 'Angular' iniciado por Learner, Junho 13, 2025.

  1. Learner

    Learner Guest

    I'm using @jsverse/transloco in an Angular project with a modular/scoped translations setup. Structure is:


    • **i18n -> en.json

      i18n -> home -> en.json**

    My config is defined like this:

    module.exports = {
    rootTranslationsPath: 'src/assets/i18n/',
    langs: ['en', 'es'],
    scopedLibs: [
    { name: 'home', translationPath: 'src/assets/i18n/home/' },
    { name: 'project-settings', translationPath: 'src/assets/i18n/project-settings/' },
    ...
    ],
    keysManager: {
    input: ['src/**/*.ts', 'src/**/*.html', '!src/**/*.spec.ts'],
    output: 'src/assets/i18n/$scope/$lang.json',
    marker: 'transloco:key',
    customMatchers: [
    {
    regex: /(?:this\.translocoService)\.translate\(['"`]([^'"`]+)['"`](?:\s*,\s*['"`]([^'"`]+)['"`])?\)/,
    keyIndex: 1,
    scopeIndex: 2
    },
    {
    regex: /provide:\s*TRANSLOCO_SCOPE,\s*useValue:\s*['"`]([^'"`]+)['"`]/,
    scopeIndex: 1
    }
    ]
    }
    };


    Issue 1: Scoped keys showing up in global JSON Even though I’ve added keys like 'project-settings.MICROPHONE' or 'my-dashboard.VIEW_ASSIGNMENT' inside their respective scoped folders (e.g. project-settings/en.json), the keys manager still reports them as missing and adds them to the global en.json file.

    These keys are used in components where I use the fully qualified key (e.g. project-settings.MICROPHONE) but not always with a TRANSLOCO_SCOPE provider in the component.

    Issue 2: Keys used in TypeScript files are marked as unused I also see keys reported as unused even though they are clearly used in TypeScript like this:

    this.translocoService.translate('ERROR', 'project-settings');


    I’ve verified that:

    The TRANSLOCO_SCOPE is added to components via providers array.

    providers: [
    {
    provide: TRANSLOCO_SCOPE,
    useValue: 'project-settings',
    },
    ],


    Keys are present in the correct JSON files (project-settings/en.json etc.)

    Continue reading...

Compartilhe esta Página