定制 mcaskill/slim-polyglot 二次开发

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

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

mcaskill/slim-polyglot

最新稳定版本:v0.5.0

Composer 安装命令:

composer require mcaskill/slim-polyglot

包简介

Slim 3 language resolution middleware

README 文档

README

Resolves the response's current language based on the requested URI, the client's preferred language, and the available languages.

Alters the ResponseInterface to assign the Content-Language header.

Uses willdurand/Negotiation to detect and negotiate the client language.

Install

Via Composer:

composer require mcaskill/slim-polyglot

Requires Slim 3.

Usage

use Slim\App;
use McAskill\Slim\Polyglot\Polyglot;

$app = new App();

// Fetch DI Container
$container = $app->getContainer();

// Register Middleware
$app->add(new Polyglot([ 'en', 'fr', 'es' ]));

// Example route with ETag header
$app->get('/foo', function ($request, $response) {
	$language = $response->getHeader('Content-Language');

	// Handle response!
});

$app->run();

The Polyglot middleware can also accept callbacks that are executed after a language is chosen.

use Slim\App;
use McAskill\Slim\Polyglot\Polyglot;

$app = new App();

// Fetch DI Container
$container = $app->getContainer();

// Register Middleware
$app->add(
	new Polyglot([
		'languages' => [ 'en', 'fr', 'es' ],
		'fallbackLanguage' => 'fr',
		// Hooks to call after language is resolved
		'callbacks' => [
			function ($language) use ($container) {
				$container['environment']['language.current'] = $language;
			},
			[ 'MySuperApp', 'set_language' ]
		]
	])
);

// Example route with ETag header
$app->get('/foo', function ($request, $response) {
	$language = $this->environment['language.current'];

	// Handle response!
});

$app->run();

Testing

TBD

Notes

The language code may be formatted as ISO 639-1 alpha-2 (en), ISO 639-3 alpha-3 (msa), or ISO 639-1 alpha-2 combined with an ISO 3166-1 alpha-2 localization (zh-tw).

[ "en", "fr-CA" ]

When giving a list of languages to the Polyglot middleware, the first language is used as the fallback language. When switching to a language that is not in the list of supported languages, the first language is used instead.

Definitions:

  • "language-fallback" — Default language; determined as the first among your supported languages.
  • "language-preferred" — Preferred language(s); determined as the client's localization preferences.
  • "language-current" — Current language; determined as the localization to use based on a cross-reference of the application's supported languages and the client's priority of preferred languages.

License

The MIT License (MIT). Please see the License File for more information.

mcaskill/slim-polyglot 适用场景与选型建议

mcaskill/slim-polyglot 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.74k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2016 年 05 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「framework」 「language」 「middleware」 「slim」 「multilingual」 「polylingual」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 mcaskill/slim-polyglot 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-05-10