Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Shopware 6 Config storage #60

Merged
merged 1 commit into from
Nov 11, 2024
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
/tests/playground/yaml/.exports
/tests/playground/po/.exports
/tests/playground/php/.exports
/tests/playground/shopware6-config/.exports
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
### Added

- Add new **SpellCheckers** with support for Aspell and OpenAI. This allows to check misspelled words and automatically fix them.
- Add new **Shopware 6** Storage option to support **config XML** files of Shopware plugins and apps. You can now validate config.xml, manifest.xml and more.
- Add new **usage summary** when using Open AI. It shows the number of requests as well as the estimated costs. (approximate values, not guaranteed).
- Add new **similarity validation** for translations. This allows to validate if translation keys are similar to each other.
- Add new command **list:translation-keys**. The old list:translations command will now show all translations and the new one will show the keys only.
- Allow DeepL / translator configuration with env variables (thx @Ocarthon)
- Enable DeepL tag splitting on HTML input to also translate HTML fragments (thx @Ocarthon)
- Support referencing Shopware snippets by their snippet set name (thx @Ocarthon)
Expand All @@ -29,6 +31,7 @@ using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
- Check all locales to determine the translation keys. Sometimes this did not happen and therefore not all keys have been detected (thx @Ocarthon)
- Fix problem with translate command and force flag (thx @Ocarthon)
- Fix problem where the error CLI output also showed successful test results and not just errors.
- Fix problem with googleweb translator where a "." was not correctly kept after translation into a German word.

## [1.21.0]

Expand Down
190 changes: 123 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ Please keep that in mind to avoids misinterpreting the goal of this framework.
Now that you know this, let's get started!

<!-- TOC -->

