Skip to content

Commit

Permalink
add full coverage options
Browse files Browse the repository at this point in the history
  • Loading branch information
boxblinkracer committed Jan 16, 2024
1 parent 943e823 commit 6415b50
Show file tree
Hide file tree
Showing 49 changed files with 1,263 additions and 410 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.

- Add new **validate:mess** command to find keys without any translation. This means that these translations might not be used at all and can be removed.
- Add new **fix:mess** command to remove keys without any translation. This means that these translations might not be used at all and can be removed.
- Add new options to validate **minimum coverage percentage** for validate:all command. If provided the coverage needs to be at least the provided percentage to pass the validation (see README for more).
- Add new configurations for a minimum coverage. These can be set for a TranslationSet, or all sets or across all locales. (see README for more).
- It's now possible to use the **%locale%** placeholder also in the **basePath** attribute of the locales node in the XML configuration.

### Changed
Expand Down
119 changes: 92 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ Now that you know this, let's get started!
* [4. Commands](#4-commands)
* [4.1 Validate All Command](#41-validate-all-command)
* [4.2 Validate Mess Command](#42-validate-mess-command)
* [4.3 Fix Structure Command](#43-fix-structure-command)
* [4.4 Fix Mess Command](#44-fix-mess-command)
* [4.5 Export Command](#45-export-command)
* [4.6 Import Command](#46-import-command)
* [4.7 Status Command](#47-status-command)
* [4.8 Translate Command](#48-translate-command)
* [4.9 List Translations Command](#49-list-translations-command)
* [4.10 Migration Command](#410-migration-command)
* [4.3 Validate Coverage](#43-validate-coverage)
* [4.4 Fix Structure Command](#44-fix-structure-command)
* [4.5 Fix Mess Command](#45-fix-mess-command)
* [4.6 Export Command](#46-export-command)
* [4.7 Import Command](#47-import-command)
* [4.8 Status Command](#48-status-command)
* [4.9 Translate Command](#49-translate-command)
* [4.10 List Translations Command](#410-list-translations-command)
* [4.11 Migration Command](#411-migration-command)
* [5. Use Cases](#5-use-cases)
* [5.1 Validation in CI pipeline](#51-validation-in-ci-pipeline)
* [5.2 Working with external translation agencies](#52-working-with-external-translation-agencies)
Expand Down Expand Up @@ -200,7 +201,7 @@ Look at this one:
>
<translations>

<set name="Storefront JSON" minCoverage="80">
<set name="Storefront JSON">
<format>
<json indent="4" sort="true"/>
</format>
Expand All @@ -210,7 +211,7 @@ Look at this one:
</locales>
</set>

<set name="Products" minCoverage="50">
<set name="Products">
<format>
<shopware6 entity="product"/>
</format>
Expand Down Expand Up @@ -252,8 +253,8 @@ php vendor/bin/phpunuhi validate:all --configuration=./translations.xml
# generate a junit report in a custom folder
php vendor/bin/phpunuhi validate:all --report-format=junit --report-output=.reports/junit.xml

# validate with minimum total coverage
php vendor/bin/phpunuhi validate:all --min-coverage=80
# ignore a configured coverage and use strict checks again
php vendor/bin/phpunuhi validate:all --ignore-coverage
```

**Invalid structure**
Expand Down Expand Up @@ -284,12 +285,6 @@ if all your translation keys, match your provided case styles.
If you have provided a rule for nestingDepth, then the validator will also verify the nesting level
on storages that support nesting (JSON, PHP, ...)

**Minimum Locale Coverage**

If you provide either the CLI option "--min-coverage" or the attribute "minCoverage" in your configuration,
then the validation will fail if the coverage is below the provided value.
Please note that all provided coverage percentage values are tested against the coverage result of each translation set.

### 4.2 Validate Mess Command

What is a mess? This is simply defined by translation keys that have no value in any of your locales.
Expand All @@ -307,7 +302,44 @@ php vendor/bin/phpunuhi validate:mess --configuration=./translations.xml
php vendor/bin/phpunuhi validate:mess --report-format=junit --report-output=.reports/junit.xml
```

### 4.3 Fix Structure Command
### 4.3 Validate Coverage

You can also validate the coverage of your translations.
This considers your configuration and only run the coverage tests.

Start by configuring your coverage in your XML either for all translation sets
or each translation set.

```xml

<coverage minCoverage="20">
</coverage>
```

```xml

<coverage>
<locale name="de">100</locale>
<locale name="en">80</locale>
</coverage>
```

These **coverage nodes can either be used on root level inside `<phpunuhi>` or
within each `<set>` node.

```bash
php vendor/bin/phpunuhi validate:coverage

# provide custom configuration
php vendor/bin/phpunuhi validate:coverage --configuration=./translations.xml
```

> Attention, once a coverage has been configured, the validation:all command will not
> work as strict as before. Strict errors will only be warnings, and only the coverage
> result is considered for the CLI exit code.
> However, you can provide a separate option to force strict validation again.
### 4.4 Fix Structure Command

If your storage is not matching, you can easily use the fixing command to make sure they are in sync.
Please note, that this will only create empty translations so that the structure is the same.
Expand All @@ -326,7 +358,7 @@ php vendor/bin/phpunuhi fix:structure --set="storefront"
<img src="/.github/assets/fix.png">
</p>

### 4.4 Fix Mess Command
### 4.5 Fix Mess Command

This command will automatically remove all translation keys that have no value in any of your locales.
Keys detected by the **validate:mess** command might not be used after all.
Expand All @@ -340,7 +372,7 @@ php vendor/bin/phpunuhi fix:mess
php vendor/bin/phpunuhi fix:mess --set="storefront"
```

### 4.5 Export Command
### 4.6 Export Command

You can export your translations **into a CSV file**, a HTML WebEdit spreadsheet, or other supported exchange formats.
These files can then be passed on to an external translator or company.
Expand Down Expand Up @@ -371,7 +403,7 @@ php vendor/bin/phpunuhi export ... --empty
<img src="/.github/assets/csv.png">
</p>

### 4.6 Import Command
### 4.7 Import Command

You can import your translations **from a CSV file** or other supported exchange formats.
This will automatically update the storage (JSON, ...) that has been assigned to the imported translation set.
Expand All @@ -386,7 +418,7 @@ php vendor/bin/phpunuhi import --set=storefront --file=storefront.csv
php vendor/bin/phpunuhi import ... --format=html
```

### 4.7 Status Command
### 4.8 Status Command

Use this command to get statistics and reports of your translations.
This includes the coverage and the number of found words.
Expand All @@ -399,7 +431,7 @@ php vendor/bin/phpunuhi status
<img src="/.github/assets/status.png">
</p>

### 4.8 Translate Command
### 4.9 Translate Command

PHPUnuhi includes the option to use external services to automatically translate missing values for you.

Expand Down Expand Up @@ -436,7 +468,7 @@ php vendor/bin/phpunuhi translate ... --source=en
<img src="/.github/assets/translate.png">
</p>

### 4.9 List Translations Command
### 4.10 List Translations Command

This command allows you to output all available translation keys in your Translation-Sets.
Use this to debug and analyse your translations.
Expand All @@ -445,7 +477,7 @@ Use this to debug and analyse your translations.
php vendor/bin/phpunuhi list:translations
```

### 4.10 Migration Command
### 4.11 Migration Command

It's also possible to migrate your translations from one storage to another.
Just use the migration command and provide the target storage as output format.
Expand Down Expand Up @@ -1119,4 +1151,37 @@ This is perfect if you have brand names or just any word that should not be acci
<term>iPhone</term>
</protect>
</set>
```
```

7.13 Coverage

You can also configure the coverage of your translations.

This means you can either define that all your locales in a single TranslationSet require a specific
coverage separately or in total, or you can even define that all your
locales across all translation sets require a specific coverage in a specific locale or in total.

Start by configuring your coverage in your XML either for all translation sets
or each translation set.

```xml

<coverage minCoverage="20">
</coverage>
```

```xml

<coverage>
<locale name="de">100</locale>
<locale name="en">80</locale>
</coverage>
```

These **coverage nodes can either be used on root level inside `<phpunuhi>` or
within each `<set>` node.

> Attention, once a coverage has been configured, the validation:all command will not
> work as strict as before. Strict errors will only be warnings, and only the coverage
> result is considered for the CLI exit code.
> However, you can provide a separate option to force strict validation again.
20 changes: 19 additions & 1 deletion config.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<xs:element name="imports" type="typeImports" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="php" type="typePHP" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="translations" type="typeTranslations" minOccurs="1" maxOccurs="unbounded"/>
<xs:element name="coverage" type="typeCoverage" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>

Expand Down Expand Up @@ -70,9 +71,9 @@
<xs:element name="rules" type="typeRules" minOccurs="0" maxOccurs="1"/>
<xs:element name="styles" type="typeStyle" minOccurs="0" maxOccurs="1"/>
<xs:element name="locales" type="typeLocales" minOccurs="1" maxOccurs="1"/>
<xs:element name="coverage" type="typeCoverage" minOccurs="0" maxOccurs="1"/>
</xs:choice>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="minCoverage" type="xs:integer" use="optional"/>
</xs:complexType>

<!-- ================================================================================================================================ -->
Expand Down Expand Up @@ -106,6 +107,23 @@
</xs:choice>
</xs:complexType>

<!-- ================================================================================================================================ -->
<!-- COVERAGE -->
<xs:complexType name="typeCoverage">
<xs:sequence>
<xs:element name="locale" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="minCoverage" type="xs:integer" use="optional"/>
</xs:complexType>

<!-- ================================================================================================================================ -->
<!-- RULES -->

Expand Down
40 changes: 21 additions & 19 deletions src/AppManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,48 @@
namespace PHPUnuhi;

use Exception;
use PHPUnuhi\Commands\Core\FixMessCommand;
use PHPUnuhi\Commands\Core\FixStructureCommand;
use PHPUnuhi\Commands\Core\ListTranslationsCommand;
use PHPUnuhi\Commands\Core\MigrateCommand;
use PHPUnuhi\Commands\Core\StatusCommand;
use PHPUnuhi\Commands\Core\ValidateCommand;
use PHPUnuhi\Commands\Exchange\ExportCommand;
use PHPUnuhi\Commands\Exchange\ImportCommand;
use PHPUnuhi\Commands\Translation\TranslateCommand;
use PHPUnuhi\Commands\Validation\ValidateAllCommand;
use PHPUnuhi\Commands\Validation\ValidateMessCommand;
use PHPUnuhi\Commands\ExportCommand;
use PHPUnuhi\Commands\FixMessCommand;
use PHPUnuhi\Commands\FixStructureCommand;
use PHPUnuhi\Commands\ImportCommand;
use PHPUnuhi\Commands\ListTranslationsCommand;
use PHPUnuhi\Commands\MigrateCommand;
use PHPUnuhi\Commands\StatusCommand;
use PHPUnuhi\Commands\TranslateCommand;
use PHPUnuhi\Commands\ValidateAllCommand;
use PHPUnuhi\Commands\ValidateCommand;
use PHPUnuhi\Commands\ValidateCoverageCommand;
use PHPUnuhi\Commands\ValidateMessCommand;
use Symfony\Component\Console\Application;

class AppManager
{

/**
* @param array<mixed> $arguments
* @throws Exception
* @return void
*/
public static function run(array $arguments): void
public static function run(): void
{
$application = new Application('PHPUnuhi', PHPUnuhi::getVersion());

$application->add(new StatusCommand());
$application->add(new ValidateCommand());
$application->add(new ExportCommand());
$application->add(new ImportCommand());
$application->add(new TranslateCommand());
$application->add(new ListTranslationsCommand());
$application->add(new MigrateCommand());

$application->add(new ValidateCommand());
$application->add(new ValidateAllCommand());
$application->add(new ValidateMessCommand());
$application->add(new ValidateCoverageCommand());

$application->add(new ImportCommand());
$application->add(new ExportCommand());

$application->add(new TranslateCommand());

$application->add(new MigrateCommand());
$application->add(new FixStructureCommand());
$application->add(new FixMessCommand());


$application->setDefaultCommand('list');

$application->run();
Expand Down
13 changes: 13 additions & 0 deletions src/Commands/CommandNames.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace PHPUnuhi\Commands;

interface CommandNames
{
public const STATUS = 'status';

public const VALIDATE = 'validate';
public const VALIDATE_ALL = 'validate:all';
public const VALIDATE_COVERAGE = 'validate:coverage';
public const VALIDATE_MESSAGES = 'validate:mess';
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PHPUnuhi\Commands\Exchange;
namespace PHPUnuhi\Commands;

use PHPUnuhi\Bundles\Exchange\ExchangeFactory;
use PHPUnuhi\Bundles\Exchange\ExchangeFormat;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PHPUnuhi\Commands\Core;
namespace PHPUnuhi\Commands;

use PHPUnuhi\Bundles\Storage\StorageFactory;
use PHPUnuhi\Configuration\ConfigurationLoader;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PHPUnuhi\Commands\Core;
namespace PHPUnuhi\Commands;

use PHPUnuhi\Bundles\Storage\StorageFactory;
use PHPUnuhi\Configuration\ConfigurationLoader;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PHPUnuhi\Commands\Core;
namespace PHPUnuhi\Commands;

use PHPUnuhi\Bundles\Storage\StorageFactory;
use PHPUnuhi\Configuration\ConfigurationLoader;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PHPUnuhi\Commands\Exchange;
namespace PHPUnuhi\Commands;

use Exception;
use PHPUnuhi\Bundles\Exchange\ExchangeFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PHPUnuhi\Commands\Core;
namespace PHPUnuhi\Commands;

use PHPUnuhi\Configuration\ConfigurationLoader;
use PHPUnuhi\Exceptions\ConfigurationException;
Expand Down
Loading

0 comments on commit 6415b50

Please sign in to comment.