2017 © Pedro Peláez
 

library translated-exception

Automatic exception message translation

image

coldume/translated-exception

Automatic exception message translation

  • Friday, October 24, 2014
  • by coldume
  • Repository
  • 1 Watchers
  • 0 Stars
  • 9,015 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 3 % Grown

The README.md

TranslatedException

Build Status, (*1)

Depict

Previously:, (*2)

+-------------+      'hello' received
| Client side | <-----------------------+
+-------------+                         |
       |                                |
       v                                |
+-------------------+                   |
| Do somthing wrong |                   |
+-------------------+                   |
       |                                |
       v                                |
+-------------------------------+       |
| throw new \Exception('hello') |       |
+-------------------------------+       |
       |                                |
       v                                |
+---------------------------------+     |
| Catch and echo $e->getMessage() | ----+
+---------------------------------+

Now:, (*3)

+-------------+       '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:, (*4)

{
    "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., (*5)

    http://symfony.com/doc/current/components/translation/index.html, (*6)

The Versions

24/10 2014

dev-master

9999999-dev https://github.com/coldume/translated-exception

Automatic exception message translation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Xianghan Wang

exception translation

24/10 2014

dev-develop

dev-develop https://github.com/coldume/translated-exception

Automatic exception message translation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Xianghan Wang

exception translation

24/10 2014

v1.0.0

1.0.0.0 https://github.com/coldume/translated-exception

Automatic exception message translation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Xianghan Wang

exception translation