Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Grumphp Xliff Task Laravel Package

pluswerk/grumphp-xliff-task

GrumPHP task to lint XLF/XLIFF translation files. Configure ignore patterns and XML validation options (load_from_net, x_include, DTD and schema validation) and run on commits via GrumPHP (triggered_by: xlf).

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the package via Composer in your Laravel project (dev dependency):

    composer require --dev pluswerk/grumphp-xliff-task
    
  2. Configure GrumPHP (grumphp.yml) to include the task:

    parameters:
        tasks:
            xlifflint:
                ignore_patterns: []  # Add patterns like ['vendor/', 'tests/'] if needed
                triggered_by: [xlf, xliff]  # Files to trigger the task
    extensions:
        - PLUS\GrumPHPXliffTask\ExtensionLoader
    
  3. Run GrumPHP locally to test:

    ./vendor/bin/grumphp run
    
    • Focus on files with .xlf or .xliff extensions.

First Use Case

Validate XLIFF files before merging translations into your Laravel localization workflow (e.g., Spatie Translation Manager or custom XLIFF-based systems).

  • Example: Catch malformed XML in translation files early, preventing deployment of broken translations.

Implementation Patterns

Core Workflows

  1. Pre-Commit Hook Integration

    • Add to .git/hooks/pre-commit or use grumphp's built-in Git hooks:
      # grumphp.yml
      hooks:
          pre_commit:
              tasks: [xlifflint]
      
    • Ensures XLIFF files are linted before commits are accepted.
  2. CI/CD Pipeline Enforcement

    • Run in GitHub Actions/GitLab CI:
      # .github/workflows/grumphp.yml
      jobs:
        lint-xliff:
          runs-on: ubuntu-latest
          steps:
            - uses: actions/checkout@v4
            - run: composer install --dev
            - run: ./vendor/bin/grumphp run --tasks=xlifflint
      
    • Fail the pipeline if XLIFF files violate rules.
  3. Dynamic Configuration

    • Use Laravel’s config() to override ignore_patterns per environment:
      // config/grumphp.php
      'xlifflint' => [
          'ignore_patterns' => env('APP_ENV') === 'production'
              ? ['storage/old-translations/']
              : [],
      ];
      
    • Load dynamically in grumphp.yml via parameters.

Laravel-Specific Tips

  • Pair with Laravel Localization Packages

    • Use alongside spatie/laravel-translation-loader to ensure XLIFF files align with your app’s translation structure.
    • Example: Validate that all XLIFF files reference keys used in your Laravel views.
  • Artisan Command Integration

    • Create a custom Artisan command to run XLIFF linting on demand:
      // app/Console/Commands/LintXliff.php
      public function handle()
      {
          $grumphp = new \GrumPHP\Runner();
          $grumphp->run(['--tasks' => 'xlifflint']);
      }
      
    • Call via:
      php artisan lint-xliff
      

Advanced Patterns

  1. Schema Validation

    • Enable DTD/schema checks for strict XLIFF compliance:
      tasks:
          xlifflint:
              dtd_validation: true
              scheme_validation: true
      
    • Useful for projects adhering to specific XLIFF standards (e.g., OASIS XLIFF 1.2).
  2. Network Dependency Control

    • Disable load_from_net if your CI environment restricts external requests:
      tasks:
          xlifflint:
              load_from_net: false
      
  3. Custom Error Handling

    • Extend the task to log XLIFF issues to Laravel’s log:
      // app/Providers/AppServiceProvider.php
      public function boot()
      {
          \GrumPHP\Task\XliffLintTask::setLogger(function ($message) {
              \Log::info('XLIFF Lint: '.$message);
          });
      }
      

Gotchas and Tips

Common Pitfalls

  1. GrumPHP Version Mismatch

    • Issue: The package supports GrumPHP 0.12–1.3 and 2.x. Using an unsupported version (e.g., 0.11 or 1.4+) may break the task.
    • Fix: Pin GrumPHP in composer.json:
      "require-dev": {
          "grumphp/grumphp": "^1.3"
      }
      
  2. Path Resolution Failures

    • Issue: Older versions used __DIR__ instead of getcwd(), causing path errors in CI.
    • Fix: Update to v10.2.7+ or manually set the working directory in CI:
      # GitHub Actions
      - run: cd $GITHUB_WORKSPACE && ./vendor/bin/grumphp run
      
  3. Silent Failures

    • Issue: The task may fail silently if the underlying xlifflint tool is missing or misconfigured.
    • Fix: Verify xlifflint is installed in your CI environment:
      # Example for Ubuntu
      sudo apt-get install xlifflint
      
    • Or use a Docker image with the tool preinstalled.
  4. Performance with Large Files

    • Issue: The package lacks optimizations for large XLIFF files (e.g., >50MB), leading to timeouts.
    • Fix:
      • Split validation by language/file size in CI.
      • Use ignore_patterns to exclude non-critical files temporarily.
  5. Namespace Confusion

    • Issue: Upgrading from andersundsehr/grumphp-xliff-task may leave old namespace references (AUS\GrumPHPXliffTask\ExtensionLoader).
    • Fix: Update grumphp.yml to use the new namespace:
      extensions:
          - PLUS\GrumPHPXliffTask\ExtensionLoader
      

Debugging Tips

  1. Enable Verbose Logging

    • Run GrumPHP with debug mode to inspect task execution:
      ./vendor/bin/grumphp run --verbose --tasks=xlifflint
      
  2. Test with a Subset of Files

    • Temporarily limit triggered_by to a single file to isolate issues:
      tasks:
          xlifflint:
              triggered_by: [path/to/test.xlf]
      
  3. Check XLIFF File Validity

    • Validate files manually using xlifflint:
      xlifflint path/to/file.xlf
      
  4. CI-Specific Quirks

    • GitHub Actions: Ensure the xlifflint tool is available in the container. Use a custom Docker image if needed.
    • GitLab CI: Cache the xlifflint binary to avoid reinstallation:
      cache:
          key: xlifflint
          paths:
              - .xlifflint-cache
      

Extension Points

  1. Custom Validation Rules

    • Extend the task by subclassing \PLUS\GrumPHPXliffTask\Task\XliffLintTask:
      // app/GrumPHP/XliffCustomTask.php
      class XliffCustomTask extends \PLUS\GrumPHPXliffTask\Task\XliffLintTask
      {
          protected function validateFile($file)
          {
              // Add custom logic (e.g., check for specific tags)
              if (!str_contains(file_get_contents($file), '<target>')) {
                  return $this->createFailure('Missing target element in '.$file);
              }
              return parent::validateFile($file);
          }
      }
      
    • Register in grumphp.yml:
      extensions:
          - App\GrumPHP\XliffCustomTask
      
  2. Dynamic Configuration

    • Override task settings via Laravel’s service container:
      // config/grumphp.php
      'xlifflint' => [
          'ignore_patterns' => config('app.xliff_ignore_patterns'),
      ];
      
  3. Post-Validation Actions

    • Trigger Laravel events or notifications after validation:
      // app/Providers/AppServiceProvider.php
      public function boot()
      {
          \GrumPHP\Task\XliffLintTask::onFailure(function ($task, $file) {
              event(new \App\Events\XliffValidationFailed($file));
          });
      }
      

Configuration Quirks

  1. triggered_by vs. file_extensions
    • The package uses triggered_by (not file_extensions) to define file patterns. Ensure your grumphp.yml matches:
      tasks:
          xlifflint:
              triggered_by: [xlf, xliff]  # Correct
              # file_extensions: [xlf, xliff]
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky