diff --git a/book/handling_multilang.rst b/book/handling_multilang.rst new file mode 100644 index 00000000..93588a6e --- /dev/null +++ b/book/handling_multilang.rst @@ -0,0 +1,350 @@ +.. index:: + single: Multi Language; Book + +Handling Multi-Language Documents +================================= + +The default storage layer of the CMF, PHPCR-ODM, can handle translations +transparently. + +.. tip:: + + This chapter assumes you already have an idea how to interact with + PHPCR-ODM, which was introduced in the :doc:`Database chapter `. + +.. caution:: + + You also need the ``intl`` php extension installed and enabled (otherwise + composer will tell you it can't find ext-intl). If you get issues that some + locales can not be loaded, have a look at `this discussion about ICU`_. + +Initial Language Choice: Lunetics LocaleBundle +---------------------------------------------- + +The CMF recommends to rely on the `LuneticsLocaleBundle`_ +to handle requests to ``/`` on your website. This bundle provides the tools +to select the best locale for the user based on various criteria. + +When you configure ``lunetics_locale``, it is recommended to use a parameter +for the locales, as you need to configure the locales for other bundles +(e.g. the CoreBundle) too. + +.. configuration-block:: + + .. code-block:: yaml + + lunetics_locale: + allowed_locales: "%locales%" + + .. code-block:: xml + + + + + + %locales% + + + + .. code-block:: php + + $container->loadFromExtension('lunetics_locale', array( + 'allowed_locales' => '%locales%', + )); + +Configuring Available Locales +----------------------------- + +The CoreBundle needs to be configure with the available locales. If it is +not configured with locales, it registeres a listener that removes all +translation mapping from PHPCR-ODM documents. + +.. configuration-block:: + + .. code-block:: yaml + + cmf_core: + multilang: + locales: "%locales%" + + .. code-block:: xml + + + + + + %locales% + + + + .. code-block:: php + + $container->loadFromExtension('cmf_core', array( + 'multilang' => array( + 'locales' => '%locales%', + ), + )); + +PHPCR-ODM multi-language Documents +---------------------------------- + +You can mark any properties as being translatable and have the document +manager store and load the correct language for you. Note that translation +always happens on a document level, not on the individual translatable fields. + +.. code-block:: php + + `". + +.. _book_handling-multilang_sonata-admin: + +Sonata PHPCR-ODM Admin +---------------------- + +.. note:: + + Using sonata admin is one way to make your content editable. A book + chapter on sonata admin is planned. Meanwhile, read + :doc:`Sonata Admin <../cookbook/creating_a_cms/sonata-admin>` in the + "Creating a CMS" tutorial. + +The first step is to configure sonata admin. You should place the +LuneticsLocaleBundle language switcher in the ``topnav`` bar. To do this, +configure the template for the ``user_block``: + +.. configuration-block:: + + .. code-block:: yaml + + # app/config/config.yml + sonata_admin: + # ... + templates: + user_block: AcmeCoreBundle:Admin:admin_topnav.html.twig + + .. code-block:: xml + + + + + +