Skip to content

Conversation

@shaharkazaz
Copy link
Collaborator

Summary

Adds support for ${sourceRoot} variable interpolation in output paths, enabling users to customize translation file locations across multiple apps/libs in NX workspaces using a single centralized configuration.

Problem (Issue #220)

When using transloco-keys-manager in NX monorepos, users want to:

  • Use a single transloco.config.js at the workspace root
  • Customize output paths (e.g., public/i18n instead of assets/i18n)
  • Have paths resolve differently per project

Previously, setting output: '${sourceRoot}/../public/i18n' would create a literal ${sourceRoot} folder instead of interpolating the variable.

Solution

This PR implements variable interpolation for ${sourceRoot}:

Example configuration:

// transloco.config.js (workspace root)
module.exports = {
  langs: ['en', 'fr'],
  keysManager: {
    output: '${sourceRoot}/../public/i18n',
    scopePathMap: {
      admin: '${sourceRoot}/../public/i18n/admin'
    }
  }
};

Results in different paths per project:

  • apps/my-app/public/i18n/en.json
  • libs/my-lib/public/i18n/en.json

Changes

  • ✅ Add ${sourceRoot} interpolation in resolveConfigPaths()
  • ✅ Add __sourceRoot internal field to Config type
  • ✅ Support interpolation in scopePathMap values via buildScopeFilePaths()
  • ✅ Extract interpolation logic into interpolatePathFactory() helper
  • ✅ Add comprehensive test coverage (20 new tests)
  • ✅ Add NX workspace integration test simulating real-world scenario
  • ✅ Fully backward compatible (existing configs work unchanged)

Test Coverage

New tests:

  • __tests__/path.utils.spec.ts - 5 tests for buildScopeFilePaths() interpolation
  • __tests__/resolveConfig/resolveConfig.spec.ts - 7 tests including NX workspace scenario

All 73 tests passing

Backward Compatibility

✅ Fully backward compatible - paths without ${sourceRoot} work exactly as before

Fixes #220

Enables users to use ${sourceRoot} variable in output paths, which gets
interpolated to each project's actual source root. This allows a single
centralized transloco.config.js to work across multiple apps/libs in NX
monorepos without duplicating configuration.

Example usage:
```js
module.exports = {
  keysManager: {
    output: '${sourceRoot}/../public/i18n',
    scopePathMap: {
      admin: '${sourceRoot}/../public/i18n/admin'
    }
  }
};
```

This resolves to different paths per project:
- apps/my-app/public/i18n
- libs/my-lib/public/i18n

Changes:
- Add ${sourceRoot} interpolation in resolveConfigPaths()
- Add __sourceRoot internal field to Config type
- Add interpolation support for scopePathMap values
- Add comprehensive tests including NX workspace scenario
- Refactor interpolation logic into interpolatePathFactory()

Fixes #220
@shaharkazaz shaharkazaz force-pushed the feat/sourceroot-interpolation-220 branch from b32d9a6 to 0db9b26 Compare December 7, 2025 10:15
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 7, 2025

Open in StackBlitz

npm i https://pkg.pr.new/jsverse/transloco-keys-manager/@jsverse/transloco-keys-manager@244

commit: 0db9b26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Unable to modify output per app/lib within nx workspace

2 participants