定制 rnr1721/multilingual-laravel 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

rnr1721/multilingual-laravel

最新稳定版本:1.0.0

Composer 安装命令:

composer require rnr1721/multilingual-laravel

包简介

Laravel implementation for multilingual support (language switcher and URL prefixes)

README 文档

README

Laravel Multilingual Support Package (Languge switcher)

This package provides multilingual support for Laravel applications, allowing easy management of multiple languages, automatic URL prefixing, language switching and locale handling.

Looking for a robust multilingual solution for your Laravel project? This package provides a clean, efficient way to handle multiple languages in your web applications with a focus on developer experience and SEO-friendly URLs.

What makes it special? Unlike traditional approaches, it separates core multilingual logic from framework implementation, making it more maintainable and portable. You get automatic language detection from URLs, smart prefix handling, and seamless locale switching - all while maintaining Laravel's elegant syntax and routing flexibility.

The package is production-ready with features like RTL support, automatic SEO-friendly URL generation, and comprehensive Blade integration. It's thoroughly tested and follows Laravel best practices, making it a reliable choice for projects of any size - from small corporate websites to large international platforms.

Integration is a breeze: just install the package, define your languages in config, and use the intuitive multilingual() route macro. The package handles all the complexities of language switching and URL generation while keeping your code clean and maintainable. No database queries, minimal overhead, and maximum flexibility - just the way Laravel developers like it.

Requirements:

  • PHP 8.1 or higher
  • Laravel 10.0 or higher
  • rnr1721/multilingual-core: ^1.0 (installed automatically as requirement)

Installation in project

composer require rnr1721/multilingual-laravel

Features:

  • Automatic language detection from URL
  • Language prefix management in URLs
  • Blade directives for language switching
  • Route macro for multilingual routes
  • Automatic framework locale switching
  • View variables for language data
  • RTL language support

Middleware: No need to manually manage language detection; LaravelLanguageMiddleware automatically switches the current language based on the URL.

Configuration:

Publish the configuration file:

php artisan vendor:publish --provider="rnr1721\MultilingualLaravel\LaravelMultilingualServiceProvider" --tag="config"

Configure your languages in config/multilingual.php:

<?php

return [
    'languages' => [
        'en' => [
            'name' => 'English',
            'locale' => 'en_US',
            'rtl' => false
        ],
        'es' => [
            'name' => 'Español',
            'locale' => 'es_ES',
            'rtl' => false
        ]
    ],
    'default_language' => 'en',
    'url' => [
        'exclude_default_language' => true
    ],
    'preload_page_links_in_templates' => true
];

Usage:

  1. Define multilingual routes:
Route::multilingual(function () {
    Route::get('/', function () {
        return view('welcome');
    })->name('welcome');
    
    Route::get('/about', function () {
        return view('about');
    })->name('about');
});

This will create routes for all configured languages:

  • / and /about for English (default)
  • /es and /es/about for Spanish
  1. Use in templates:
<nav>
    <ul>
        @foreach($pageLinks as $pageLink)
            <li>
                <a href="{{ $pageLink['url'] }}"
                   @if($pageLink['active']) class="active" @endif>
                    {{ $pageLink['name'] }}
                </a>
            </li>
        @endforeach
    </ul>
</nav>
  1. Generate language-specific URLs:
@language('route.name')
// or
@language('route.name', ['param' => 'value'])
// or
@language('route.name', [], 'es')
  1. Available helper functions:
  • language_route($name, $parameters = [], $language = null)
  • language_url($path, $parameters = [], $language = null)
  • current_language()
  • available_languages()
  • page_links()
  1. Available view variables:
  • $currentLanguage - Current language object
  • $languages - Array of all available languages
  • $pageLinks - Array of language URLs for current page
  1. Translations:

Place your translation files in resources/lang/{locale}/ directories matching the locales in your config:

resources/ └── lang/ ├── en_US/ │ └── messages.php └── es_ES/ └── messages.php

Use translations in templates:

{{ __('messages.welcome') }}

Testing:

composer test

Code Style:

composer cs-check
composer cs-fix

Static Analysis:

composer phpstan

License:

MIT

Credits:

Eugeny G rnr1721@gmail.com

For more detailed documentation and examples, please visit the GitHub repository.

rnr1721/multilingual-laravel 适用场景与选型建议

rnr1721/multilingual-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 rnr1721/multilingual-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rnr1721/multilingual-laravel 我们能提供哪些服务?
定制开发 / 二次开发

基于 rnr1721/multilingual-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-15