Skip to content

Commit 7f409d5

Browse files
committed
fix: handle translations
1 parent 5389cf9 commit 7f409d5

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
],
3434
[
3535
'pattern' => ['(:all)/og-image', 'og-image'],
36-
'language' => '*',
37-
'action' => function ($lang, $slug) {
36+
'action' => function ($slug) {
3837
$languages = kirby()->languages();
3938
$language = null;
39+
4040
if (count($languages) > 1) {
4141
$language = null;
4242
$slugParts = explode('/', $slug);
@@ -48,7 +48,7 @@
4848
}
4949

5050
$languageString = is_null($language) ? 'default' : $language;
51-
$page = ($slug == '/' || $slug == 'og-image') ? site()->homePage() : $page = page($slug);
51+
$page = ($slug == '/' || $slug == 'og-image') ? site()->homePage() : page($slug);
5252

5353
if (!$page) {
5454
return new Response('Page "' . $slug . '" not found', 'text/plain', 404);

lib/page-methods.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,16 @@
4747
return;
4848
}
4949

50+
if ($language == 'default') {
51+
$title = $this->{$titleField}()->isNotEmpty() ? $this->{$titleField}() : $this->title();
52+
} else {
53+
$translation = $this->translation($language);
54+
$content = $translation->content();
55+
$title = !empty($content[$titleField]) ? $content[$titleField] : $content['title'];
56+
}
57+
5058
$canvas = imagecreatetruecolor($imageWidth, $imageHeight);
5159
$textColor = imagecolorallocate($canvas, $fontColor[0], $fontColor[1], $fontColor[2]);
52-
$title = $this->{$titleField}()->isNotEmpty() ? $this->{$titleField}() : $this->title();
5360
$templateImage = imagecreatefrompng($templateImagePath);
5461

5562
$backgroundFile = !is_null($this->{$heroImageField}()) && $this->{$heroImageField}()->isNotEmpty()

0 commit comments

Comments
 (0)