Skip to main content

Silex and the TranslationServiceProvider and some Composer magic

This blog post might be outdated!
This blog post was published more than one year ago and might be outdated!
· 2 min read
Stephan Hochdörfer
Head of IT Business Operations

First time I am toying with Silex and the Symfony components. To demo an application for one of our customers we quickly set-up Silex and put a small application on top. Since the application was in need for a I18N solution I threw in the TranslationServiceProvider. The documentation of Silex states that "you can simply clone the whole Symfony2 into vendor" which did not make any sense to me. Why using a micro-framework when I have to have Symfony2 installed just for the translation part? I was looking for a alternative and remembered Composer. Composer is a tool written in PHP that helps you manage your project or libraries' dependencies. Luckily the Symfony2 components are using Composer, so we can easily install the required dependencies like this:

1. Add a file called composer.json in the root of your project. The content of the file should look like this:
{ "require": { "symfony/translation": "*", "symfony/config": "*", "symfony/yaml": "*", }}
2. Install composer and run the install task and you are done. Is is quite handy as well:
wget http://getcomposer.org/composer.pharphp composer.phar install
Composer will now run, fetch the dependencies from the packagist.org site and installs them in a local directory. After that just include the autoloader.php file which was also generated by Composer for you and you are done.