Installation:
composer require blioxxx/contao-i18nl10n
Ensure your Contao 4 project is up-to-date.
First Use Case:
config/bundles.php:
return [
// ...
Blioxxx\ContaoI18nl10nBundle\ContaoI18nl10nBundle::class => ['all' => true],
];
config/packages/contao_i18nl10n.yaml to define supported locales (e.g., en, fr):
locales:
- en
- fr
Where to Look First:
System > Localization to manage locales and page assignments.templates/ for locale-specific templates (e.g., page_*.html5.twig).config/routes.yaml for locale-aware routes (e.g., /{_locale}/page).Page Localization:
i18nl10n field.redirects in contao_i18nl10n.yaml to handle fallback locales:
redirects:
fr: en # Fallback to English if French page missing
Content Localization:
tl_content table with i18nl10n fields for multilingual content (e.g., title, text).// In a custom field type
$this->strTable = 'tl_content';
$this->addField('i18nl10n_title', 'text', 'Title', true);
Twig Integration:
{% set locale = app.request.attributes.get('_locale') %} in Twig to render locale-specific content.{% if locale == 'fr' %}
{{ content.i18nl10n_title|default(content.title) }}
{% endif %}
API/CLI:
contao:i18nl10n:export and import commands to sync locales:
php bin/console contao:i18nl10n:export fr locales/fr.csv
ContaoI18nl10nBundle's router to handle custom routes:
# config/routes.yaml
contao_i18nl10n:
resource: "@ContaoI18nl10nBundle/Resources/config/routing.yaml"
prefix: "/{_locale}"
ContaoI18nl10nBundle::EVENT_LOCALIZE to customize localization logic:
use Symfony\Component\EventDispatcher\GenericEvent;
$dispatcher->addListener(
ContaoI18nl10nBundle::EVENT_LOCALIZE,
function (GenericEvent $event) {
$event->setArgument('fallback', 'en');
}
);
Locale Fallbacks:
redirects in config.php bin/console debug:router to verify routes.Caching:
php bin/console cache:clear
Database Conflicts:
tl_page entries if not managed via the module’s UI.i18nl10n field to avoid manual DB edits.Twig Debugging:
locale variable not updating in Twig.ContaoI18nl10nBundle is loaded before TwigBundle in bundles.php._locale values:
$dispatcher->addListener(
KernelEvents::REQUEST,
function (RequestEvent $event) {
error_log('Locale: ' . $event->getRequest()->attributes->get('_locale'));
}
);
tl_page.i18nl10n.Custom Fields: Extend the module to support custom fields:
// src/EventListener/CustomFieldListener.php
use Blioxxx\ContaoI18nl10nBundle\Event\LocalizeEvent;
public function onLocalize(LocalizeEvent $event) {
$event->addField('custom_field', 'tl_custom_field');
}
Override Templates:
Copy vendor/blioxxx/contao-i18nl10n/src/Resources/contao/templates/ to templates/ to customize backend UI.
Locale-Specific Assets:
Use {% set asset_path = path('assets', {'_locale': locale}) %} in Twig to load locale-aware CSS/JS.
How can I help you explore Laravel packages today?