Skip to content

Commit 97029c1

Browse files
committed
TMP
1 parent 19f170d commit 97029c1

File tree

2 files changed

+71
-11
lines changed

2 files changed

+71
-11
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace App\AutomatedTranslation;
4+
5+
use Ibexa\AutomatedTranslation\Exception\ClientNotConfiguredException;
6+
use Ibexa\Contracts\AutomatedTranslation\Client\ClientInterface;
7+
8+
final class CustomClient implements ClientInterface
9+
{
10+
private string $apiKey;
11+
12+
private const SUPPORTED_LANGUAGES = ['en', 'de', 'fr'];
13+
14+
public function setConfiguration(array $configuration): void
15+
{
16+
if (!isset($configuration['apiKey'])) {
17+
throw new ClientNotConfiguredException('apiKey is required');
18+
}
19+
$this->apiKey = $configuration['apiKey'];
20+
}
21+
22+
public function translate(string $payload, ?string $from, string $to): string
23+
{
24+
// call your custom translation logic here
25+
return str_replace('foo', 'bar', $payload);
26+
}
27+
28+
public function supportsLanguage(string $languageCode): bool
29+
{
30+
return in_array(substr($languageCode, 0, 2), self::SUPPORTED_LANGUAGES, true);
31+
}
32+
33+
public function getServiceAlias(): string
34+
{
35+
return 'custom';
36+
}
37+
38+
public function getServiceFullName(): string
39+
{
40+
return 'Custom Automated Translation';
41+
}
42+
}

docs/multisite/languages/automated_translations.md

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ description: With the automated translation add-on, users can translate content
66

77
The automated translation add-on package allows users have content items machine-translated into multiple languages by using either Google Translate or DeepL external translation engine.
88
The package integrates with [[= product_name =]], and allows users to [request from the UI]([[= user_doc =]]/content_management/translate_content.md#add-translations) that a content item is translated.
9-
However, you can also run an API command to translate a specific content item.
10-
Either way, as a result, a new version of the content item is created, with the following elements translated into a target language:
9+
However, you can also run an Console Command to translate a specific content item.
10+
Either way, as a result, a new version of the content item is created.
1111

12+
The following field types are supported out of the box:
1213

13-
- for pages: blocks that have the `text` or `richtext` [block attributes](../../content_management/pages/page_block_attributes/#block-attribute-types)
14-
- for other content types: Fields of the [TextLine](../../content_management/field_types/field_type_reference//textlinefield.md) and [RichText](../../content_management/field_types/field_type_reference//richtextfield.md) type
14+
- [TextLine](textlinefield.md)
15+
- [TextBlock](textblockfield.md)
16+
- [RichText](richtextfield.md)
17+
- [Page](pagefield.md):
18+
- The content of `text` and `richtext` [block attributes](page_block_attributes.md#block-attribute-types)
19+
20+
See [adding a custom field encoder](##add-a-custom-field-encoder) for more information on how to expand this.
1521

1622
!!! note "DeepL limitations"
1723

@@ -30,7 +36,7 @@ composer require ibexa/automated-translation
3036
!!! caution "Modify the default configuration"
3137

3238
Symfony Flex installs and activates the package.
33-
However, you must modify the `config/bundles.php` file to change the template loading order:
39+
However, you must modify the `config/bundles.php` file to change the bundle loading order so that`IbexaAutomatedTranslationBundle` is before `IbexaAdminUiBundle`:
3440

3541
```php
3642
<?php
@@ -62,9 +68,7 @@ ibexa_automated_translation:
6268
authKey: "deepl-pro-key"
6369
```
6470
65-
!!! note
66-
67-
The configuration is SiteAccess-aware, therefore, you can configure different engines to be used for different sites.
71+
The configuration is SiteAccess-aware, therefore, you can configure different engines to be used for different sites.
6872
6973
## Translate content items with CLI
7074
@@ -81,6 +85,20 @@ You would do it, for example, when a new service emerges on the market, or your
8185

8286
To add a custom engine to a list of available translation services, do the following:
8387

84-
1. Create a service that implements ` Ibexa\AutomatedTranslation\Client\ClientInterface`
85-
1. Implement the `translate` method
86-
1. In `services.yaml` file, tag the service as `ibexa.automated_translation.client`
88+
1. Create a service that implements the [`\Ibexa\AutomatedTranslation\Client\ClientInterface`](REFERENCE LINK) interface
89+
1. In `services.yaml` file, tag the service as `ibexa.automated_translation.client`
90+
91+
See the example below:
92+
93+
<example here>
94+
95+
The whole automated translation process consists of 3 phases:
96+
1. Encoding - the raw data stored in the fieldtype is processed so that it can be translated by the automated translation service. Google and Deepl can h
97+
1. Translating - the data is translated using an Automated Translatin client.
98+
1. Decoding - the translated data is decoded back to the original structure so that it can be stored back in [= product_name =]]
99+
100+
## Add a custom field or block encoder
101+
102+
103+
104+

0 commit comments

Comments
 (0)