Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit69491ae

Browse files
committed
Improved custom formats article based on comments
1 parentc0f3b0a commit69491ae

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

‎components/translation/custom_formats.rst‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
..index::
2-
single: Translation; Customformats
2+
single: Translation;AddingCustomFormat Support
33

4-
CustomFormats
5-
==============
4+
AddingCustomFormat Support
5+
============================
66

77
Sometimes, you need to deal with custom formats for translation files. The
88
Translation 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 aCustom Loader
22+
------------------------
2323

2424
To define a custom loader that is able to read this kind of files, you must create a
2525
new 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 aCustom Dumper
69+
------------------------
7070

7171
It is also possible to create a custom dumper for your format, which is
7272
useful when using the extraction commands. To do so, a new class
7373
implementing 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
7877
will 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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp