定制 germania-kg/localisation 二次开发

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

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

germania-kg/localisation

Composer 安装命令:

composer require germania-kg/localisation

包简介

Localisation interfaces, classes and factory

README 文档

README

Germania KG · Localisation

Packagist PHP version Tests

Installation

$ composer require germania-kg/localisation

Interfaces

LocalisationInterface

<?php
namespace Germania\Localisation;

interface LocalisationInterface 
{
    // Sets the fully-qualified Locale string such as `en_GB`.
    public function setLocale( string $locale ) : LocalisationInterface;

    // Returns a fully-qualified Locale string such as `en_GB`.
    public function __toString();

    // Returns a fully-qualified Locale string such as `en_GB`.
    public function getLocale() : string;

    // Returns ISO 639-1 language code such as `en`.
    public function getLanguage() : string;

  	// Returns an ISO 3166-1 alpha-2 country/region code such as `GB`, if possible.
    public function getRegion() : ?string;
}

LocalisationFactoryInterface

<?php
namespace Germania\Localisation;

use Germania\Localisation\LocalisationInterface as Localisation;
use Psr\Http\Message\ServerRequestInterface as Request;

interface LocalisationFactoryInterface
{
    /**
     * @param  ServerRequestInterface $request PSR-7 Server Request
     * @return \Germania\Localisation\LocalisationInterface
     * @throws \Germania\Localisation\FactoryException
     */  
    public function createFromRequest( Request $request ) : Localisation;
}

Factories

NegotiationLocalisationFactory

Class NegotiationLocalisationFactory implements LocalisationFactoryInterface. The constructor requires an instance of Will Durand´s LanguageNegotiator and an array with available language codes and locale strings.

Setup

<?php
use Germania\Localisation\NegotiationLocalisationFactory;
use Negotiation\LanguageNegotiator;

$negotiator = new LanguageNegotiator;
$available = array(
	"de" => "de_DE",
  "de-de" => "de_DE",
  "de_DE" => "de_DE"
);

$factory = new NegotiationLocalisationFactory( $negotiator, $available);

// Optional, as factory would use the first available locale from above, 
// e.g. "de_DE"
$factory->setDefaultLocale("en_US");

Usage

<?php
use Germania\Localisation\ExceptionInterface;  
use Psr\Http\Message\ServerRequestInterface;

try {
  $server_request = ...; //
	$localisation = $factory->createFromRequest( $server_request );  
}
catch (\Germania\Localisation\ExceptionInterface $e) {
  echo get_class($e);
  // Germania\Localisation\FactoryException  
}

Development

$ git clone git@github.com:GermaniaKG/Localisation.git
$ cd Localisation
$ composer install

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固