Kritim Yantra
Apr 02, 2025
Building modern web applications that cater to a global audience has never been easier. With the Laravel 12 + ReactJS Starter Kit, you can jump-start your project with multi-language support, featuring Arabic, English, and Spanish languages—all in one cohesive package. This starter kit combines the powerful backend of Laravel with the dynamic frontend capabilities of ReactJS and Inertia.js to create a full-fledged blog CRUD application with a host of advanced features.
In today’s interconnected world, reaching out to users in their native language is key to delivering a personalized experience. This starter kit enables you to:
The project comes with dedicated language files for Arabic, English, and Spanish. For each language, you have separate files like messages.php
and validation.php
stored under /lang/{locale}
. This structure makes it easy to:
Example File Structure:
/lang/ar
├─ messages.php
└─ validation.php
/lang/en
├─ messages.php
└─ validation.php
/lang/es
├─ messages.php
└─ validation.php
The starter kit includes a SetLocale
middleware, which dynamically sets the application language based on the user session. It also loads translations into Inertia.js, making them accessible in your React components.
Key Code Snippet:
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Lang;
use Inertia\Inertia;
use Symfony\Component\HttpFoundation\Response;
class SetLocale
{
public function handle(Request $request, Closure $next): Response
{
$locale = Session::get('locale', config('app.locale'));
App::setLocale($locale);
$translations = [];
$langPath = base_path("lang/{$locale}");
if (File::exists($langPath)) {
foreach (File::allFiles($langPath) as $file) {
$filename = pathinfo($file, PATHINFO_FILENAME);
$translations[$filename] = Lang::get($filename);
}
}
$locales = [
'en' => 'English',
'ar' => 'Arabic',
'es' => 'Spanish',
];
Inertia::share('translations', $translations);
Inertia::share('locale', $locale);
Inertia::share('locales', $locales);
return $next($request);
}
}
This middleware:
On the React side, integrating translations is a breeze. With a custom hook (e.g., useTranslations
), you can access and render translated strings effortlessly:
Example Usage in a React Component (PostShow.tsx
):
import { useTranslations } from '@/hooks/useTranslations';
const PostShow = () => {
const { t } = useTranslations();
return (
<div>
<h1>{t('messages.home')}</h1>
{/* Additional content */}
</div>
);
};
export default PostShow;
For right-to-left languages like Arabic, you simply adjust the text direction in your Blade layout:
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}" dir="{{ app()->getLocale() === 'ar' ? 'rtl' : 'ltr' }}">
The blog system in the starter kit includes:
Creating a Blog Post:
/posts/create
.Editing a Blog Post:
Viewing Blog Posts:
The kit isn’t just a one-trick pony—it’s designed to be your launchpad:
Setting up the project is simple:
Download & Extract:
.env
file and a sample SQLite database.Install Dependencies:
composer install
for PHP dependencies.npm install
for frontend packages.Run the Project:
npm run dev
(powered by Vite).php artisan serve
.http://localhost:8000
to see your multi-language blog in action.The Laravel 12 + ReactJS Starter Kit is a powerful, feature-rich solution for developers who want to build multi-language blogs quickly and efficiently. Whether you’re targeting a global audience or looking to support right-to-left languages like Arabic, this starter kit provides all the tools you need—from translation management to advanced blog CRUD operations.
Don’t miss out on this opportunity to streamline your development process and launch your multi-lingual project with confidence.
Happy coding!
No comments yet. Be the first to comment!
Please log in to post a comment:
Continue with Google