miladul/laravel-multilang
最新稳定版本:v1.0.0
Composer 安装命令:
composer require miladul/laravel-multilang
包简介
A simple multi-language package for Laravel using JSON files.
README 文档
README
A simple multilingual package for Laravel to manage translations easily using JSON language files.
📦 Installation
You can install this package directly from GitHub.
1. Add the repository to your
composer.json:
"repositories": [
{
"type": "git",
"url": "https://github.com/miladul/laravel-multilang.git"
}
]
2. Require the package using Composer:
composer require miladul/laravel-multilang:dev-main
3. Publish the configuration and language files:
php artisan vendor:publish --tag=multilang
This will create the default language files in resources/lang.
🌐 Language Files
Language files are stored as JSON files in resources/lang. like:
resources/lang/
├── en.json # English
├── bn.json # Bengali
├── cn.json # Chinese
└── in.json # Hindi/India
Example en.json:
{
"welcome": "Welcome to our website",
"goodbye": "Goodbye"
}
Example bn.json
{
"welcome": "আমাদের ওয়েবসাইটে স্বাগতম",
"goodbye": "বিদায়!"
}
🚀 Usage
Using the mlang helper function:
echo mlang('welcome'); // Outputs translation based on current locale
Using Laravel’s standard __ helper function:
<p>{{ __('goodbye') }}</p>
Both methods work the same way. mlang() is just a shortcut for convenience.
🌍 Changing Locale
app()->setLocale('en') // Switch to English
app()->setLocale('bn') // Switch to Bengali
app()->setLocale('cn') // Switch to Chinese
app()->setLocale('in') // Switch to Hindi/India
✏️ Adding or Updating Translations
- Open the language JSON file for the desired locale, e.g., resources/lang/bn.json.
- Add new key-value pairs or update existing ones.
- you can add new file that must be match with your locale. eg:
ar.json for arabic language - Run
php artisan config:clearto clear the configuration cache.
Example: bn.json
{
"welcome": "আমাদের ওয়েবসাইটে স্বাগতম",
"goodbye": "বিদায়!",
"contact_us": "যোগাযোগ করুন" //new one
}
📝 Summary
- Install via Composer from GitHub.
- Publish language files with php artisan vendor:publish --tag=multilang.
- Use mlang('key') or __('key') to get translations.
- Manage translations via JSON files in resources/lang.
- Dynamically switch locale using App::setLocale('locale').
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-01