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

Add new translations config path#8634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
yceruto wants to merge1 commit intosymfony:masterfromyceruto:translations_path
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletionsreference/configuration/framework.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -88,6 +88,7 @@ Configuration
* :ref:`enabled <reference-translator-enabled>`
* `fallbacks`_
* `logging`_
* `default_path`_
* :ref:`paths <reference-translator-paths>`
* `property_access`_
* `magic_call`_
Expand DownExpand Up@@ -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
Expand DownExpand Up@@ -2004,6 +2015,7 @@ Full Default Configuration
enabled: false
fallbacks: [en]
logging: "%kernel.debug%"
default_path: '%kernel.project_dir%/translations'
paths: []

# validation configuration
Expand Down
18 changes: 8 additions & 10 deletionstranslation.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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

<!--app/config/config.xml -->
<!-- config/packages/translation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand All@@ -84,7 +84,7 @@ locale to lookup and return translated messages. Before using it, enable the

.. code-block:: php

//app/config/config.php
// config/packages/translation.php
$container->loadFromExtension('framework', array(
'translator' => array('fallbacks' => array('en')),
));
Expand DownExpand Up@@ -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/<bundle name>/translations`` directory;

* the ``translations/`` directory;
* the ``translations/<bundle name>/`` directory;
* the ``Resources/translations/`` directory inside of any bundle.

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

.. code-block:: yaml

#app/config/config.yml
# config/packages/translation.yaml
framework:
translator:
paths:
- '%kernel.project_dir%/translations'

.. code-block:: xml

<!--app/config/config.xml -->
<!-- config/packages/translation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:framework="http://symfony.com/schema/dic/symfony"
Expand All@@ -409,7 +407,7 @@ For more options, see :ref:`component-translator-message-catalogs`.

.. code-block:: php

//app/config/config.php
// config/packages/translation.php
$container->loadFromExtension('framework', array(
'translator' => array(
'paths' => array(
Expand Down
27 changes: 14 additions & 13 deletionstranslation/debug.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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

<!--src/Acme/AcmeDemoBundle/Resources/translations/messages.fr.xliff -->
<!-- translations/messages.fr.xlf -->
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
Expand All@@ -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',
);
Expand All@@ -85,7 +86,7 @@ and for the ``en`` locale:

.. code-block:: xml

<!--src/Acme/AcmeDemoBundle/Resources/translations/messages.en.xliff -->
<!-- translations/messages.en.xlf -->
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
Expand All@@ -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:

Expand DownExpand Up@@ -164,13 +165,13 @@ domain:

.. code-block:: terminal

$ php bin/console debug:translation enAcmeDemoBundle--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``
switches:

.. code-block:: terminal

$ php bin/console debug:translation enAcmeDemoBundle--only-unused
$ php bin/console debug:translation enAcmeDemoBundle--only-missing
$ php bin/console debug:translation en --only-unused
$ php bin/console debug:translation en --only-missing
16 changes: 6 additions & 10 deletionstranslation/lint.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,21 +15,17 @@ translation file using the ``lint:yaml`` and ``lint:xliff`` commands:
.. code-block:: terminal

# lint a single file
$ ./bin/console lint:yamlapp/Resources/translations/messages.en.yml
$ ./bin/console lint:xliffapp/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:yamlapp/Resources/translations --format=json
$ ./bin/console lint:xliffapp/Resources/translations --format=json
$ ./bin/console lint:yaml translations --format=json
$ ./bin/console lint:xliff translations --format=json
6 changes: 3 additions & 3 deletionstranslation/locale.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -130,13 +130,13 @@ the framework:

.. code-block:: yaml

#app/config/config.yml
# config/packages/translation.yaml
framework:
default_locale: en

.. code-block:: xml

<!--app/config/config.xml -->
<!-- config/packages/translation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand All@@ -151,7 +151,7 @@ the framework:

.. code-block:: php

//app/config/config.php
// config/packages/translation.php
$container->loadFromExtension('framework', array(
'default_locale' => 'en',
));

[8]ページ先頭

©2009-2025 Movatter.jp