Internationalization in Symfony
Learn how to create a basic implementation of field-level translation in an Astro project.
Setup
Copy the reference space, providing the intended structure to follow this guide. Make sure to update the access token.
Alternatively, go to Settings > Internationalization > Languages and add es
(Spanish).
- In the article content type block schema, set the
title
andcontent
fields as translatable. - Go to each article, select the Spanish language, and provide translated content. You can also use AI Translations.
Learn more in the internationalization concept.
Use the language prefix
Update the route configuration to support language paths.
resource: '@StoryblokBundle/config/routes/webhook.php'
storyblok_content_type:
resource: '@StoryblokBundle/config/routes/content_type.php'
+ prefix:
+ es: '/es'
+ en: ''
The Storyblok Symfony bundle will automatically handle the multilingual routing and will fetch the content based on the locale prefix.
Use the language in your controller logic or in your templates, by accessing the current locale using the request
object.
#[AsContentTypeController(contentType: Page::class)]
final class PageController extends AbstractController
{
public function __invoke(Request $request, Page $page): Response
{
$locale = $request->getLocale();
return $this->render('page.html.twig', [
'page' => $page,
'locale' => $locale
]);
}
}