Skip to content

Commit

Permalink
fix: handle translations
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricerenck committed Nov 15, 2024
1 parent 5389cf9 commit 7f409d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
],
[
'pattern' => ['(:all)/og-image', 'og-image'],
'language' => '*',
'action' => function ($lang, $slug) {
'action' => function ($slug) {
$languages = kirby()->languages();
$language = null;

if (count($languages) > 1) {
$language = null;
$slugParts = explode('/', $slug);
Expand All @@ -48,7 +48,7 @@
}

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

if (!$page) {
return new Response('Page "' . $slug . '" not found', 'text/plain', 404);
Expand Down
9 changes: 8 additions & 1 deletion lib/page-methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,16 @@
return;
}

if ($language == 'default') {
$title = $this->{$titleField}()->isNotEmpty() ? $this->{$titleField}() : $this->title();
} else {
$translation = $this->translation($language);
$content = $translation->content();
$title = !empty($content[$titleField]) ? $content[$titleField] : $content['title'];
}

$canvas = imagecreatetruecolor($imageWidth, $imageHeight);
$textColor = imagecolorallocate($canvas, $fontColor[0], $fontColor[1], $fontColor[2]);
$title = $this->{$titleField}()->isNotEmpty() ? $this->{$titleField}() : $this->title();
$templateImage = imagecreatefrompng($templateImagePath);

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

0 comments on commit 7f409d5

Please sign in to comment.