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 d100ffaf76 fixed CS
2012-07-09 14:54:20 +02:00
..
Dumper fixed CS 2012-07-09 14:54:20 +02:00
Extractor fixed CS 2012-07-09 14:54:20 +02:00
Loader fixed CS 2012-07-09 14:54:20 +02:00
Tests fixed CS 2012-05-21 16:06:09 +02:00
Writer fix some translations component phpdocs 2012-01-24 10:12:17 +01:00
.gitignore [Components] Tests/Autoloading fixes 2012-05-01 17:51:41 +02:00
CHANGELOG.md [Translation] added CHANGELOG 2012-04-26 19:56:13 +02:00
composer.json updated minimum PHP version to 5.3.3 2012-05-07 10:29:11 +02:00
IdentityTranslator.php [Translation] tagged the guaranteed BC API 2011-03-24 09:07:52 +01:00
Interval.php fixed CS 2012-07-09 14:54:20 +02:00
LICENSE Updated LICENSE files copyright 2012-02-22 10:10:37 +01:00
MessageCatalogue.php Merge branch '2.0' 2011-11-11 22:52:07 +01:00
MessageCatalogueInterface.php fixed CS 2012-07-09 14:54:20 +02:00
MessageSelector.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
phpunit.xml.dist [Components] Tests/Autoloading fixes 2012-05-01 17:51:41 +02:00
PluralizationRules.php fixed CS 2012-07-09 14:54:20 +02:00
README.md [Components] Tests/Autoloading fixes 2012-05-01 17:51:41 +02:00
Translator.php merged 2.0 2012-02-22 18:59:56 +01:00
TranslatorInterface.php fixed CS 2012-07-09 14:54:20 +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->setFallbackLocale('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.0/book/translation.html

You can run the unit tests with the following command:

phpunit

If you also want to run the unit tests that depend on other Symfony Components, install dev dependencies before running PHPUnit:

php composer.phar install --dev