Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ If skipping rules, files, or folders is not sufficient, you can also skip entire
use a9f\FractorFluid\FluidFileProcessor;
use a9f\FractorHtaccess\HtaccessFileProcessor;
use a9f\FractorTypoScript\TypoScriptFileProcessor;
use a9f\FractorYaml\XliffFileProcessor;
use a9f\FractorXml\XmlFileProcessor;
use a9f\FractorYaml\YamlFileProcessor;

Expand All @@ -137,6 +138,7 @@ return FractorConfiguration::configure()
FluidFileProcessor::class,
HtaccessFileProcessor::class,
TypoScriptFileProcessor::class,
XliffFileProcessor::class,
XmlFileProcessor::class,
YamlFileProcessor::class,
]);
Expand Down
11 changes: 11 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"a9f/fractor-phpstan-rules": "self.version",
"a9f/fractor-rule-generator": "self.version",
"a9f/fractor-typoscript": "self.version",
"a9f/fractor-xliff": "self.version",
"a9f/fractor-xml": "self.version",
"a9f/fractor-yaml": "self.version",
"a9f/typo3-fractor": "self.version"
Expand All @@ -78,6 +79,10 @@
"a9f\\FractorPhpStanRules\\": "packages/fractor-phpstan-rules/src/",
"a9f\\FractorRuleGenerator\\": "packages/fractor-rule-generator/src/",
"a9f\\FractorTypoScript\\": "packages/fractor-typoscript/src/",
"a9f\\FractorXliff\\": [
"packages/fractor-xliff/rules/",
"packages/fractor-xliff/src/"
],
"a9f\\FractorXml\\": "packages/fractor-xml/src/",
"a9f\\FractorYaml\\": "packages/fractor-yaml/src/",
"a9f\\Fractor\\": "packages/fractor/src/",
Expand All @@ -99,6 +104,10 @@
"a9f\\FractorPhpStanRules\\Tests\\": "packages/fractor-phpstan-rules/tests/",
"a9f\\FractorRuleGenerator\\Tests\\": "packages/fractor-rule-generator/tests/",
"a9f\\FractorTypoScript\\Tests\\": "packages/fractor-typoscript/tests/",
"a9f\\FractorXliff\\Tests\\": [
"packages/fractor-xliff/rules-tests/",
"packages/fractor-xliff/tests/"
],
"a9f\\FractorXml\\Tests\\": "packages/fractor-xml/tests/",
"a9f\\FractorYaml\\Tests\\": "packages/fractor-yaml/tests/",
"a9f\\Fractor\\Tests\\": "packages/fractor/tests/",
Expand Down Expand Up @@ -160,6 +169,7 @@
"@composer normalize --dry-run packages/fractor-fluid/composer.json",
"@composer normalize --dry-run packages/fractor-htaccess/composer.json",
"@composer normalize --dry-run packages/fractor-typoscript/composer.json",
"@composer normalize --dry-run packages/fractor-xliff/composer.json",
"@composer normalize --dry-run packages/fractor-xml/composer.json",
"@composer normalize --dry-run packages/fractor-yaml/composer.json",
"@composer normalize --dry-run packages/typo3-fractor/composer.json"
Expand All @@ -174,6 +184,7 @@
"@composer normalize --no-check-lock packages/fractor-fluid/composer.json",
"@composer normalize --no-check-lock packages/fractor-htaccess/composer.json",
"@composer normalize --no-check-lock packages/fractor-typoscript/composer.json",
"@composer normalize --no-check-lock packages/fractor-xliff/composer.json",
"@composer normalize --no-check-lock packages/fractor-xml/composer.json",
"@composer normalize --no-check-lock packages/fractor-yaml/composer.json",
"@composer normalize --no-check-lock packages/typo3-fractor/composer.json"
Expand Down
5 changes: 5 additions & 0 deletions packages/fractor-xliff/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
phpunit.xml export-ignore
README.md export-ignore
3 changes: 3 additions & 0 deletions packages/fractor-xliff/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor/
/composer.lock
.phpunit.cache
25 changes: 25 additions & 0 deletions packages/fractor-xliff/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
The MIT License
---------------

Copyright (c) 2026-present Sebastian Schreiber and Christian Sonntag

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
91 changes: 91 additions & 0 deletions packages/fractor-xliff/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Fractor XLIFF

