Skip to content
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

[Reference] link translation DIC tags to components section #4247

Merged
merged 1 commit into from
Sep 22, 2014
Merged
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
4 changes: 4 additions & 0 deletions components/translation/custom_formats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ message. A translation file would look like this:
(goodbye)(au revoir)
(hello)(bonjour)

.. _components-translation-custom-loader:

Creating a Custom Loader
------------------------

Expand Down Expand Up @@ -65,6 +67,8 @@ Once created, it can be used as any other loader::

It will print *"accueil"*.

.. _components-translation-custom-dumper:

Creating a Custom Dumper
------------------------

Expand Down
33 changes: 9 additions & 24 deletions reference/dic_tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1029,32 +1029,12 @@ translation.loader
**Purpose**: To register a custom service that loads translations

By default, translations are loaded from the filesystem in a variety of different
formats (YAML, XLIFF, PHP, etc). If you need to load translations from some
other source, first create a class that implements the
:class:`Symfony\\Component\\Translation\\Loader\\LoaderInterface` interface::
formats (YAML, XLIFF, PHP, etc).

// src/Acme/MainBundle/Translation/MyCustomLoader.php
namespace Acme\MainBundle\Translation;

use Symfony\Component\Translation\Loader\LoaderInterface;
use Symfony\Component\Translation\MessageCatalogue;

class MyCustomLoader implements LoaderInterface
{
public function load($resource, $locale, $domain = 'messages')
{
$catalogue = new MessageCatalogue($locale);

// some how load up some translations from the "resource"
// then set them into the catalogue
$catalogue->set('hello.world', 'Hello World!', $domain);

return $catalogue;
}
}
.. seealso::

Your custom loader's ``load`` method is responsible for returning a
:Class:`Symfony\\Component\\Translation\\MessageCatalogue`.
Learn how to :ref:`load custom formats <components-translation-custom-loader>`
in the components section.

Now, register your loader as a service and tag it with ``translation.loader``:

Expand Down Expand Up @@ -1252,6 +1232,11 @@ This is the name that's used to determine which dumper should be used.
)
->addTag('translation.dumper', array('alias' => 'json'));

.. seealso::

Learn how to :ref:`dump to custom formats <components-translation-custom-dumper>`
in the components section.
Copy link
Contributor

Choose a reason for hiding this comment

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

this is too generic? or you really mean component singular

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, don't you think it's clear enough with link directly pointing to the relevant part? Do you think that "[...] in the component's documentation" is better?


.. _reference-dic-tags-twig-extension:

twig.extension
Expand Down