1
1
.. index ::
2
- single: Translation; Custom formats
2
+ single: Translation; Adding Custom Format Support
3
3
4
- Custom Formats
5
- ==============
4
+ Adding Custom Format Support
5
+ ============================
6
6
7
7
Sometimes, you need to deal with custom formats for translation files. The
8
8
Translation component is flexible enough to support this. Just create a
@@ -14,12 +14,12 @@ message. A translation file would look like this:
14
14
15
15
.. code-block :: text
16
16
17
- (welcome)(Bienvenido )
18
- (goodbye)(Adiós )
19
- (hello)(Hola )
17
+ (welcome)(accueil )
18
+ (goodbye)(au revoir )
19
+ (hello)(bonjour )
20
20
21
- Custom Loader
22
- -------------
21
+ Creating a Custom Loader
22
+ ------------------------
23
23
24
24
To define a custom loader that is able to read this kind of files, you must create a
25
25
new class that implements the
@@ -56,24 +56,23 @@ Once created, it can be used as any other loader::
56
56
57
57
use Symfony\Component\Translation\Translator;
58
58
59
- $translator = new Translator('es_ES ');
59
+ $translator = new Translator('fr_FR ');
60
60
$translator->addLoader('my_format', new MyFormatLoader());
61
61
62
- $translator->addResource('my_format', __DIR__.'/translations/messages.txt', 'es_ES ');
62
+ $translator->addResource('my_format', __DIR__.'/translations/messages.txt', 'fr_FR ');
63
63
64
64
echo $translator->trans('welcome');
65
65
66
- It will print *"Bienvenido " *.
66
+ It will print *"accueil " *.
67
67
68
- Custom Dumper
69
- -------------
68
+ Creating a Custom Dumper
69
+ ------------------------
70
70
71
71
It is also possible to create a custom dumper for your format, which is
72
72
useful when using the extraction commands. To do so, a new class
73
73
implementing the
74
74
: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
77
76
:class: `Symfony\\ Component\\ Translation\\ Dumper\\ FileDumper ` class
78
77
will save a few lines::
79
78
@@ -109,7 +108,7 @@ YAML file are dumped into a text file with the custom format::
109
108
use Symfony\Component\Translation\Loader\YamlFileLoader;
110
109
111
110
$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 ');
113
112
114
113
$dumper = new MyFormatDumper();
115
114
$dumper->dump($catalogue, array('path' => __DIR__.'/dumps'));
0 commit comments