I’m confused… If you want to do this inside a content representation template, the Kirby router takes care of this for you via the URL parameter. I don’t even know if $site->visit() still works here.
It might be better to fetch content in all languages via a custom route?
Not really sure if that would make the blocks render out the translated content though!
Yes, perhaps it’s a poor solution but I was just returning all languages in the json template to avoid having to fetch multiple requests to load each language into the frontend vue app (each language needs to display simultaneously).
What is odd is that the snippets are actually rendered in the correct language, but trying to fetch the caption for the corresponding image in the gallery block is not:
<?php
/** @var \Kirby\Cms\Block $block */ ?>
<figure>
<ul>
<?php foreach ($block->images()->toFiles() as $image) : ?>
<li>
<?= $image ?> // The image itself is correct
<figcaption><?= $image->caption()->kirbytextinline() ?></figcaption> // The caption is not
</li>
<?php endforeach ?>
</ul>
</figure>
OK I think I have found the root if the issue, we have projects with multiple fields. However, one field is a set of gallery blocks that uses the same images across each language. As a result, we made that field non-translatable to avoid confusion.
So I think the question is more explicitly: Is it possible to set the language or pass a variable to a snippet through toBlocks() or toHtml() so something like the image caption can be rendered in the desired language?
In this case, the projects utilized the same selection of images through the gallery block, but the caption but their captions need to display in their corresponding languages.
I’m just surprised there’s no way to access the current language inside the snippet.