Skip to content

Commit 8ac3781

Browse files
committed
Merge branch 'beta'
2 parents 9b0c090 + 47cea9d commit 8ac3781

18 files changed

+181
-80
lines changed

CHANGELOG.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
# Release Notes for Altify
22

3-
# [1.0.0-beta.3] (2024-04-25)
3+
# [1.0.0-beta.4] (2024-04-26)
4+
5+
### Features
6+
7+
* Added the possibility to register own generators and translators via events
48

59
### Changes
610

7-
* Refactored the connector settings for simplicity and future extensibility
11+
* Refactored Settings and Services a bit for easier integration of the registration events
812

9-
# [1.0.0-beta.2] (2024-04-24)
13+
# [1.0.0-beta.3] (2024-04-25)
1014

1115
### Changes
1216

13-
* The plugin is called Altify from now on
17+
* Refactored the connector settings for simplicity and future extensibility
18+
19+
# [1.0.0-beta.2] (2024-04-24)
1420

1521
### Features
1622

1723
* Add translation services DeepL, Opus MT and Flan T5 small
1824

25+
### Changes
26+
27+
* The plugin is called Altify from now on
28+
1929
# [1.0.0-beta.1] (2024-02-23)
2030

2131
### Features

README.md

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ cd /path/to/my-project.test
3535
composer require fork/craft-altify
3636

