-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
54 lines (48 loc) · 1.94 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
use Composer\Semver\Semver;
use Kirby\Cms\App as Kirby;
use Kirby\Cms\File;
use Kirby\Cms\Page;
use Kirby\Cms\Site;
use Kirby\Filesystem\F;
F::loadClasses([
'JohannSchopplich\\ContentTranslator\\DeepL' => 'src/classes/ContentTranslator/DeepL.php',
'JohannSchopplich\\ContentTranslator\\Translator' => 'src/classes/ContentTranslator/Translator.php',
'JohannSchopplich\\ContentTranslator\\Licenses' => 'src/classes/ContentTranslator/Licenses.php'
], __DIR__);
// Validate Kirby version
if (!Semver::satisfies(Kirby::version() ?? '0.0.0', '~4.0')) {
throw new Exception('Kirby Content Translator requires Kirby 4');
}
Kirby::plugin('johannschopplich/content-translator', [
'api' => require __DIR__ . '/src/extensions/api.php',
'sections' => require __DIR__ . '/src/extensions/sections.php',
'translations' => require __DIR__ . '/src/extensions/translations.php',
'siteMethods' => [
'translator' => function (array $options = []) {
return new \JohannSchopplich\ContentTranslator\Translator($this, $options);
}
],
'pageMethods' => [
'translator' => function (array $options = []) {
return new \JohannSchopplich\ContentTranslator\Translator($this, $options);
}
],
'fileMethods' => [
'translator' => function (array $options = []) {
return new \JohannSchopplich\ContentTranslator\Translator($this, $options);
}
]
]);
if (!function_exists('translator')) {
function translator(Site|Page|File $model, array $options = []): \JohannSchopplich\ContentTranslator\Translator
{
return new \JohannSchopplich\ContentTranslator\Translator($model, $options);
}
}
if (!function_exists('translate')) {
function translate(string $text, string $targetLanguage, string|null $sourceLanguage = null): string
{
return \JohannSchopplich\ContentTranslator\Translator::translateText($text, $targetLanguage, $sourceLanguage);
}
}