Language
This guide covers language configuration, content translation, and multilingual site setup.
- Overview
- Configuring Languages
- Translating Content
- URL Structure for Multilingual Sites
- Language Switching
- Translation Caching
- Best Practices
Overview
The language system in InspireCMS allows you to:
- Define multiple languages for your site
- Translate content into different languages
- Manage language-specific URLs
Configuring Languages
Managing Languages
Languages are managed through the admin panel:
- Navigate to Settings > Languages
- Here you can:
- View existing languages
- Add new languages
- Edit language settings
- Set the default language
Adding a New Language
- Go to Settings > Languages
- Click New Language
- Fill in the required information:
- Code: Standard language code (e.g., 'fr' for French)
- Is Default: Whether this is the default language
- Click Save
Setting the Default Language
The default language is used when:
- A user first visits your site without a language preference
- A requested content translation doesn't exist
- Fallback content is required
To change the default language:
- Go to Settings > Languages
- Find the language you want to make default
- Toggle the "Default" checkbox or edit and check "Default"
Translating Content
InspireCMS manages content translations through a flexible system based on locale keys.
Setting Up Translatable Fields
Configuring fields through the admin panel:
- Go to Settings > Custom Fields > [Your Field Group]
- Edit the field you want to make translatable
- Enable the "Translatable" option
- Save the field configuration
Creating Multilingual Content
When creating or editing content:
- Look for the language selector (often near the top of the form)
- Select the language you want to create/edit content for
- Enter content in that language
- Switch to another language to provide translations
- Fields that are translatable will show for each language
URL Structure for Multilingual Sites
InspireCMS supports different URL strategies for multilingual content:
Language Prefix URLs
/en/about-us
/fr/a-propos
/es/sobre-nosotros
This is the default and most common approach, adding the language code to the URL.
Language Switching
Adding a Language Switcher
InspireCMS provides helper functions to create language switchers:
<!-- In your template -->
<div class="language-switcher">
@foreach(inspirecms()->getAllAvailableLanguages() as $locale => $languageDto)
<a href="{{ url("/$locale") }}>{{ $languageDto->getLabel() }}</a>
@endforeach
</div>
Translation Caching
InspireCMS caches translations for performance:
config/inspirecms.php
'cache' => [
'languages' => [
'key' => 'inspirecms.languages',
'ttl' => 60 * 60 * 24, // 24 hours in seconds
],
],
Clear the language cache after making significant changes to language settings:
php artisan cache:clear
Best Practices
- Start with Default Language: Create content in your default language first
- Consistent URLs: Use consistent URL strategies across languages
- Language Variants: Consider language variants (e.g., PT-BR vs. PT-PT) for targeted audiences