8000 Add new translations config path · symfony/symfony-docs@48f89a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 48f89a0

Browse files
committed
Add new translations config path
1 parent 66bb046 commit 48f89a0

File tree

5 files changed

+43
-36
lines changed

5 files changed

+43
-36
lines changed

reference/configuration/framework.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Configuration
8888
* :ref:`enabled <reference-translator-enabled>`
8989
* `fallbacks`_
9090
* `logging`_
91+
* `default_path`_
9192
* :ref:`paths <reference-translator-paths>`
9293
* `property_access`_
9394
* `magic_call`_
@@ -1506,6 +1507,16 @@ for a given key. The logs are made to the ``translation`` channel and at the
15061507
``debug`` for level for keys where there is a translation in the fallback
15071508
locale and the ``warning`` level if there is no translation to use at all.
15081509

1510+
.. _reference-translator-default_path:
1511+
1512+
default_path
1513+
............
1514+
1515+
**type**: ``string`` **default**: ``'%kernel.project_dir%/config/translations'``
1516+
1517+
This option defines the default path where the component will look for translation
1518+
files.
1519+
15091520
.. _reference-translator-paths:
15101521

15111522
paths
@@ -2004,6 +2015,7 @@ Full Default Configuration
20042015
enabled: false
20052016
fallbacks: [en]
20062017
logging: "%kernel.debug%"
2018+
default_path: '%kernel.project_dir%/config/translations'
20072019
paths: []
20082020
20092021
# validation configuration

translation.rst

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ locale to lookup and return translated messages. Before using it, enable the
5959

6060
.. code-block:: yaml
6161
62-
# app/config/config.yml
62+
# config/packages/translation.yaml
6363
framework:
6464
translator: { fallbacks: [en] }
6565
6666
.. code-block:: xml
6767
68-
<!-- app/config/config.xml -->
68+
<!-- config/packages/translation.xml -->
6969
<?xml version="1.0" encoding="UTF-8" ?>
7070
<container xmlns="http://symfony.com/schema/dic/services"
7171
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -84,7 +84,7 @@ locale to lookup and return translated messages. Before using it, enable the
8484
8585
.. code-block:: php
8686
87-
// app/config/config.php
87+
// config/packages/translation.php
8888
$container->loadFromExtension('framework', array(
8989
'translator' => array('fallbacks' => array('en')),
9090
));
@@ -336,10 +336,8 @@ Translation Resource/File Names and Locations
336336

337337
Symfony looks for message files (i.e. translations) in the following default locations:
338338

339-
* the ``app/Resources/translations`` directory;
340-
341-
* the ``app/Resources/<bundle name>/translations`` directory;
342-
339+
* the ``config/translations/`` directory;
340+
* the ``config/translations/<bundle name>/`` directory;
343341
* the ``Resources/translations/`` directory inside of any bundle.
344342

345343
The locations are listed here with the highest priority first. That is, you can
@@ -381,15 +379,15 @@ For more options, see :ref:`component-translator-message-catalogs`.
381379

