Skip to content

Commit ad1dc32

Browse files
docs: improve file detection and validator documentation with formatting enhancements and additional examples
1 parent 802d2a6 commit ad1dc32

4 files changed

Lines changed: 30 additions & 237 deletions

File tree

README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ Supports XLIFF, YAML, JSON and PHP translation files.
1616
## ✨ Features
1717

1818
* Autodetect coherent language files
19-
* Supports various [translation formats](#supported-translation-file-formats)
19+
* Supports various [translation file formats](#supported-translation-file-formats)
2020
* Provides multiple [validators](#translation-validators)
21+
* Configurable via separate [configuration files](docs/config-file.md)
2122

2223
## 🔥 Installation
2324

@@ -45,18 +46,20 @@ The command `validate-translations` can be used to validate translation files in
4546

4647
### Supported File Formats
4748

48-
| Format | Frameworks | Examples |
49-
|--------|------------|----------|
50-
| **[XLIFF](docs/file-detector.md#xliff-xml-localization-interchange-file-format)** | TYPO3 CMS | `locallang.xlf`, `de.locallang.xlf` |
51-
| **[YAML](docs/file-detector.md#yaml-yaml-aint-markup-language)** | Symfony | `messages.en.yaml`, `messages.de.yaml` |
52-
| **[JSON](docs/file-detector.md#json-javascript-object-notation)** | Laravel, Symfony | `messages.en.json`, `messages.de.json` |
53-
| **[PHP](docs/file-detector.md#php-arrays)** | Laravel, Symfony | `en/messages.php`, `messages.en.php` |
49+
Translations will be detected and grouped by the following formats:
5450

55-
See detailed format [documentation](docs/file-detector.md) and file grouping.
51+
| Format | Frameworks | Example files |
52+
|--------|------------|----------------------------------------|
53+
| [XLIFF](docs/file-detector.md#xliff-xml-localization-interchange-file-format) | TYPO3 CMS | `locallang.xlf`, `de.locallang.xlf` |
54+
| [YAML](docs/file-detector.md#yaml-yaml-aint-markup-language) | Symfony | `messages.en.yaml`, `messages.de.yaml` |
55+
| [JSON](docs/file-detector.md#json-javascript-object-notation) | Laravel, Symfony | `messages.en.json`, `messages.de.json` |
56+
| [PHP](docs/file-detector.md#php-arrays) | Laravel, Symfony | `en/messages.php`, `messages.en.php` |
57+
58+
See detailed [file format and file detection documentation](docs/file-detector.md) with examples.
5659

5760
### Translation Validators
5861

59-
The following translation validators are available:
62+
The following translation validators are available (and enabled by default):
6063

6164
| Validator | Description |
6265
|-----------|-------------|
@@ -70,11 +73,7 @@ The following translation validators are available:
7073
| [PlaceholderConsistencyValidator](docs/validators.md#placeholderconsistencyvalidator) | Validates placeholder patterns |
7174
| [XliffSchemaValidator](docs/validators.md#xliffschemavalidator) | Validates XLIFF against XML schemas |
7275

73-
View detailed [documentation](docs/validators.md) with examples.
74-
75-
### Validator-Specific Configuration
76-
77-
Some validators support additional configuration options. For detailed configuration instructions and examples, see [Validator Configuration](docs/validator-configuration.md).
76+
View detailed [validator documentation](docs/validators.md) with examples.
7877

7978
## 🧑‍💻 Contributing
8079

docs/file-detector.md

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@
22

33
This document provides comprehensive information about supported translation file formats and how the validator detects and groups related translation files across different languages.
44

5+
- [Supported Translation File Formats](#supported-translation-file-formats)
6+
- [XLIFF](#xliff)
7+
- [YAML](#yaml)
8+
- [JSON](#json)
9+
- [PHP Arrays](#php-arrays)
10+
- [File Detection Strategies](#file-detection-strategies)
11+
- [PrefixFileDetector](#prefixfiledetector)
12+
- [SuffixFileDetector](#suffixfiledetector)
13+
- [DirectoryFileDetector](#directoryfiledetector)
14+
515
## Supported Translation File Formats
616

717
The Composer Translation Validator supports multiple translation file formats commonly used in PHP frameworks and applications:
818

9-
### XLIFF (XML Localization Interchange File Format)
19+
### XLIFF
1020
- **Extensions**: `.xlf`, `.xliff`
1121
- **Frameworks**: TYPO3 CMS, Symfony (optional)
12-
- **Features**: Industry standard, supports metadata, translation states, and comments
13-
- **Structure**: XML-based with `<source>` and `<target>` elements
1422
- **Example**:
1523
```xml
1624
<?xml version="1.0" encoding="UTF-8"?>
@@ -26,11 +34,9 @@ The Composer Translation Validator supports multiple translation file formats co
2634
</xliff>
2735
```
2836

29-
### YAML (YAML Ain't Markup Language)
37+
### YAML
3038
- **Extensions**: `.yaml`, `.yml`
3139
- **Frameworks**: Symfony (primary), Laravel (supported)
32-
- **Features**: Human-readable, supports nested structures, comments
33-
- **Structure**: Key-value pairs with hierarchical nesting
3440
- **Example**:
3541
```yaml
3642
welcome: "Welcome to our application"
@@ -42,11 +48,9 @@ The Composer Translation Validator supports multiple translation file formats co
4248
about: "About Us"
4349
```
4450
45-
### JSON (JavaScript Object Notation)
51+
### JSON
4652
- **Extensions**: `.json`
4753
- **Frameworks**: Laravel, Symfony, Vue.js, React
48-
- **Features**: Lightweight, widely supported, machine-readable
49-
- **Structure**: Nested objects and arrays
5054
- **Example**:
5155
```json
5256
{
@@ -65,8 +69,6 @@ The Composer Translation Validator supports multiple translation file formats co
6569
### PHP Arrays
6670
- **Extensions**: `.php`
6771
- **Frameworks**: Laravel (primary), Symfony (supported)
68-
- **Features**: Native PHP syntax, supports complex data structures, dynamic values
69-
- **Structure**: PHP array return statements
7072
- **Example**:
7173
```php
7274
<?php
@@ -87,9 +89,7 @@ The Composer Translation Validator supports multiple translation file formats co
8789

8890
File Detectors group translation files that represent the same content in different languages. The validator supports three detection strategies for different project layouts.
8991

90-
### Available File Detectors
91-
92-
#### PrefixFileDetector
92+
### PrefixFileDetector
9393
Groups files where the language code appears as a **prefix**.
9494

9595
- **Pattern**: `{lang}.{name}.{ext}` or `{name}.{ext}`
@@ -98,7 +98,7 @@ Groups files where the language code appears as a **prefix**.
9898
- **Example**: `en.messages.xlf`, `de.messages.xlf` → grouped as `messages.xlf`
9999
- **Framework Context**: Common in TYPO3 where the default language file has no prefix
100100

101-
#### SuffixFileDetector
101+
### SuffixFileDetector
102102
Groups files where the language code appears as a **suffix**.
103103

104104
- **Pattern**: `{name}.{lang}.{ext}`
@@ -107,7 +107,7 @@ Groups files where the language code appears as a **suffix**.
107107
- **Example**: `messages.en.yaml`, `messages.de.yaml` → grouped as `messages`
108108
- **Framework Context**: Standard approach in Symfony applications
109109

110-
#### DirectoryFileDetector
110+
### DirectoryFileDetector
111111
Groups files organized in **language directories**.
112112

113113
- **Pattern**: `{lang}/{name}.{ext}`
@@ -253,43 +253,3 @@ file-detectors:
253253
]
254254
}
255255
```
256-
257-
## Troubleshooting Common Issues
258-
259-
### No Translation Files Detected
260-
**Symptoms**: Command shows "No translation files found"
261-
262-
**Solutions**:
263-
- Verify file extensions are supported (`.xlf`, `.yaml`, `.json`, `.php`)
264-
- Check language codes follow supported formats
265-
- Ensure file naming matches one of the three patterns
266-
- Use `--verbose` flag to see detection details
267-
- Try `--recursive` flag for nested directories
268-
269-
### Files Not Grouped Correctly
270-
**Symptoms**: Validators report missing translations when files exist
271-
272-
**Solutions**:
273-
- Ensure consistent naming pattern throughout project
274-
- Don't mix different detection patterns in the same directory
275-
- Check for typos in language codes or file names
276-
- Verify file extensions are identical across language variants
277-
- Use `--verbose` to see how files are being grouped
278-
279-
### Mixed Project Structures
280-
**Symptoms**: Some files detected, others ignored
281-
282-
**Solutions**:
283-
- Reorganize files to use consistent pattern
284-
- Configure specific detectors manually
285-
- Use separate validation runs for different file types
286-
- Consider splitting translation directories by pattern
287-
288-
### Performance with Large Projects
289-
**Symptoms**: Slow file detection or high memory usage
290-
291-
**Solutions**:
292-
- Use specific paths instead of project root
293-
- Configure exclude patterns for non-translation directories
294-
- Limit file detectors to only needed types
295-
- Use `--recursive` selectively rather than globally

docs/validator-configuration.md

Lines changed: 0 additions & 166 deletions
This file was deleted.

docs/validators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ composer -d tests validate-translations Fixtures/examples/encoding --only "MoveE
238238
239239
---
240240

241-
## [`HtmlTagValidator`](../src/Validator/HtmlTagValidator.php)HtmlTagValidator
241+
## [`HtmlTagValidator`](../src/Validator/HtmlTagValidator.php)
242242

243243
Verifies HTML tags are consistent across all language versions: same tags, proper nesting, matching attributes.
244244

0 commit comments

Comments
 (0)