Translations
Laratic supports multi-language blog posts through a translation system. Posts can be translated using AI or created manually. All translations of the same post share a common reference number.
How Translations Work
Reference Number System
Each English post gets a unique reference number (e.g., REF-000001) upon creation, when you create a
translation for the post, the translation will have the same reference number. This allows the system to
maintain relationships between posts in different languages.
Language Configuration
Supported languages are configured in config/languages.php. The default languages are English and
Spanish. You can add more languages to the configuration file. Each language has a code, name, local name, and
flag. We are using flags from Flag CDN to display the
language
flag in the UI.
- Language code (e.g.,
en,es) - Language name
- Flag emoji or icon
return [
'en' => [
'code' => 'en',
'name' => 'English',
'local_name' => 'English',
'flag' => 'gb',
],
'es' => [
'code' => 'es',
'name' => 'Spanish',
'local_name' => 'Español',
'flag' => 'es',
],
];
Creating Translations
To create a translation for an existing post, navigate to the post editor and use the translations tab. The process involves:
- Go to the translations tab in the post editor
- Select the target language from the available languages (languages that don't already have translations for this post)
- Choose between manual translation or AI-powered translation
- You are redirected to edit the newly created translation and the Livewire component is updated to show the translation details
- The translated post shares the same cover image and is created as inactive (unpublished) by default
Manual Translation
Manual translation allows you to manually create a new post with the same reference number and cover image as the original but with the target language:
- Select a target language in the post editor's translations tab
- Click "Create Manual Translation"
- A new draft post is created with the same reference number and cover image as the original but with the target language and empty title, description, and content fields
- You manually fill in the translated title, description, and content
- The post is created as inactive (unpublished) by default, remember to publish and save once you are done editing.
- You are redirected to edit the newly created translation.
AI Translation
The system can automatically translate posts using AI. Translation preserves formatting, structure, and tone while adapting content to the target language.
AI Translation Process
- User selects target language in the post editor
- The
EditPostcomponent dispatches aTranslatePostWithAijob - The job translates title, description, and content using OpenAI
- The translation will use the same cover image as the original post
- A new post is created with the same reference number but different language
- AI usage is tracked and linked to the translated post
- The translated post is created as inactive (unpublished) by default
- User is redirected to edit the translated post
The process is similar to the AI content generation process, but instead of generating a new post, it will translate the existing post. Please see AI Content Generation for more details.
Translation Management
Slug Generation for Translations
Translations automatically generate slugs using the following logic:
- First, attempt to generate a slug from the translation's title using
Str::slug() - If the title cannot generate a valid slug (e.g., Korean, Chinese, Japanese characters), and a reference number exists, the system will use the English version's slug from the same reference number
- If the slug already exists for another post, a counter is appended to make it unique (e.g.,
my-postbecomesmy-post-1,my-post-2, etc.)
Manual Slug Editing: You can manually set or edit the slug for any post, including translations, in the post editor. The slug field is available in the sidebar when editing a post. Manually set slugs will not be overridden by automatic generation when you update the post title, allowing you full control over your post URLs.
Public Blog Display
The public blog automatically displays (PUBLISHED) posts in the user's current locale, this can be set using the language switcher in the header.
Read Next
- AI Content Generation for creating posts with AI
- Post Management for creating posts manually