382380
.. code-block:: yaml
383381
384-
# app/config/config.yml
382+
# config/packages/translation.yaml
385383
framework:
386384
translator:
387385
paths:
388386
- '%kernel.project_dir%/translations'
389387
390388
.. code-block:: xml
391389
392-
<!-- app/config/config.xml -->
390+
<!-- config/packages/translation.xml -->
393391
<?xml version="1.0" encoding="UTF-8" ?>
394392
<container xmlns="http://symfony.com/schema/dic/services"
395393
xmlns:framework="http://symfony.com/schema/dic/symfony"
@@ -409,7 +407,7 @@ For more options, see :ref:`component-translator-message-catalogs`.
409407
410408
.. code-block:: php
411409
412-
// app/config/config.php
410+
// config/packages/translation.php
413411
$container->loadFromExtension('framework', array(
414412
'translator' => array(
415413
'paths' => array(

translation/debug.rst

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,17 @@ It will also detect the following translator usages in PHP templates:
4444
{% set message = 'Symfony is great' %}
4545
{{ message|trans }}
4646
47-
Suppose your application's default_locale is ``fr`` and you have configured
47+
Suppose your application's ``default_locale`` is ``fr`` and you have configured
4848
``en`` as the fallback locale (see :ref:`translation-configuration` and
4949
:ref:`translation-fallback` for how to configure these). And suppose
50-
you've already setup some translations for the ``fr`` locale inside an AcmeDemoBundle:
50+
you've already setup some translations for the ``fr`` locale inside
51+
``config/translations`` directory:
5152

5253
.. configuration-block::
5354

5455
.. code-block:: xml
5556
56-
<!-- src/Acme/AcmeDemoBundle/Resources/translations/messages.fr.xliff -->
57+
<!-- config/translations/messages.fr.xlf -->
5758
<?xml version="1.0"?>
5859
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
5960
<file source-language="en" datatype="plaintext" original="file.ext">
@@ -69,12 +70,12 @@ you've already setup some translations for the ``fr`` locale inside an AcmeDemoB
6970
7071
.. code-block:: yaml
7172
72-
# src/Acme/AcmeDemoBundle/Resources/translations/messages.fr.yml
73+
# config/translations/messages.fr.yaml
7374
Symfony is great: J'aime Symfony
7475
7576
.. code-block:: php
7677
77-
// src/Acme/AcmeDemoBundle/Resources/translations/messages.fr.php
78+
// config/translations/messages.fr.php
7879
return array(
7980
'Symfony is great' => 'J\'aime Symfony',
8081
);
@@ -85,7 +86,7 @@ and for the ``en`` locale:
8586

8687
.. code-block:: xml
8788
88-
<!-- src/Acme/AcmeDemoBundle/Resources/translations/messages.en.xliff -->
89+
<!-- config/translations/messages.en.xlf -->
8990
<?xml version="1.0"?>
9091
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
9192
<file source-language="en" datatype="plaintext" original="file.ext">
@@ -100,21 +101,21 @@ and for the ``en`` locale:
100101
101102
.. code-block:: yaml
102103
103-
# src/Acme/AcmeDemoBundle/Resources/translations/messages.en.yml
104+
# config/translations/messages.en.yml
104105
Symfony is great: Symfony is great
105106
106107
.. code-block:: php
107108
108-
// src/Acme/AcmeDemoBundle/Resources/translations/messages.en.php
109+
// config/translations/messages.en.php
109110
return array(
110111
'Symfony is great' => 'Symfony is great',
111112
);
112113
113-
To inspect all messages in the ``fr`` locale for the AcmeDemoBundle, run:
114+
To inspect all messages in the ``fr`` locale, run:
114115

115116
.. code-block:: terminal
116117
117-
$ php bin/console debug:translation fr AcmeDemoBundle
118+
$ php bin/console debug:translation fr
118119
119120
You will get this output:
120121

@@ -164,13 +165,13 @@ domain:
164165

165166
.. code-block:: terminal
166167
167-
$ php bin/console debug:translation en AcmeDemoBundle --domain=messages
168+
$ php bin/console debug:translation en --domain=messages
168169
169170
When bundles have a lot of messages, it is useful to display only the unused
170171
or only the missing messages, by using the ``--only-unused`` or ``--only-missing``
171172
switches:
172173

173174
.. code-block:: terminal
174175
175-
$ php bin/console debug:translation en AcmeDemoBundle --only-unused
176-
$ php bin/console debug:translation en AcmeDemoBundle --only-missing
176+
$ php bin/console debug:translation en --only-unused
177+
$ php bin/console debug:translation en --only-missing

translation/lint.rst

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,17 @@ translation file using the ``lint:yaml`` and ``lint:xliff`` commands:
1515
.. code-block:: terminal
1616
1717
# lint a single file
18-
$ ./bin/console lint:yaml app/Resources/translations/messages.en.yml
19-
$ ./bin/console lint:xliff app/Resources/translations/messages.en.xlf
18+
$ ./bin/console lint:yaml config/translations/messages.en.yml
19+
$ ./bin/console lint:xliff config/translations/messages.en.xlf
2020
2121
# lint a whole directory
22-
$ ./bin/console lint:yaml app/Resources/translations
23-
$ ./bin/console lint:xliff app/Resources/translations
24-
25-
# lint a specific bundle
26-
$ ./bin/console lint:yaml @AppBundle
27-
$ ./bin/console lint:xliff @AppBundle
22+
$ ./bin/console lint:yaml config/translations
23+
$ ./bin/console lint:xliff config/translations
2824
2925
The linter results can be exported to JSON using the ``--format`` option:
3026

3127
.. code-block:: terminal
3228
3329
# lint a single file
34-
$ ./bin/console lint:yaml app/Resources/translations --format=json
35-
$ ./bin/console lint:xliff app/Resources/translations --format=json
30+
$ ./bin/console lint:yaml config/translations --format=json
31+
$ ./bin/console lint:xliff config/translations --format=json

translation/locale.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ the framework:
130130

131131
.. code-block:: yaml
132132
133-
# app/config/config.yml
133+
# config/packages/translation.yaml
134134
framework:
135135
default_locale: en
136136
137137
.. code-block:: xml
138138
139-
<!-- app/config/config.xml -->
139+
<!-- config/packages/translation.xml -->
140140
<?xml version="1.0" encoding="UTF-8" ?>
141141
<container xmlns="http://symfony.com/schema/dic/services"
142142
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -151,7 +151,7 @@ the framework:
151151
152152
.. code-block:: php
153153
154-
// app/config/config.php
154+
// config/packages/translation.php
155155
$container->loadFromExtension('framework', array(
156156
'default_locale' => 'en',
157157
));

0 commit comments

Comments
 (0)
0