Skip to content

some tweaks for #3190 #3195

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
30 changes: 17 additions & 13 deletions book/translation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ to learn even more. Overall, the process has several steps:
for each supported locale that translate each message in the application;

#. Determine, :ref:`set and manage the user's locale <book-translation-user-locale>`
for the request and optionally on the user's entire session.
for the request and optionally
:doc:`on the user's entire session </cookbook/session/locale_sticky_session>`.

.. _book-translation-configuration:

Expand Down Expand Up @@ -147,11 +148,12 @@ different formats, XLIFF being the recommended format:
# messages.fr.yml
Symfony2 is great: J'aime Symfony2

For information on where these files should be located, see :ref:`book-translation-resource-locations`.
For information on where these files should be located, see
:ref:`book-translation-resource-locations`.

Now, if the language of the user's locale is French (e.g. ``fr_FR`` or ``fr_BE``),
the message will be translated into ``J'aime Symfony2``. You can also translate
message inside your :ref:`templates <book-translation-tags>`.
the message inside your :ref:`templates <book-translation-tags>`.

The Translation Process
~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -278,8 +280,8 @@ texts* and complex expressions:
Using the translation tags or filters have the same effect, but with
one subtle difference: automatic output escaping is only applied to
translations using a filter. In other words, if you need to be sure
that your translated is *not* output escaped, you must apply the
``raw`` filter after the translation filter:
that your translated message is *not* output escaped, you must apply
the ``raw`` filter after the translation filter:

.. code-block:: jinja

Expand All @@ -290,7 +292,7 @@ texts* and complex expressions:

{% set message = '<h3>foo</h3>' %}

{# strings and variables translated via a filter is escaped by default #}
{# strings and variables translated via a filter are escaped by default #}
{{ message|trans|raw }}
{{ '<h3>bar</h3>'|trans|raw }}

Expand All @@ -303,7 +305,7 @@ texts* and complex expressions:
{% trans_default_domain "app" %}

Note that this only influences the current template, not any "included"
templates (in order to avoid side effects).
template (in order to avoid side effects).

.. versionadded:: 2.1
The ``trans_default_domain`` tag is new in Symfony 2.1
Expand Down Expand Up @@ -349,7 +351,7 @@ The filename of the translation files is also important: each message file
must be named according to the following path: ``domain.locale.loader``:

* **domain**: An optional way to organize messages into groups (e.g. ``admin``,
``navigation`` or the default ``messages``) - see ":ref:`using-message-domains`";
``navigation`` or the default ``messages``) - see :ref:`using-message-domains`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should discuss whether we generally want to enclose references to other sections in quotes. Is there some convention we used throughout the docs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to always enclose them in quotes, except for the cases in which we provide the link name explicietly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes quotes seem necessary to me and other times they seem less necessary. I usually take it on a case-by-case basis - I don't care too much either way :).


* **locale**: The locale that the translations are for (e.g. ``en_GB``, ``en``, etc);

Expand Down Expand Up @@ -377,7 +379,7 @@ taste. For more options, see :ref:`component-translator-message-catalogs`.

Each time you create a *new* translation resource (or install a bundle
that includes a translation resource), be sure to clear your cache so
that Symfony can discover the new translation resource:
that Symfony can discover the new translation resources:

.. code-block:: bash

Expand Down Expand Up @@ -484,11 +486,13 @@ by the routing system using the special ``_locale`` parameter:
return $collection;

When using the special ``_locale`` parameter in a route, the matched locale
will *automatically be set on the user's session*. In other words, if a user
will *automatically be set on the Request* and can be retrieved via the
:method:`Symfony\\Component\\HttpFoundation\\Request::getLocale` method.
In other words, if a user
visits the URI ``/fr/contact``, the locale ``fr`` will automatically be set
as the locale for the user's session.
as the locale for the current request.

You can now use the user's locale to create routes to other translated pages
You can now use the locale to create routes to other translated pages
in your application.

Setting a Default Locale
Expand Down Expand Up @@ -659,7 +663,7 @@ steps:
* Abstract messages in your application by wrapping each in either the
:method:`Symfony\\Component\\Translation\\Translator::trans` or
:method:`Symfony\\Component\\Translation\\Translator::transChoice` methods
(learn about this in ":doc:`/components/translation/usage`");
(learn about this in :doc:`/components/translation/usage`);

* Translate each message into multiple locales by creating translation message
files. Symfony2 discovers and processes each file because its name follows
Expand Down
14 changes: 7 additions & 7 deletions components/translation/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ Installation

You can install the component in 2 different ways:

* :doc:`Install it via Composer</components/using_components>` (``symfony/translation`` on `Packagist`_).
* Use the official Git repository (https://github.com/symfony/Translation);
* :doc:`Install it via Composer </components/using_components>` (``symfony/translation`` on `Packagist`_);
* Use the official Git repository (https://github.com/symfony/Translation).

Constructing the Translator
---------------------------

The main access point of the Translation Component is
The main access point of the Translation component is
:class:`Symfony\\Component\\Translation\\Translator`. Before you can use it,
you need to configure it and load the messages to translate (called *message
catalogs*).
Expand Down Expand Up @@ -59,7 +59,7 @@ class. A message catalog is like a dictionary of translations for a specific
locale.

The Translation component uses Loader classes to load catalogs. You can load
multiple resources for the same locale, it will be combined into one
multiple resources for the same locale, which will then be combined into one
catalog.

The component comes with some default Loaders and you can create your own
Expand Down Expand Up @@ -90,10 +90,10 @@ Loader too. The default loaders are:

.. versionadded:: 2.1
The ``IcuDatFileLoader``, ``IcuResFileLoader``, ``IniFileLoader``,
``MofileLoader``, ``PoFileLoader`` and ``QtFileLoader`` are new in
``MofileLoader``, ``PoFileLoader`` and ``QtFileLoader`` were added in
Symfony 2.1

All file loaders require the :doc:`Config component</components/config/index>`.
All file loaders require the :doc:`Config component </components/config/index>`.

At first, you should add one or more loaders to the ``Translator``::

Expand Down Expand Up @@ -203,7 +203,7 @@ specified locale.
Usage
-----

Read how to use the Translation component in ":doc:`/components/translation/usage`".
Read how to use the Translation component in :doc:`/components/translation/usage`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1


.. _Packagist: https://packagist.org/packages/symfony/translation
.. _`ISO3166 Alpha-2`: http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes
Expand Down
6 changes: 3 additions & 3 deletions components/translation/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Imagine you want to translate the string *"Symfony2 is great"* into French::
$translator->addResource('array', array(
'Symfony2 is great!' => 'J\'aime Symfony2!',
), 'fr_FR');

echo $translator->trans('Symfony2 is great!');

In this example, the message *"Symfony2 is great!"* will be translated into
Expand Down Expand Up @@ -81,7 +81,7 @@ is done just as before:

The placeholders can take on any form as the full message is reconstructed
using the PHP :phpfunction:`strtr function<strtr>`. But the ``%...%`` form
is recommend, to avoid problems when using Twig.
is recommended, to avoid problems when using Twig.

As you've seen, creating a translation is a two-step process:

Expand Down Expand Up @@ -257,7 +257,7 @@ To translate pluralized messages, use the
array('%count%' => 10)
);

The second argument (``10`` in this example), is the *number* of objects being
The second argument (``10`` in this example) is the *number* of objects being
described and is used to determine which translation to use and also to populate
the ``%count%`` placeholder.

Expand Down