Skip to content

Commit 629a008

Browse files
committed
Extra improvements based on comments
1 parent bfd78b3 commit 629a008

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

components/translation/custom_formats.rst

+16-17
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@ Custom Formats
55
==============
66

77
Sometimes, 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
99
loader (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
1313
message. 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
2525
new class that implements the
2626
:class:`Symfony\\Component\\Translation\\Loader\\LoaderInterface`. The
2727
:method:`Symfony\\Component\\Translation\\Loader\\LoaderInterface::load`
2828
method 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

5555
Once 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"*.
6668
Custom 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.
7376
To write the dump contents into a file, extending the
7477
:class:`Symfony\\Component\\Translation\\Dumper\\FileDumper` class
7578
will 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::
100102
The :method:`Symfony\\Component\\Translation\\Dumper\\FileDumper::format`
101103
method 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

components/translation/introduction.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ The Translation component uses Loader classes to load catalogs. You can load
6262
multiple resources for the same locale, which will then be combined into one
6363
catalog.
6464

65-
The component comes with some default loaders and you can
66-
:doc:`create your own Loader too </components/translation/custom_formats>`. The
67-
default loaders are:
65+
The component comes with some default loaders:
6866

6967
* :class:`Symfony\\Component\\Translation\\Loader\\ArrayLoader` - to load
7068
catalogs from PHP arrays.
@@ -96,6 +94,9 @@ default loaders are:
9694

9795
All file loaders require the :doc:`Config component </components/config/index>`.
9896

97+
You can also :doc:`create your own Loader </components/translation/custom_formats>`,
98+
in case the format is not already supported by one of the default loaders.
99+
99100
At first, you should add one or more loaders to the ``Translator``::
100101

101102
// ...

0 commit comments

Comments
 (0)