XLIFF extension for the [Fractor](https://github.com/andreaswolf/fractor) file refactoring tool.

Allows validating and transforming XLIFF (XML Localization Interchange File Format) translation files.
Supports XLIFF Versions 1.0, 1.1, 1.2 and 2.0.

## Installation

```bash
composer require a9f/fractor-xliff --dev
```

## Configuration

```php
<?php

use a9f\Fractor\Configuration\FractorConfiguration;
use a9f\FractorXliff\Configuration\XliffProcessorOption;
use a9f\Fractor\ValueObject\Indent;

return FractorConfiguration::configure()
->withPaths([__DIR__ . '/Resources/Private/Language/'])
->withOptions([
XliffProcessorOption::INDENT_CHARACTER => Indent::STYLE_SPACE,
XliffProcessorOption::INDENT_SIZE => 4,
XliffProcessorOption::ALLOWED_FILE_EXTENSIONS => ['xlf', 'xliff'],
]);
```

Have a look at all available rules [Overview of all rules](docs/xliff-fractor-rules.md)

## Processed File Extensions

By default, the following file extensions are processed: `xlf`, `xliff`.

## For Devlopers

All rules must implement the a9f\FractorXliff\Contract\XliffFractorRule interface.
The rule will be tagged with 'fractor.xliff_rule' and be injected in the XliffFileProcessor.

### Testing with DDEV

#### phpstan

```bash
ddev composer analyze:php
```

#### rector

```bash
ddev composer rector
```

Fix with:

```bash
ddev exec rector src/
```

#### composer normalize

```bash
ddev composer style:composer:normalize
```

Fix with:

```bash
ddev composer normalize
```

#### php-cs-fixer

```bash
ddev composer style:php:check
```

Fix with:

```bash
ddev exec ecs check --fix --config ecs.php src/
```

#### phpunit

```bash
ddev composer test:php
```
55 changes: 55 additions & 0 deletions packages/fractor-xliff/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "a9f/fractor-xliff",
"description": "XLIFF extension for the File Read-Analyse-Change Tool. Allows modifying XLIFF translation files",
"license": "MIT",
"type": "fractor-extension",
"keywords": [
"dev",
"fractor",
"upgrade",
"refactoring",
"automation",
"migration",
"xliff",
"translation"
],
"require": {
"php": "^8.2",
"ext-dom": "*",
"ext-xml": "*",
"a9f/fractor": "^0.5.10",
"a9f/fractor-extension-installer": "^0.5.10",
"simonschaufi/pretty-xml": "^3.0.0",
"symplify/rule-doc-generator-contracts": "^11.2",
"webmozart/assert": "^1.11"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"a9f\\FractorXliff\\": [
"src/",
"rules/"
]
}
},
"autoload-dev": {
"psr-4": {
"a9f\\FractorXliff\\Tests\\": [
"tests/",
"rules-tests/"
]
}
},
"config": {
"allow-plugins": {
"a9f/fractor-extension-installer": true
},
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-main": "0.5-dev"
}
}
}
38 changes: 38 additions & 0 deletions packages/fractor-xliff/config/application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

use a9f\Fractor\ValueObject\Indent;
use a9f\FractorXliff\Contract\XliffFractorRule;
use a9f\FractorXliff\IndentFactory;
use a9f\FractorXliff\ValueObject\XliffFormatConfiguration;
use a9f\FractorXliff\XliffFileProcessor;
use PrettyXml\Formatter;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
use function Symfony\Component\DependencyInjection\Loader\Configurator\tagged_iterator;

return static function (ContainerConfigurator $containerConfigurator, ContainerBuilder $containerBuilder): void {
$services = $containerConfigurator->services();
$services->defaults()
->autowire()
->autoconfigure();

$services->load('a9f\\FractorXliff\\', __DIR__ . '/../src/');

$services->set('fractor.xliff_processor.indent', Indent::class)
->factory([service(IndentFactory::class), 'create']);

$services->set('fractor.xliff_processor.format_configuration', XliffFormatConfiguration::class)
->factory([null, 'createFromParameterBag']);

$services->set(XliffFileProcessor::class)
->arg('$indent', service('fractor.xliff_processor.indent'))
->arg('$rules', tagged_iterator('fractor.xliff_rule'))
->arg('$xliffFormatConfiguration', service('fractor.xliff_processor.format_configuration'));

$services->set(Formatter::class);

$containerBuilder->registerForAutoconfiguration(XliffFractorRule::class)->addTag('fractor.xliff_rule');
};
75 changes: 75 additions & 0 deletions packages/fractor-xliff/docs/xliff-fractor-rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 3 Rules Overview

## ConvertXliff1To2Fractor

Convert XLIFF 1.2 files to XLIFF 2.0 format

- class: [`a9f\FractorXliff\ConvertXliff1To2Fractor`](../rules/ConvertXliff1To2Fractor.php)

```diff
<?xml version="1.0" encoding="UTF-8"?>
-<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
- <file source-language="en" datatype="plaintext" original="messages">
- <header/>
- <body>
- <trans-unit id="label.hello">
+<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="en">
+ <file id="messages">
+ <unit id="label.hello">
+ <segment>
<source>Hello</source>
- </trans-unit>
- </body>
+ </segment>
+ </unit>
</file>
</xliff>
```

<br>

## EnsureXliffHasSourceLanguageFractor

Ensure XLIFF files have the required source-language (v1.x) or srcLang (v2.0) attribute

- class: [`a9f\FractorXliff\EnsureXliffHasSourceLanguageFractor`](../rules/EnsureXliffHasSourceLanguageFractor.php)

```diff
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
- <file datatype="plaintext" original="messages">
+ <file source-language="en" datatype="plaintext" original="messages">
<body>
<trans-unit id="label.hello">
<source>Hello</source>
</trans-unit>
</body>
</file>
</xliff>
```

<br>

## EnsureXliffHasTargetLanguageFractor

Add target-language attribute to localized XLIFF files where the filename starts with a 2-letter ISO language code

- class: [`a9f\FractorXliff\EnsureXliffHasTargetLanguageFractor`](../rules/EnsureXliffHasTargetLanguageFractor.php)

```diff
<!-- de.locallang.xlf -->
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
- <file source-language="en" datatype="plaintext" original="messages">
+ <file source-language="en" target-language="de" datatype="plaintext" original="messages">
<body>
<trans-unit id="label.hello">
<source>Hello</source>
<target>Hallo</target>
</trans-unit>
</body>
</file>
</xliff>
```

<br>
13 changes: 13 additions & 0 deletions packages/fractor-xliff/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="fractor-xliff">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>./src</directory>
</include>
</source>
</phpunit>
Loading
Loading