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 3baa43b44e Merge branch '2.4'
* 2.4: (52 commits)
  Fix #8205 : Deprecate file mode update when calling dumpFile
  Fix #10437: Catch exceptions when reloading a no-cache request
  Fix libxml_use_internal_errors and libxml_disable_entity_loader usage
  removed ini check to make uploadedfile work on gae
  Update OptionsResolver.php
  fixed comment in forms.xml file
  Clean KernelInterface docblocks
  Cast the group name as a string
  Fixed doc of InitAclCommand
  [Form] Fix "Array was modified outside object" in ResizeFormListener.
  Fix IBAN validator
  [Process] Remove unreachable code + avoid skipping tests in sigchild environment
  Fixed bug that incorrectly causes the "required" attribute to be omitted from select even though it contains the "multiple" attribute
  Added travis_retry to .travis.yml
  [Process] fix some typos and refactor some code
  [Process] Fix unit tests in sigchild disabled environment
  [Process] Trow exceptions in case a Process method is supposed to be called after termination
  fixed typo
  [Process] fixed fatal errors in getOutput and getErrorOutput when process was not started
  [Process] Fix escaping on Windows
  ...

Conflicts:
	src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php
	src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php
	src/Symfony/Component/Process/Process.php
	src/Symfony/Component/Process/ProcessPipes.php
	src/Symfony/Component/Process/Tests/AbstractProcessTest.php
2014-03-26 12:51:10 +01:00
..
Catalogue Enforce sprintf for exceptions 2013-04-11 08:50:46 +02:00
Dumper fixed CS 2014-03-03 18:47:50 +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.3' into 2.4 2014-03-26 12:35:33 +01:00
Tests Merge branch '2.4' 2014-03-26 12:51:10 +01: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 [Translation] Added template for relative file paths 2014-03-03 18:10:14 +01:00
composer.json updated version to 2.5 2013-11-24 21:17:07 +01:00
IdentityTranslator.php [Translation] make IdentityTranslater consistent with normal translator 2013-11-20 03:31:35 +01:00
Interval.php Fixed most of the docblocks/unused namespaces 2012-12-19 08:09:49 +01:00
LICENSE update year on licenses 2014-01-07 08:19:25 -05: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 [Translation] Fixed regression: When only one rule is passed to transChoice(), this rule should be used 2013-08-23 17:24:14 +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 Merge branch '2.4' 2014-02-03 18:15:42 +01:00
README.md updated version to 2.5 2013-11-24 21:17:07 +01:00
Translator.php added getLoaders() method 2013-09-27 14:04:15 +02:00
TranslatorInterface.php [Translation] make IdentityTranslater consistent with normal translator 2013-11-20 03:31:35 +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.5/book/translation.html

You can run the unit tests with the following command:

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