1
1
.. index ::
2
2
single: Translation; Custom formats
3
3
4
- Custom formats
4
+ Custom Formats
5
5
==============
6
6
7
7
Sometimes, you need to deal with custom formats for translation files. The
@@ -10,19 +10,23 @@ loader (to load translations) and, optionally, a dumper (to dump translations).
10
10
11
11
Let's imagine you have a custom format where translation messages are defined
12
12
using one line for each translation and parenthesis to wrap the key and the
13
- message. A translation file would look like this::
13
+ message. A translation file would look like this:
14
+
15
+ .. code-block :: text
14
16
15
17
(welcome)(Bienvenido)
16
18
(goodbye)(Adios)
17
19
(hello)(Hola)
18
20
21
+ Custom Loader
22
+ -------------
23
+
19
24
To define a custom loader able to read this kind of files, you must create a
20
25
new class that implements the
21
- :class: `Symfony\\ Component\\ Translation\\ Loader\\ LoaderInterface ` interface,
22
- which defines a
26
+ :class: `Symfony\\ Component\\ Translation\\ Loader\\ LoaderInterface `. The
23
27
:method: `Symfony\\ Component\\ Translation\\ Loader\\ LoaderInterface::load `
24
- method. In the loader, this method will get a filename and parse it to create an
25
- array. Then, it will create the catalog that will be returned::
28
+ method will get a filename and parse it into an array. Then, it will
29
+ create the catalogue that will be returned::
26
30
27
31
use Symfony\Component\Translation\MessageCatalogue;
28
32
use Symfony\Component\Translation\Loader\LoaderInterface;
@@ -59,8 +63,11 @@ Once created, it can be used as any other loader::
59
63
60
64
It will print *"Bienvenido" *.
61
65
62
- It is also possible to create a custom dumper for your format. To do so,
63
- a new class implementing the
66
+ Custom Dumper
67
+ -------------
68
+
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
64
71
:class: `Symfony\\ Component\\ Translation\\ Dumper\\ DumperInterface `
65
72
interface must be created.
66
73
To write the dump contents into a file, extending the
0 commit comments