This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Translation
Fabien Potencier bbadcfd01b Merge branch '2.3' into 2.4
* 2.3:
  Little correction for case 'ar'
  No need to use mb functions here
  [HttpFoundation] update phpdoc of SessionHandlerInterface and unify parameters of all handlers according to interface
  [Doctrine Bridge] fix DbalSessionHandler for high concurrency, interface compliance, compatibility with all drivers (oci8, mysqli, pdo with mysql, sqlsrv, sqlite)
  [Finder] Marked test skipped when ftp stream wrapper is not available
2014-04-18 23:02:05 +02:00
..
Catalogue Enforce sprintf for exceptions 2013-04-11 08:50:46 +02:00
Dumper made {@inheritdoc} annotations consistent across the board 2014-04-16 10:03:46 +02:00
Exception [Translation] uniformized the way exception are thrown in LoaderInterface::load() 2012-12-13 11:00:37 +01:00
Extractor made {@inheritdoc} annotations consistent across the board 2014-04-16 09:04:20 +02:00
Loader Merge branch '2.3' into 2.4 2014-04-16 12:34:31 +02:00
Tests Merge branch '2.3' into 2.4 2014-04-16 10:02:57 +02:00
Writer Fixed most of the docblocks/unused namespaces 2012-12-19 08:09:49 +01:00
.gitignore Added missing files .gitignore 2013-07-21 14:12:18 +02:00
CHANGELOG.md updated various CHANGELOG files that were not updated when the PRs were merged 2013-03-23 08:35:36 +01:00
composer.json updated version to 2.4 2013-05-16 09:54:39 +02:00
IdentityTranslator.php [Translation] make IdentityTranslater consistent with normal translator 2013-11-20 03:31:35 +01:00
Interval.php fixed types in phpdocs 2014-04-16 12:30:19 +02:00
LICENSE update year on licenses 2014-01-07 08:19:25 -05:00
MessageCatalogue.php unified return null usages 2014-04-16 09:43:51 +02:00
MessageCatalogueInterface.php fixed types in phpdocs 2014-04-16 12:30:19 +02:00
MessageSelector.php made phpdoc types consistent with those defined in Hack 2014-04-15 07:41:45 +02:00
MetadataAwareInterface.php Fix doc blocks 2014-04-18 22:17:16 +02:00
phpunit.xml.dist made usage of Composer autoloader for subtree-split unit tests 2012-11-09 14:10:06 +01:00
PluralizationRules.php Merge branch '2.3' into 2.4 2014-04-18 23:02:05 +02:00
README.md Merge branch '2.3' 2013-09-19 11:47:34 +02:00
Translator.php added getLoaders() method 2013-09-27 14:04:15 +02:00
TranslatorInterface.php Merge branch '2.3' into 2.4 2014-04-16 10:02:57 +02:00

Translation Component

Translation provides tools for loading translation files and generating translated strings from these including support for pluralization.

use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\MessageSelector;
use Symfony\Component\Translation\Loader\ArrayLoader;

$translator = new Translator('fr_FR', new MessageSelector());
$translator->setFallbackLocales(array('fr'));
$translator->addLoader('array', new ArrayLoader());
$translator->addResource('array', array(
    'Hello World!' => 'Bonjour',
), 'fr');

echo $translator->trans('Hello World!')."\n";

Resources

Silex integration:

https://github.com/fabpot/Silex/blob/master/src/Silex/Provider/TranslationServiceProvider.php

Documentation:

http://symfony.com/doc/2.4/book/translation.html

You can run the unit tests with the following command:

$ cd path/to/Symfony/Component/Translation/
$ composer.phar install
$ phpunit