@@ -5,28 +5,28 @@ Custom Formats
55==============
66
77Sometimes, you need to deal with custom formats for translation files. The
8- Translation component is flexible enough to support this, just creating a
8+ Translation component is flexible enough to support this. Just create a
99loader (to load translations) and, optionally, a dumper (to dump translations).
1010
11- Let's imagine you have a custom format where translation messages are defined
12- using one line for each translation and parenthesis to wrap the key and the
11+ Imagine that you have a custom format where translation messages are defined
12+ using one line for each translation and parentheses to wrap the key and the
1313message. A translation file would look like this:
1414
1515.. code-block :: text
1616
1717 (welcome)(Bienvenido)
18- (goodbye)(Adios )
18+ (goodbye)(Adiós )
1919 (hello)(Hola)
2020
2121 Custom Loader
2222-------------
2323
24- To define a custom loader able to read this kind of files, you must create a
24+ To define a custom loader that is able to read this kind of files, you must create a
2525new class that implements the
2626:class: `Symfony\\ Component\\ Translation\\ Loader\\ LoaderInterface `. The
2727:method: `Symfony\\ Component\\ Translation\\ Loader\\ LoaderInterface::load `
2828method will get a filename and parse it into an array. Then, it will
29- create the catalogue that will be returned::
29+ create the catalog that will be returned::
3030
3131 use Symfony\Component\Translation\MessageCatalogue;
3232 use Symfony\Component\Translation\Loader\LoaderInterface;
@@ -54,6 +54,8 @@ create the catalogue that will be returned::
5454
5555Once created, it can be used as any other loader::
5656
57+ use Symfony\Component\Translation\Translator;
58+
5759 $translator = new Translator('es_ES');
5860 $translator->addLoader('my_format', new MyFormatLoader());
5961
@@ -66,10 +68,11 @@ It will print *"Bienvenido"*.
6668Custom Dumper
6769-------------
6870
69- It is also possible to create a custom dumper for your format, useful when using
70- the extraction commands. To do so, a new class implementing the
71+ It is also possible to create a custom dumper for your format, which is
72+ useful when using the extraction commands. To do so, a new class
73+ implementing the
7174:class: `Symfony\\ Component\\ Translation\\ Dumper\\ DumperInterface `
72- interface must be created.
75+ must be created.
7376To write the dump contents into a file, extending the
7477:class: `Symfony\\ Component\\ Translation\\ Dumper\\ FileDumper ` class
7578will save a few lines::
@@ -79,8 +82,7 @@ will save a few lines::
7982
8083 class MyFormatDumper extends FileDumper
8184 {
82-
83- public function format(MessageCatalogue $messages, $domain = 'messages')
85+ protected function format(MessageCatalogue $messages, $domain = 'messages')
8486 {
8587 $output = '';
8688
@@ -100,15 +102,12 @@ will save a few lines::
100102The :method: `Symfony\\ Component\\ Translation\\ Dumper\\ FileDumper::format `
101103method creates the output string, that will be used by the
102104:method: `Symfony\\ Component\\ Translation\\ Dumper\\ FileDumper::dump ` method
103- of the :class: `Symfony\\ Component\\ Translation\\ Dumper\\ FileDumper ` class to
104- create the file. The dumper can be used like any other
105- built-in dumper. In this example, the translation messages defined in the YAML file
106- are dumped into a text file with the custom format::
105+ of the FileDumper class to create the file. The dumper can be used like any other
106+ built-in dumper. In the following example, the translation messages defined in the
107+ YAML file are dumped into a text file with the custom format::
107108
108109 use Symfony\Component\Translation\Loader\YamlFileLoader;
109110
110- include_once __DIR__. '/vendor/autoload.php';
111-
112111 $loader = new YamlFileLoader();
113112 $catalogue = $loader->load(__DIR__ . '/translations/messages.es_ES.yml' , 'es_ES');
114113
0 commit comments