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 d6f503660f Merge branch '2.3' into 2.7
* 2.3:
  Update copyright year
  [2.3] Static Code Analysis for Components
2016-01-03 16:32:00 +01:00
..
Catalogue Merge branch '2.5' 2014-10-26 08:46:28 +01:00
DataCollector fixes CS 2015-08-24 09:13:45 +02:00
Dumper Merge branch '2.3' into 2.7 2016-01-03 16:32:00 +01:00
Exception remove api tags from code 2015-09-28 19:11:22 +02:00
Extractor [Translation][Extractor] Allow extracting an array of files besides extracting a directory 2015-03-27 07:53:09 +01:00
Loader Merge branch '2.3' into 2.7 2015-10-27 08:38:06 -07:00
Tests Merge branch '2.3' into 2.7 2015-12-05 18:37:09 +01:00
Writer Merge branch '2.3' into 2.7 2016-01-03 16:32:00 +01:00
.gitignore Added missing files .gitignore 2013-07-21 14:12:18 +02:00
CHANGELOG.md [2.7][Translation][change log] added DataCollectorTranslator. 2015-04-12 23:10:02 +01:00
composer.json Merge branch '2.3' into 2.7 2015-10-30 13:10:21 -07:00
DataCollectorTranslator.php remove api tags that are new in 2.7 2015-09-29 14:08:33 +02:00
IdentityTranslator.php Merge branch '2.3' into 2.7 2015-09-29 14:06:14 +02:00
Interval.php Docblock fixes 2014-11-30 13:33:44 +00:00
LICENSE Update copyright year 2016-01-01 23:53:47 -03:00
LoggingTranslator.php remove api tags that are new in 2.7 2015-09-29 14:08:33 +02:00
MessageCatalogue.php remove api tags from code 2015-09-28 19:11:22 +02:00
MessageCatalogueInterface.php remove api tags from code 2015-09-28 19:11:22 +02:00
MessageSelector.php Merge branch '2.3' into 2.7 2015-09-29 14:06:14 +02:00
MetadataAwareInterface.php Fix doc blocks 2014-04-18 22:17:16 +02:00
phpunit.xml.dist Add missing exclusions from phpunit.xml.dist 2015-11-18 09:19:46 +01:00
PluralizationRules.php Merge branch '2.3' into 2.7 2015-11-18 14:41:01 +01:00
README.md Merge branch '2.3' into 2.7 2015-09-06 10:36:38 +02:00
Translator.php Merge branch '2.3' into 2.7 2015-09-29 14:06:14 +02:00
TranslatorBagInterface.php [2.6][Translation] remove duplicate code for loading catalogue. 2015-04-16 11:17:38 +01:00
TranslatorInterface.php Merge branch '2.3' into 2.7 2015-09-29 14:06:14 +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/silexphp/Silex/blob/master/src/Silex/Provider/TranslationServiceProvider.php

Documentation:

https://symfony.com/doc/2.7/book/translation.html

You can run the unit tests with the following command:

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