* [1. Basic Concept](#1-basic-concept)
* [2. Installation](#2-installation)
* [3. Configuration](#3-configuration)
* [4. Commands](#4-commands)
* [1. Basic Concept](#1-basic-concept)
* [2. Installation](#2-installation)
* [3. Configuration](#3-configuration)
* [4. Commands](#4-commands)
* [4.1 Validate All Command](#41-validate-all-command)
* [4.2 Validate Mess Command](#42-validate-mess-command)
* [4.3 Validate Coverage Command](#43-validate-coverage-command)
Expand All @@ -47,63 +46,65 @@ Now that you know this, let's get started!
* [4.11 Status Command](#411-status-command)
* [4.12 Fix Spelling Command](#412-fix-spelling-command)
* [4.13 Translate Command](#413-translate-command)
* [4.14 List Translations Command](#414-list-translations-command)
* [4.15 Migration Command](#415-migration-command)
* [4.16 Scan Usage Command](#416-scan-usage-command)
* [5. Validation Processes](#5-validation-processes)
* [4.14 List Translation Keys Command](#414-list-translation-keys-command)
* [4.15 List Translations Command](#415-list-translations-command)
* [4.16 Migration Command](#416-migration-command)
* [4.17 Scan Usage Command](#417-scan-usage-command)
* [5. Validation Processes](#5-validation-processes)
* [5.1 Structure Validation](#51-structure-validation)
* [5.2 Empty content Validation](#52-empty-content-validation)
* [5.3 Case-Style Validation](#53-case-style-validation)
* [5.4 Rules Validation](#54-rules-validation)
* [6. Use Cases](#6-use-cases)
* [6. Use Cases](#6-use-cases)
* [6.1 Validation in CI pipeline](#61-validation-in-ci-pipeline)
* [6.2 Working with external translation agencies](#62-working-with-external-translation-agencies)
* [6.3 Live WebEdit with HTML](#63-live-webedit-with-html)
* [6.4 Automatic Translation with Google, DeepL, ...](#64-automatic-translation-with-google-deepl-)
* [7. Warning](#7-warning)
* [8. Appendix](#8-appendix)
* [8.1 Imports](#81-imports)
* [8.2 Locales](#82-locales)
* [7. Warning](#7-warning)
* [8. Appendix](#8-appendix)
* [8.1 Imports](#81-imports)
* [8.2 Locales](#82-locales)
* [8.3 Storage Formats](#83-storage-formats)
* [8.3.1 Formats](#831-formats)
* [8.3.1.1 JSON](#8311-json)
* [8.3.1.2 INI](#8312-ini)
* [8.3.1.3 PO](#8313-po)
* [8.3.1.4 PHP](#8314-php)
* [8.3.1.5 Shopware 6](#8315-shopware-6)
* [8.3.1.6 YAML](#8316-yaml)
* [8.3.2 Custom Formats](#832-custom-formats)
* [8.3.1 Formats](#831-formats)
* [8.3.1.1 JSON](#8311-json)
* [8.3.1.2 INI](#8312-ini)
* [8.3.1.3 PO](#8313-po)
* [8.3.1.4 PHP](#8314-php)
* [8.3.1.5 YAML](#8315-yaml)
* [8.3.1.6 Shopware 6](#8316-shopware-6)
* [Entities](#entities)
* [Configs](#configs)
* [8.3.2 Custom Formats](#832-custom-formats)
* [8.4 Filters](#84-filters)
* [8.5 Groups](#85-groups)
* [8.6 Case Styles](#86-case-styles)
* [8.7 Rules](#87-rules)
* [8.8.1 Nesting Depth](#881-nesting-depth)
* [8.8.2 Key Length](#882-key-length)
* [8.8.3 Disallowed Texts](#883-disallowed-texts)
* [8.8.4 Duplicate Content](#884-duplicate-content)
* [8.8.5 Empty Content](#885-empty-content)
* [8.8.1 Nesting Depth](#881-nesting-depth)
* [8.8.2 Key Length](#882-key-length)
* [8.8.3 Disallowed Texts](#883-disallowed-texts)
* [8.8.4 Duplicate Content](#884-duplicate-content)
* [8.8.5 Empty Content](#885-empty-content)
* [8.8 PHP ENV Variables](#88-php-env-variables)
* [8.9 Exchange Formats](#89-exchange-formats)
* [8.9.1 CSV](#891-csv)
* [8.9.2 HTML / WebEdit](#892-html--webedit)
* [8.9.3 JSON](#893-json)
* [8.9.4 Custom Exchange Formats](#894-custom-exchange-formats)
* [8.9.1 CSV](#891-csv)
* [8.9.2 HTML / WebEdit](#892-html--webedit)
* [8.9.3 JSON](#893-json)
* [8.9.4 Custom Exchange Formats](#894-custom-exchange-formats)
* [8.10 Translator Services](#810-translator-services)
* [8.10.1 DeepL](#8101-deepl)
* [8.10.2 Google Cloud Translate](#8102-google-cloud-translate)
* [8.10.3 Google Web Translate](#8103-google-web-translate)
* [8.10.4 OpenAI GPT Translate](#8104-openai-gpt-translate)
* [8.10.5 Custom Translators](#8105-custom-translators)
* [8.10.1 DeepL](#8101-deepl)
* [8.10.2 Google Cloud Translate](#8102-google-cloud-translate)
* [8.10.3 Google Web Translate](#8103-google-web-translate)
* [8.10.4 OpenAI GPT Translate](#8104-openai-gpt-translate)
* [8.10.5 Custom Translators](#8105-custom-translators)
* [8.11 Validation Reports](#811-validation-reports)
* [8.11.1 JUnit Report](#8111-junit-report)
* [8.11.2 JSON Report](#8112-json-report)
* [8.11.1 JUnit Report](#8111-junit-report)
* [8.11.2 JSON Report](#8112-json-report)
* [8.12 Protection](#812-protection)
* [8.13 Coverage](#813-coverage)
* [8.14 Scanners](#814-scanners)
* [8.15 Spell Checkers](#815-spell-checkers)
* [8.15.1 Aspell](#8151-aspell)
* [8.15.2 OpenAI](#8152-openai)

* [8.15.1 Aspell](#8151-aspell)
* [8.15.2 OpenAI](#8152-openai)
<!-- TOC -->


Expand Down Expand Up @@ -501,16 +502,24 @@ php vendor/bin/phpunuhi translate ... --source=en
<img src="/.github/assets/translate.png">
</p>

### 4.14 List Translations Command
### 4.14 List Translation Keys Command

This command allows you to output all available translation keys in your Translation-Sets.
Use this to debug and analyse your translations.

```bash
php vendor/bin/phpunuhi list:translation-keys
```

### 4.15 List Translations Command

This command shows all found translations and their values in a small and compact format.

```bash
php vendor/bin/phpunuhi list:translations
```

### 4.15 Migration Command
### 4.16 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 All @@ -519,7 +528,7 @@ Just use the migration command and provide the target storage as output format.
php vendor/bin/phpunuhi migrate --output=json
```

### 4.16 Scan Usage Command
### 4.17 Scan Usage Command

Usually you have template files that use your translation keys.
The scanner command helps to scan all these files and see if all your translation keys are actually used in there.
Expand Down Expand Up @@ -812,15 +821,52 @@ This storage type makes sure to read and also write PHP files that return a sing
</set>
```

##### 8.3.1.5 Shopware 6
##### 8.3.1.5 YAML

| Format Attributes | Default | Description |
|-------------------|---------|----------------------------------------|
| entity | | The entity your Translation-Set covers |
| Format Attributes | Default | Description |
|-------------------|---------|-----------------------------------------|
| indent | 2 | Set a custom YAML indent for the spaces |
| sort | false | Turn on or off the alphabetical sorting |
| eol-last | false | Adds a new line at the end of the file |

The YAML format means that your files are stored in separate YAML files.
Every locale has its own YAML file.
The YAML structure across all files of a set should match.

```xml

<set name="sample">
<format>
<yaml indent="4" sort="true"/>
</format>
<locales>
<locale name="de">./snippets/de.yaml</locale>
<locale name="en">./snippets/en.yaml</locale>
</locales>
</set>
```

##### 8.3.1.6 Shopware 6

| Format Attributes | Default | Description |
|-------------------|---------|------------------------------------------------------------------------------------------------------------------------------|
| type | entity | Whether you want to check for entities against the database or configuration files such as config.xml, manifest.xml and more |
| entity | | The entity your Translation-Set covers |
| file | | In case of type "config", you have to define a filename like ./Resources/config.xml |

The Shopware 6 format allows you to use PHPUnuhi directly on the database and the Shopware entities.
But also validation on configuration files for Plugins and Apps like config.xml and manifest.xml are possible.

You can switch modes by using the **type** attribute.

The following types are possible:

What do we mean with entities? These are real objects of the platform, stored within the database.
* entity
* config

###### Entities

Entities are real objects of the platform, stored within the database.
This means **snippets**, **products**, **salutations**, **shipping methods** and more. Basically, everything that has a
**_translation** table in the database.

Expand Down Expand Up @@ -896,29 +942,39 @@ instead of an entity translation table.
</phpunuhi>
```

##### 8.3.1.6 YAML
###### Configs

| Format Attributes | Default | Description |
|-------------------|---------|-----------------------------------------|
| indent | 2 | Set a custom YAML indent for the spaces |
| sort | false | Turn on or off the alphabetical sorting |
| eol-last | false | Adds a new line at the end of the file |
Shopware Plugins and Apps can also have configuration files based on XML.
These files contain translations for the plugin itself, flow actions and way more.

The YAML format means that your files are stored in separate YAML files.
Every locale has its own YAML file.
The YAML structure across all files of a set should match.
You can now also use PHPUnuhi to validate and maintain these translations too.

Please provide the path to the configuration file in the **file** attribute and also make sure to set a **base** locale.
PHPUnuhi will then automatically detect if it is a config.xml, a manifest.xml or a different configuration type of Shopware.

The following configuration types are currently supported:

* config.xml
* manifest.xml
* flow-actions.xml and flow.xml

```xml

<set name="sample">
<format>
<yaml indent="4" sort="true"/>
</format>
<locales>
<locale name="de">./snippets/de.yaml</locale>
<locale name="en">./snippets/en.yaml</locale>
</locales>
</set>
<phpunuhi>
<translations>

<set name="config">
<format>
<shopware6 type="config" file="./Resources/config.xml"/>
</format>
<locales base="true">
<locale name="en-GB" base="true"></locale>
<locale name="nl-NL"></locale>
</locales>
</set>

</translations>
</phpunuhi>
```

#### 8.3.2 Custom Formats
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"orhanerday/open-ai": "^5.1",
"symfony/console": "*",
"symfony/dotenv": "*",
"symfony/yaml": "*"
"symfony/yaml": "*",
"ext-dom": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.18",
Expand Down
21 changes: 15 additions & 6 deletions config.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -290,24 +290,33 @@
</xs:simpleContent>
</xs:complexType>

<xs:complexType name="typeFormatShopware6">
<xs:complexType name="typeFormatYAML">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="entity" type="xs:string" use="required"/>
<xs:attribute name="indent" type="xs:string" use="optional"/>
<xs:attribute name="sort" type="xs:boolean" use="optional"/>
<xs:attribute name="eol-last" type="xs:boolean" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:complexType name="typeFormatYAML">
<xs:complexType name="typeFormatShopware6">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="indent" type="xs:string" use="optional"/>
<xs:attribute name="sort" type="xs:boolean" use="optional"/>
<xs:attribute name="eol-last" type="xs:boolean" use="optional"/>
<xs:attribute name="type" type="typeShopware6" use="required"/>
<xs:attribute name="file" type="xs:string" use="optional"/>
<xs:attribute name="entity" type="xs:string" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:simpleType name="typeShopware6">
<xs:restriction base="xs:token">
<xs:enumeration value="config"/>
<xs:enumeration value="entity"/>
</xs:restriction>
</xs:simpleType>

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

</xs:schema>
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# -------------------------------------------------------
PHP_MIN_VERSION := 7.2
PHPUNIT_MIN_COVERAGE := 43
PHPUNIT_MIN_COVERAGE := 38
# -------------------------------------------------------


Expand Down
2 changes: 2 additions & 0 deletions src/AppManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PHPUnuhi\Commands\FixSpellingCommand;
use PHPUnuhi\Commands\FixStructureCommand;
use PHPUnuhi\Commands\ImportCommand;
use PHPUnuhi\Commands\ListTranslationKeysCommand;
use PHPUnuhi\Commands\ListTranslationsCommand;
use PHPUnuhi\Commands\MigrateCommand;
use PHPUnuhi\Commands\ScanUsageCommand;
Expand All @@ -34,6 +35,7 @@ public static function run(): void
$application = new Application('PHPUnuhi', PHPUnuhi::getVersion());

$application->add(new StatusCommand());
$application->add(new ListTranslationKeysCommand());
$application->add(new ListTranslationsCommand());

$application->add(new ValidateCommand());
Expand Down
Loading
Loading