承接 rnr1721/multilingual-core 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

rnr1721/multilingual-core

最新稳定版本:1.0.2

Composer 安装命令:

composer require rnr1721/multilingual-core

包简介

Core package for multilingual support across different PHP frameworks

README 文档

README

This package provides core functionality for implementing multilingual support across different PHP frameworks. It serves as a base dependency for framework-specific implementations.

Features:

  • Framework-agnostic multilingual support
  • PSR-7 compatible
  • Simple language switching via URL prefixes
  • Support for RTL languages
  • Flexible language detection strategies
  • Framework-independent locale management

Requirements:

  • PHP 8.1 or higher
  • PSR-7 HTTP Message implementation
  • PSR-15 HTTP Middleware
  • PSR-11 Container

Installation:

composer require rnr1721/multilingual-core

Usage:

This package is not intended to be used directly. Instead, use one of the framework-specific implementations:

  • rnr1721/multilingual-laravel for Laravel
  • rnr1721/multilingual-symfony for Symfony
  • rnr1721/multilingual-slim for Slim Framework

For Framework Implementation Developers: The core package provides several interfaces and base classes:

LanguageInterface - Represents a language with its properties:

  • getCode() - returns language code (e.g., 'en', 'ru')
  • getName() - returns language name
  • getLocale() - returns locale code (e.g., 'en_US')
  • isRtl() - indicates if language is RTL

LanguageManagerInterface - Manages available languages:

  • getDefaultLanguage()
  • getCurrentLanguage()
  • setCurrentLanguage()
  • getAvailableLanguages()
  • hasLanguage()
  • getLanguage()

LanguageDetectorInterface - Detects current language from request

UrlGeneratorInterface - Generates URLs with language prefixes

LocaleManagerInterface - Framework-specific locale management:

  • setLocale() - sets the application locale in framework-specific way

Implementation example

// Create language instances
$languages = [
    new Language('en', 'English', 'en_US'),
    new Language('ru', 'Russian', 'ru_RU', false)
];

// Implement LocaleManagerInterface for your framework
class MyFrameworkLocaleManager implements LocaleManagerInterface 
{
    public function setLocale(string $locale): void 
    {
        // Framework-specific locale setting
    }
}

// Create language manager
$manager = new LanguageManager(
    new MyFrameworkLocaleManager(),
    $languages,
    'en' // default language
);

// Language switching example
$manager->setCurrentLanguage('ru'); // Will also set framework locale to ru_RU

Testing:

composer test

Code Style:

composer cs-check
composer cs-fix

Static Analysis:

composer phpstan

License: MIT

Contributing:

Feel free to submit issues and pull requests. For detailed documentation on implementing framework-specific packages, see the examples in our official implementations.

Note: This is a core package and should be used as a dependency for framework-specific implementations rather than directly in projects.

统计信息

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

GitHub 信息

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

其他信息

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