For the complete documentation index, see llms.txt. This page is also available as Markdown.

Validator

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@next --save-dev
yarn add @jsverse/transloco-validator@next --dev
npm install @jsverse/transloco-validator@next --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 multiple configuration formats. 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.

Last updated

Was this helpful?