3737
# tell Craft to install the plugin
38-
./craft plugin/install alt
38+
./craft plugin/install altify
3939
```
4040

4141
## Usage
@@ -53,22 +53,18 @@ You can also set the model via ENV variable. This can be a class name, or one of
5353
<tr>
5454
<th>Model name</th>
5555
<th>Link</th>
56-
<th>Config name</th>
5756
</tr>
5857
<tr>
5958
<td>BLIP (large)</td>
6059
<td><a>https://huggingface.co/Salesforce/blip-image-captioning-large</a></td>
61-
<td>BLIP large model (Hugging Face)</td>
6260
</tr>
6361
<tr>
6462
<td>BLIP (base)</td>
6563
<td><a>https://huggingface.co/Salesforce/blip-image-captioning-base</a></td>
66-
<td>BLIP base model (Hugging Face)</td>
6764
</tr>
6865
<tr>
6966
<td>...</td>
7067
<td>...</td>
71-
<td>...</td>
7268
</tr>
7369
</table>
7470

@@ -78,37 +74,59 @@ You can also set the model via ENV variable. This can be a class name, or one of
7874
<tr>
7975
<th>Model name</th>
8076
<th>Link</th>
81-
<th>Config name</th>
8277
</tr>
8378
<tr>
84-
<td>DeepL</td>
79+
<td>DeepL API</td>
8580
<td><a>https://developers.deepl.com/docs</a></td>
86-
<td>DeepL</td>
8781
</tr>
8882
<tr>
8983
<td>OPUS MT (EN → DE)</td>
9084
<td><a>https://huggingface.co/Helsinki-NLP/opus-mt-en-de</a></td>
91-
<td>OPUS MT En -> De</td>
9285
</tr>
9386
<tr>
9487
<td>Google T5 small (EN → DE)</td>
9588
<td><a>https://huggingface.co/google-t5/t5-small</a></td>
96-
<td>T5 small En -> De</td>
9789
</tr>
9890
<tr>
9991
<td>...</td>
10092
<td>...</td>
101-
<td>...</td>
10293
</tr>
10394
</table>
10495

105-
### Implementing own alt text generator services
96+
### Implementing own alt text generators and translators
10697

10798
You can implement your own alt text generator service by implementing the interface
108-
`fork\alt\connectors\alttextgeneration\AltTextGeneratorInterface` and configuring this plugin to use it
109-
by setting your own generator's class name via ENV variable.
99+
`fork\alt\connectors\alttextgeneration\AltTextGeneratorInterface` and registering it via the `EVENT_REGISTER_GENERATORS`
100+
event like this:
101+
102+
```
103+
use fork\altify\events\RegisterGeneratorsEvent;
104+
use fork\altify\services\Generator;
105+
106+
Event::on(
107+
Generator::class,
108+
Generator::EVENT_REGISTER_GENERATORS,
109+
function (RegisterGeneratorsEvent $event) {
110+
$event->generators['myGenerator'] = MyGenerator::class;
111+
}
112+
);
113+
```
114+
115+
The same goes for translator services. Implement `fork\altify\connectors\translation\TranslatorInterface` and register
116+
your translator like this:
110117

111-
In a future release it should be possible to register alt text generators with an event.
118+
```
119+
use fork\altify\events\RegisterTranslatorsEvent;
120+
use fork\altify\services\Translator;
121+
122+
Event::on(
123+
Translator::class,
124+
Translator::EVENT_REGISTER_TRANSLATORS,
125+
function (RegisterTranslatorsEvent $event) {
126+
$event->translators['myTranslator'] = MyTranslator::class;
127+
}
128+
);
129+
```
112130

113131
---
114132

@@ -117,7 +135,7 @@ In a future release it should be possible to register alt text generators with a
117135
* Make translation services site based to respect languages
118136
* Implement more alt text generation services
119137
* Maybe implement a self-hosted alt text generation service
120-
* Maybe implement an alt text generation service running in browser with TensorFlow JS
138+
* Maybe implement an alt text generation service running in browser with TensorFlow JS or something similar
121139
* Implement an alt text generator registering event
122140
* Make public on GitHub, release on Packagist and the Craft Plugin Store
123141

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"extra": {
2828
"handle": "altify",
29-
"name": "altify",
29+
"name": "Altify",
3030
"developer": "Fork",
3131
"documentationUrl": "https://github.com/fork/craft-altify"
3232
},

src/Plugin.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
use fork\altify\elements\actions\TranslateAltText as TranslateAltTextAction;
1717
use fork\altify\jobs\GenerateAltText as GenerateAltTextJob;
1818
use fork\altify\models\Settings;
19-
use fork\altify\services\AltTextGeneration;
20-
use fork\altify\services\Translation;
19+
use fork\altify\services\Generator;
20+
use fork\altify\services\Translator;
2121
use Twig\Error\LoaderError;
2222
use Twig\Error\RuntimeError;
2323
use Twig\Error\SyntaxError;
@@ -32,9 +32,9 @@
3232
* @author Fork <obj@fork.de>
3333
* @copyright Fork
3434
* @license MIT
35-
* @property-read AltTextGeneration $altTextGeneration
35+
* @property-read Generator $generator
3636
* @property-read Settings $settings
37-
* @property-read Translation $translation
37+
* @property-read Translator $translator
3838
*/
3939
class Plugin extends BasePlugin
4040
{
@@ -46,8 +46,8 @@ public static function config(): array
4646
{
4747
return [
4848
'components' => [
49-
'altTextGeneration' => AltTextGeneration::class,
50-
'translation' => Translation::class
49+
'generator' => Generator::class,
50+
'translator' => Translator::class
5151
],
5252
];
5353
}

src/connectors/translation/DeeplTranslator.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,4 @@ public function translateAltTextForImage(Asset $image): ?string
3939

4040
return $altText;
4141
}
42-
4342
}

src/controllers/GenerateAltTextController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function actionIndex(): Response
3232
$assetId = Craft::$app->request->getBodyParam('assetId');
3333

3434
try {
35-
Plugin::getInstance()->altTextGeneration->generateAltTextForImage($assetId);
35+
Plugin::getInstance()->generator->generateAltTextForImage($assetId);
3636
} catch (Exception|Throwable $e) {
3737
Craft::$app->getSession()->setError($e->getMessage());
3838
}

src/controllers/TranslateAltTextController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function actionIndex(): Response
3232
$assetId = Craft::$app->request->getBodyParam('assetId');
3333

3434
try {
35-
Plugin::getInstance()->translation->translateAltTextForImage($assetId);
35+
Plugin::getInstance()->translator->translateAltTextForImage($assetId);
3636
} catch (Exception|Throwable $e) {
3737
Craft::$app->getSession()->setError($e->getMessage());
3838
}

src/elements/actions/GenerateAltText.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function performAction(Craft\elements\db\ElementQueryInterface $query): b
5858
$elements = $query->all();
5959
foreach ($elements as $element) {
6060
try {
61-
Plugin::getInstance()->altTextGeneration->generateAltTextForImage($element->id);
61+
Plugin::getInstance()->generator->generateAltTextForImage($element->id);
6262
} catch (Exception|Throwable $e) {
6363
Craft::$app->getSession()->setError($e->getMessage());
6464
}

src/elements/actions/TranslateAltText.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function performAction(Craft\elements\db\ElementQueryInterface $query): b
5858
$elements = $query->all();
5959
foreach ($elements as $element) {
6060
try {
61-
Plugin::getInstance()->translation->translateAltTextForImage($element->id);
61+
Plugin::getInstance()->translator->translateAltTextForImage($element->id);
6262
} catch (Exception|Throwable $e) {
6363
Craft::$app->getSession()->setError($e->getMessage());
6464
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace fork\altify\events;
4+
5+
use yii\base\Event;
6+
7+
class RegisterGeneratorsEvent extends Event
8+
{
9+
public array $generators = [];
10+
}

0 commit comments

Comments
 (0)