11.. index ::
2- single: Translation; Custom formats
2+ single: Translation; Adding Custom Format Support
33
4- Custom Formats
5- ==============
4+ Adding Custom Format Support
5+ ============================
66
77Sometimes, you need to deal with custom formats for translation files. The
88Translation component is flexible enough to support this. Just create a
@@ -14,12 +14,12 @@ message. A translation file would look like this:
1414
1515.. code-block :: text
1616
17- (welcome)(Bienvenido )
18- (goodbye)(Adiós )
19- (hello)(Hola )
17+ (welcome)(accueil )
18+ (goodbye)(au revoir )
19+ (hello)(bonjour )
2020
21- Custom Loader
22- -------------
21+ Creating a Custom Loader
22+ ------------------------
2323
2424To define a custom loader that is able to read this kind of files, you must create a
2525new class that implements the
@@ -56,24 +56,23 @@ Once created, it can be used as any other loader::
5656
5757 use Symfony\Component\Translation\Translator;
5858
59- $translator = new Translator('es_ES ');
59+ $translator = new Translator('fr_FR ');
6060 $translator->addLoader('my_format', new MyFormatLoader());
6161
62- $translator->addResource('my_format', __DIR__.'/translations/messages.txt', 'es_ES ');
62+ $translator->addResource('my_format', __DIR__.'/translations/messages.txt', 'fr_FR ');
6363
6464 echo $translator->trans('welcome');
6565
66- It will print *"Bienvenido " *.
66+ It will print *"accueil " *.
6767
68- Custom Dumper
69- -------------
68+ Creating a Custom Dumper
69+ ------------------------
7070
7171It is also possible to create a custom dumper for your format, which is
7272useful when using the extraction commands. To do so, a new class
7373implementing the
7474:class: `Symfony\\ Component\\ Translation\\ Dumper\\ DumperInterface `
75- must be created.
76- To write the dump contents into a file, extending the
75+ must be created. To write the dump contents into a file, extending the
7776:class: `Symfony\\ Component\\ Translation\\ Dumper\\ FileDumper ` class
7877will save a few lines::
7978
@@ -109,7 +108,7 @@ YAML file are dumped into a text file with the custom format::
109108 use Symfony\Component\Translation\Loader\YamlFileLoader;
110109
111110 $loader = new YamlFileLoader();
112- $catalogue = $loader->load(__DIR__ . '/translations/messages.es_ES .yml' , 'es_ES ');
111+ $catalogue = $loader->load(__DIR__ . '/translations/messages.fr_FR .yml' , 'fr_FR ');
113112
114113 $dumper = new MyFormatDumper();
115114 $dumper->dump($catalogue, array('path' => __DIR__.'/dumps'));
0 commit comments