From a227186294b11345442109e958669267f39a262f Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Mon, 13 Nov 2017 00:58:32 -0500 Subject: [PATCH] Add new translations config path --- reference/configuration/framework.rst | 12 ++++++++++++ translation.rst | 18 ++++++++---------- translation/debug.rst | 27 ++++++++++++++------------- translation/lint.rst | 16 ++++++---------- translation/locale.rst | 6 +++--- 5 files changed, 43 insertions(+), 36 deletions(-) diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index 374edd23263..d605c037f30 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -88,6 +88,7 @@ Configuration * :ref:`enabled ` * `fallbacks`_ * `logging`_ + * `default_path`_ * :ref:`paths ` * `property_access`_ * `magic_call`_ @@ -1506,6 +1507,16 @@ for a given key. The logs are made to the ``translation`` channel and at the ``debug`` for level for keys where there is a translation in the fallback locale and the ``warning`` level if there is no translation to use at all. +.. _reference-translator-default_path: + +default_path +............ + +**type**: ``string`` **default**: ``'%kernel.project_dir%/config/translations'`` + +This option defines the default path where the component will look for translation +files. + .. _reference-translator-paths: paths @@ -2004,6 +2015,7 @@ Full Default Configuration enabled: false fallbacks: [en] logging: "%kernel.debug%" + default_path: '%kernel.project_dir%/translations' paths: [] # validation configuration diff --git a/translation.rst b/translation.rst index ab9cc438385..fbb811aa932 100644 --- a/translation.rst +++ b/translation.rst @@ -59,13 +59,13 @@ locale to lookup and return translated messages. Before using it, enable the .. code-block:: yaml - # app/config/config.yml + # config/packages/translation.yaml framework: translator: { fallbacks: [en] } .. code-block:: xml - + loadFromExtension('framework', array( 'translator' => array('fallbacks' => array('en')), )); @@ -336,10 +336,8 @@ Translation Resource/File Names and Locations Symfony looks for message files (i.e. translations) in the following default locations: -* the ``app/Resources/translations`` directory; - -* the ``app/Resources//translations`` directory; - +* the ``translations/`` directory; +* the ``translations//`` directory; * the ``Resources/translations/`` directory inside of any bundle. The locations are listed here with the highest priority first. That is, you can @@ -381,7 +379,7 @@ For more options, see :ref:`component-translator-message-catalogs`. .. code-block:: yaml - # app/config/config.yml + # config/packages/translation.yaml framework: translator: paths: @@ -389,7 +387,7 @@ For more options, see :ref:`component-translator-message-catalogs`. .. code-block:: xml - + loadFromExtension('framework', array( 'translator' => array( 'paths' => array( diff --git a/translation/debug.rst b/translation/debug.rst index 5ff68533669..938d0b0a68d 100644 --- a/translation/debug.rst +++ b/translation/debug.rst @@ -44,16 +44,17 @@ It will also detect the following translator usages in PHP templates: {% set message = 'Symfony is great' %} {{ message|trans }} -Suppose your application's default_locale is ``fr`` and you have configured +Suppose your application's ``default_locale`` is ``fr`` and you have configured ``en`` as the fallback locale (see :ref:`translation-configuration` and :ref:`translation-fallback` for how to configure these). And suppose -you've already setup some translations for the ``fr`` locale inside an AcmeDemoBundle: +you've already setup some translations for the ``fr`` locale inside +``translations/`` directory: .. configuration-block:: .. code-block:: xml - + @@ -69,12 +70,12 @@ you've already setup some translations for the ``fr`` locale inside an AcmeDemoB .. code-block:: yaml - # src/Acme/AcmeDemoBundle/Resources/translations/messages.fr.yml + # translations/messages.fr.yaml Symfony is great: J'aime Symfony .. code-block:: php - // src/Acme/AcmeDemoBundle/Resources/translations/messages.fr.php + // translations/messages.fr.php return array( 'Symfony is great' => 'J\'aime Symfony', ); @@ -85,7 +86,7 @@ and for the ``en`` locale: .. code-block:: xml - + @@ -100,21 +101,21 @@ and for the ``en`` locale: .. code-block:: yaml - # src/Acme/AcmeDemoBundle/Resources/translations/messages.en.yml + # translations/messages.en.yml Symfony is great: Symfony is great .. code-block:: php - // src/Acme/AcmeDemoBundle/Resources/translations/messages.en.php + // translations/messages.en.php return array( 'Symfony is great' => 'Symfony is great', ); -To inspect all messages in the ``fr`` locale for the AcmeDemoBundle, run: +To inspect all messages in the ``fr`` locale, run: .. code-block:: terminal - $ php bin/console debug:translation fr AcmeDemoBundle + $ php bin/console debug:translation fr You will get this output: @@ -164,7 +165,7 @@ domain: .. code-block:: terminal - $ php bin/console debug:translation en AcmeDemoBundle --domain=messages + $ php bin/console debug:translation en --domain=messages When bundles have a lot of messages, it is useful to display only the unused or only the missing messages, by using the ``--only-unused`` or ``--only-missing`` @@ -172,5 +173,5 @@ switches: .. code-block:: terminal - $ php bin/console debug:translation en AcmeDemoBundle --only-unused - $ php bin/console debug:translation en AcmeDemoBundle --only-missing + $ php bin/console debug:translation en --only-unused + $ php bin/console debug:translation en --only-missing diff --git a/translation/lint.rst b/translation/lint.rst index 0c64e4a427e..fc11aebec40 100644 --- a/translation/lint.rst +++ b/translation/lint.rst @@ -15,21 +15,17 @@ translation file using the ``lint:yaml`` and ``lint:xliff`` commands: .. code-block:: terminal # lint a single file - $ ./bin/console lint:yaml app/Resources/translations/messages.en.yml - $ ./bin/console lint:xliff app/Resources/translations/messages.en.xlf + $ ./bin/console lint:yaml translations/messages.en.yml + $ ./bin/console lint:xliff translations/messages.en.xlf # lint a whole directory - $ ./bin/console lint:yaml app/Resources/translations - $ ./bin/console lint:xliff app/Resources/translations - - # lint a specific bundle - $ ./bin/console lint:yaml @AppBundle - $ ./bin/console lint:xliff @AppBundle + $ ./bin/console lint:yaml translations + $ ./bin/console lint:xliff translations The linter results can be exported to JSON using the ``--format`` option: .. code-block:: terminal # lint a single file - $ ./bin/console lint:yaml app/Resources/translations --format=json - $ ./bin/console lint:xliff app/Resources/translations --format=json + $ ./bin/console lint:yaml translations --format=json + $ ./bin/console lint:xliff translations --format=json diff --git a/translation/locale.rst b/translation/locale.rst index d15e441b608..367270a7334 100644 --- a/translation/locale.rst +++ b/translation/locale.rst @@ -130,13 +130,13 @@ the framework: .. code-block:: yaml - # app/config/config.yml + # config/packages/translation.yaml framework: default_locale: en .. code-block:: xml - + loadFromExtension('framework', array( 'default_locale' => 'en', ));