miladul/laravel-multilang 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

  1. Open the language JSON file for the desired locale, e.g., resources/lang/bn.json.
  2. Add new key-value pairs or update existing ones.
  3. you can add new file that must be match with your locale. eg: ar.json for arabic language
  4. Run php artisan config:clear to clear the configuration cache.

Example: bn.json

{
    "welcome": "আমাদের ওয়েবসাইটে স্বাগতম",
    "goodbye": "বিদায়!",
    "contact_us": "যোগাযোগ করুন" //new one
}

📝 Summary

  1. Install via Composer from GitHub.
  2. Publish language files with php artisan vendor:publish --tag=multilang.
  3. Use mlang('key') or __('key') to get translations.
  4. Manage translations via JSON files in resources/lang.
  5. Dynamically switch locale using App::setLocale('locale').

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-01