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
Abdellatif Ait boudad ce540aeaf9 update changelog.
2015-09-07 18:06:19 +00:00
..
Catalogue [translation][framework-bundle] Deprecated DiffOperation 2015-09-03 14:49:29 +08:00
DataCollector Merge branch '2.7' into 2.8 2015-08-24 09:18:02 +02:00
Dumper [Translation] added <tool> element metadata to XliffFileDumper 2015-08-27 09:23:57 +00:00
Exception [Translation] uniformized the way exception are thrown in LoaderInterface::load() 2012-12-13 11:00:37 +01:00
Extractor [Translation][Extractor] Allow extracting an array of files besides extracting a directory 2015-03-27 07:53:09 +01:00
Loader [Translation][Loader] added XLIFF 2.0 support. 2015-09-07 17:58:34 +00:00
Tests [Translation][Loader] added XLIFF 2.0 support. 2015-09-07 17:58:34 +00:00
Util [Translation] add options 'as_tree', 'inline' to YamlFileDumper to dump messages as tree instead of simple list. 2015-05-20 12:35:10 +03:00
Writer Merge branch '2.3' into 2.5 2014-12-22 17:16:14 +01:00
.gitignore Added missing files .gitignore 2013-07-21 14:12:18 +02:00
CHANGELOG.md update changelog. 2015-09-07 18:06:19 +00:00
composer.json Merge branch '2.7' into 2.8 2015-09-01 15:59:44 +02:00
DataCollectorTranslator.php [Translation] Add parameters to DataCollectorTranslator 2015-07-09 18:26:53 +02:00
IdentityTranslator.php [Translation] make IdentityTranslater consistent with normal translator 2013-11-20 03:31:35 +01:00
Interval.php Docblock fixes 2014-11-30 13:33:44 +00:00
LICENSE Updated copyright to 2015 2015-01-01 13:56:52 +01:00
LoggingTranslator.php [2.6][Translation] remove duplicate code for loading catalogue. 2015-04-16 11:17:38 +01:00
MessageCatalogue.php [Translator][fallback catalogues] fixed circular reference. 2015-09-02 09:56:25 +00:00
MessageCatalogueInterface.php Docblock fixes 2014-11-30 13:33:44 +00:00
MessageSelector.php Merge branch '2.3' into 2.6 2015-06-11 19:26:27 +02:00
MetadataAwareInterface.php Fix doc blocks 2014-04-18 22:17:16 +02:00
phpunit.xml.dist [2.3] require-dev PHPUnit bridge 2015-02-24 11:24:26 +01:00
PluralizationRules.php Merge branch '2.3' into 2.6 2015-07-01 20:23:01 +02:00
README.md Merge branch '2.7' into 2.8 2015-09-06 10:37:06 +02:00
Translator.php Merge branch '2.7' into 2.8 2015-09-03 13:42:45 +02:00
TranslatorBagInterface.php [2.6][Translation] remove duplicate code for loading catalogue. 2015-04-16 11:17:38 +01:00
TranslatorInterface.php Docblock fixes 2014-11-30 13:33:44 +00: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.8/book/translation.html

You can run the unit tests with the following command:

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