coldume/translated-exception
最新稳定版本:v1.0.0
Composer 安装命令:
composer require coldume/translated-exception
包简介
Automatic exception message translation
关键字:
README 文档
README
Depict
Previously:
+-------------+ 'hello' received
| Client side | <-----------------------+
+-------------+ |
| |
v |
+-------------------+ |
| Do somthing wrong | |
+-------------------+ |
| |
v |
+-------------------------------+ |
| throw new \Exception('hello') | |
+-------------------------------+ |
| |
v |
+---------------------------------+ |
| Catch and echo $e->getMessage() | ----+
+---------------------------------+
Now:
+-------------+ 'bonjour' received
| Client side | <-------------------------------------+
+-------------+ |
| |
v |
+-------------------+ |
| Do somthing wrong | |
+-------------------+ |
| |
v |
+----------------------------------------+ |
| throw new TranslatedException('hello') | |
+----------------------------------------+ |
| |
v +---------------------+ |
+---------------------+ | Translator | |
| Inside | --> | locale: "fr" | |
| TranslatedException | <-- | dictionary: "fr-en" | |
+---------------------+ +---------------------+ |
| |
v |
+---------------------------------+ |
| Catch and echo $e->getMessage() | ------------------+
+---------------------------------+
Installation
Simply add a dependency on coldume/translated-exception to your project's composer.json file:
{
"require": {
"coldume/translated-exception": "~1.0"
}
}
Usage
use TranslatedException\TranslatedException; $options = [ 'locale' => 'fr', 'cache_dir' => __DIR__.'/foo', 'debug' => true, ]; TranslatedException::init($options); TranslatedException::addResourceDir(__DIR__.'/bar'); try { throw new TranslatedException('foo', 'hello.%name%', ['%name%' => 'foo']); } catch (TranslatedException $e) { echo $e->getMessage(); }
Resources
-
Symfony translation component.
http://symfony.com/doc/current/components/translation/index.html
统计信息
- 总下载量: 33.93k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-10-24