LogoLogo
❀️ SponserMore
  • πŸš€Getting Started
    • Installation
    • Angular Compatibility
    • Config Options
  • πŸ’‘Core Concepts
    • Translation in the Template
    • Signals
    • Translation API
    • Language API
  • 🧠Advanced Topics
    • πŸ¦₯Lazy Load
      • Scope Configuration
      • Inline Loaders
    • The Transpiler
    • SSR Support
    • Unit Testing
    • Hack the Library
  • πŸ§ͺSandbox & Examples
  • βš™οΈAdditional Functionality
    • Loading Template
    • Key Referencing
    • Utility Functions
    • Comments for Translators
    • Multiple Languages Simultaneously
  • πŸ“¦Migration Guides
    • Migrate from ngx-translate
    • Migrate from Angular's i18n
  • πŸ”§Tools
    • Keys Manager (TKM)
      • Keys Extractor
      • Keys Detective
      • Options
      • Debugging
      • Using with Nx πŸ‹
    • Validator
    • Optimize
    • Scoped Library Extractor
  • πŸ”ŒPlugins
    • Message Format
    • Persist Translations
    • Persist Lang
    • Preload Langs
    • Locale l10n
    • Community Plugins
  • 🧰Schematics
    • :ng-add
    • :scope
    • :join
    • :split
  • 🍳Recipies
    • Prefetch User Language
    • Using Xliff
    • Generate Locale Files using Google Translate
  • πŸ“šBlog Posts
    • Transloco Team Posts
      • Transloco Goes Functional: A Guide to Transloco's Functional Transpiler
    • From the Community
  • ❓FAQs
Powered by GitBook

@ 2025 Transloco

On this page
  • Installation
  • Usage
  • Benefits

Was this helpful?

  1. Tools

Validator

PreviousUsing with Nx πŸ‹NextOptimize

Last updated 5 months ago

Was this helpful?

The Transloco Validator package helps ensure the integrity of your translation files by validating their JSON structure and detecting duplicate keys. This tool is handy for maintaining consistent and error-free translation files throughout your project.

Installation

pnpm add @jsverse/transloco-validator --save-dev
yarn add @jsverse/transloco-validator --dev
npm install @jsverse/transloco-validator --save-dev

Usage

To ensure your translation files are always valid, configure Transloco Validator to run on specific paths during pre-commit checks. You can easily set this up in your lint-staged configuration.

lint-staged supports . All you need to do is add the following line to the configuration of your choice:

"src/assets/i18n/*.json": ["transloco-validator"]

This ensures that any changes to your translation files are validated before they are committed.

Here’s an example workflow that triggers when your translation files are changed and verifies them using the transloco-validator:

validate-translations.yml
name: Validate Translation Files

on:
  pull_request:
    paths:
      # Trigger when any i18n JSON file is modified
      - 'src/assets/i18n/**.json'

jobs:
  validate-translations:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Install Dependencies
        run: npm ci

      - name: Run Transloco Validator on Changed i18n Files
        run: |
          # Find the changed i18n files and run the validator on them
          git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep 'src/assets/i18n/.*\.json' | xargs npx transloco-validator

Benefits

  • JSON Validation: Verifies that all translation files have a valid JSON structure.

  • Duplicate Key Detection: Ensures no duplicate keys are present in your translation files.

By incorporating Transloco Validator into your workflow, you can maintain high-quality translation files and avoid runtime issues caused by invalid JSON or key conflicts.

πŸ”§
multiple configuration formats