Commit b85b956b authored by Fabien Potencier's avatar Fabien Potencier

merged branch benoitpointet/update-translation-doc (PR #283)

Commits
-------

ac9dd1f2 added shared services
ccb0452a fixed doc
c57aeab6 fixed typo in doc
06898fb1 corrected translation doc
49f00191 updated tranlation doc with XLIFF and twig infos

Discussion
----------

updated translation doc with XLIFF and Twig infos

Update of PR https://github.com/fabpot/Silex/pull/251

---------------------------------------------------------------------------

by benoitpointet at 2012-03-22T06:48:45Z

fixed typo in doc, please reconsider PR.

---------------------------------------------------------------------------

by igorw at 2012-03-22T19:21:52Z

Apart from the things I mentioned, looks good.

---------------------------------------------------------------------------

by igorw at 2012-03-27T06:30:52Z

👍

---------------------------------------------------------------------------

by benoitpointet at 2012-04-05T18:05:02Z

please reconsider this PR
parents 9516ea7f ac9dd1f2
...@@ -121,6 +121,47 @@ to map languages to files:: ...@@ -121,6 +121,47 @@ to map languages to files::
Finally override the ``translator.loader`` to use a ``YamlFileLoader`` instead Finally override the ``translator.loader`` to use a ``YamlFileLoader`` instead
of the default ``ArrayLoader``:: of the default ``ArrayLoader``::
$app['translator.loader'] = new Symfony\Component\Translation\Loader\YamlFileLoader();
And that's all you need to load translations from YAML files. use Symfony\Component\Translation\Loader\YamlFileLoader;
$app['translator.loader'] = $app->share(function () {
return new YamlFileLoader();
});
That's all you need to load translations from YAML files.
XLIFF-based language files
~~~~~~~~~~~~~~~~~~~~~~~~~
Just as you would do with YAML translation files, you first need to make
sure you have the ``Config`` component from Symfony2, and that it is
registered with the autoloader. See above for details.
Then, similarly, create XLIFF files in your locales directory and setup the ``translator.messages`` to map to them.
Finally override the ``translator.loader`` to use a ``XliffFileLoader``::
use Symfony\Component\Translation\Loader\XliffFileLoader;
$app['translator.loader'] = $app->share(function () {
return new XliffFileLoader();
});
That's it.
Accessing translations in Twig templates
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Once loaded, the translation service provider is available from within Twig templates:
.. code-block:: jinja
{{ app.translator.trans('translation_key') }}
Even better: register the :doc:`SymfonyBridgesServiceProvider <providers/symfony_bridges>` and you will get
the TranslationExtension of the bridge allowing you to translate strings in
the Twig way:
.. code-block:: jinja
{{ 'translation_key'|trans }}
{{ 'translation_key'|transchoice }}
{% trans %}translation_key{% endtrans %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment