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 d699a929e0 Merge branch '2.2'
* 2.2: (70 commits)
  change wrapped exception message to be more usefull
  updated VERSION for 2.0.23
  update CONTRIBUTORS for 2.0.23
  updated CHANGELOG for 2.0.23
  [Form] fixed failing test
  [DomCrawler] added support for query string with slash
  Fixed invalid file path for hiddeninput.exe on Windows.
  fix xsd definition for strict-requirements
  [WebProfilerBundle] Fixed the toolbar styles to apply them in IE8
  [ClassLoader] fixed heredocs handling
  fixed handling of heredocs
  Add a public modifier to an interface method
  removing xdebug extension
  [HttpRequest] fixes Request::getLanguages() bug
  [HttpCache] added a test (cached content should be kept after purging)
  [DoctrineBridge] Fixed non-utf-8 recognition
  [Security] fixed HttpUtils class tests
  replaced new occurences of 'Request::create()' with '::create()'
  changed sub-requests creation to '::create()'
  fixed merge issue
  ...

Conflicts:
	src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php
	src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig
	src/Symfony/Component/DomCrawler/Link.php
	src/Symfony/Component/Translation/Translator.php
2013-03-20 15:03:03 +01:00
..
Catalogue [FrameworkBundle] adds --clean option translation:update command 2013-03-18 14:53:00 +01:00
Dumper [Translation] added xliff loader/dumper with resname support 2013-03-12 12:04:38 +01:00
Exception [Translation] uniformized the way exception are thrown in LoaderInterface::load() 2012-12-13 11:00:37 +01:00
Extractor CS Fixes - Replaced "array of type" by "Type[]" in PHPDoc block 2012-11-19 13:58:52 +01:00
Loader Merge branch '2.1' into 2.2 2013-03-15 11:14:31 +01:00
Tests Merge branch '2.2' 2013-03-20 15:03:03 +01:00
Writer Fixed most of the docblocks/unused namespaces 2012-12-19 08:09:49 +01:00
.gitignore made usage of Composer autoloader for subtree-split unit tests 2012-11-09 14:10:06 +01:00
CHANGELOG.md [Translator] fixed inconsistency in Translator 2013-02-19 08:34:16 +01:00
composer.json changed dependencies to allow all 2.3 versions of the components (closes #6983) 2013-02-11 11:13:11 +01:00
IdentityTranslator.php [Translator] mention that the message id may also be an object that can be cast to string in TranslatorInterface and fix the IdentityTranslator that did not respect this 2013-02-14 09:35:42 +01:00
Interval.php Fixed most of the docblocks/unused namespaces 2012-12-19 08:09:49 +01:00
LICENSE updated license year 2013-01-04 17:59:43 +01:00
MessageCatalogue.php [Translator] fix metadata 2013-02-14 10:33:29 +01:00
MessageCatalogueInterface.php [Translator] fix phpdoc of MessageCatalogueInterface::add and ::replace 2013-02-14 09:39:14 +01:00
MessageSelector.php Merge branch '2.0' into 2.1 2012-10-06 21:54:37 +02:00
MetadataAwareInterface.php [Translator] fix metadata 2013-02-14 10:33:29 +01:00
phpunit.xml.dist made usage of Composer autoloader for subtree-split unit tests 2012-11-09 14:10:06 +01:00
PluralizationRules.php Fixed most of the docblocks/unused namespaces 2012-12-19 08:09:49 +01:00
README.md [Translator] fixed inconsistency in Translator 2013-02-19 08:34:16 +01:00
Translator.php Merge branch '2.2' 2013-03-20 15:03:03 +01:00
TranslatorInterface.php [Translator] mention that the message id may also be an object that can be cast to string in TranslatorInterface and fix the IdentityTranslator that did not respect this 2013-02-14 09:35:42 +01: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.0/book/translation.html

You can run the unit tests with the following command:

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