Skip to content

Commit

Permalink
Merge pull request #5190 from coudenysj/translation-documentation
Browse files Browse the repository at this point in the history
Merge the translation component documentation in the resource component documentation
  • Loading branch information
Paweł Jędrzejewski committed Jun 7, 2016
2 parents 4b7ba66 + 6db2cc6 commit 8609316
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 175 deletions.
4 changes: 2 additions & 2 deletions docs/components/Attribute/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Every attribute is represented by the **Attribute** model which by default has t
+---------------+-----------------------------------------------------------+

.. note::
This model extends the :ref:`component_translation_model_abstract-translatable` class
This model uses the :ref:`component_resource_translations_translatable-trait`
and implements the :ref:`component_attribute_model_attribute-interface`.

For more detailed information go to `Sylius API Attribute`_.
Expand Down Expand Up @@ -101,7 +101,7 @@ model which has the following properties:
+-----------+----------------------------------------+

.. note::
This model extends the :ref:`component_translation_model_abstract-translation` class
This model extends the :ref:`component_resource_translations_abstract-translation` class
and implements the :ref:`component_attribute_model_attribute-translation-interface`.

For more detailed information go to `Sylius API AttributeTranslation`_.
Expand Down
4 changes: 2 additions & 2 deletions docs/components/Product/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ By default it contains the following properties:
+-----------------+-----------------------------------------------------------------------------+

.. note::
This model extends the :ref:`component_translation_model_abstract-translatable`
This model uses the :ref:`component_resource_translations_translatable-trait`
and implements the :ref:`component_product_model_product-interface`.

For more detailed information go to `Sylius API Product`_.
Expand All @@ -63,7 +63,7 @@ By default it has the following properties:
+-----------------+--------------------------------------+

.. note::
This model extends the :ref:`component_translation_model_abstract-translation`
This model extends the :ref:`component_resource_translations_abstract-translation` class
and implements the :ref:`component_product_model_product-translation-interface`.

For more detailed information go to `Sylius API ProductTranslation`_.
Expand Down
2 changes: 2 additions & 0 deletions docs/components/Resource/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ Domain management abstraction for PHP. It provides interface for most common ope
model
factory
repository
service
translation
summary
32 changes: 32 additions & 0 deletions docs/components/Resource/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,35 @@ and will ask you to implement the following methods to your model:
+------------------------------------+------------------------------------------+-------------------+
| setSlug(string $slug = null) | Set slug | void |
+------------------------------------+------------------------------------------+-------------------+

.. _component_resource_model_translatable-interface:

TranslatableInterface
---------------------

This interface should be implemented by a model used in more than one language.

.. hint::
Although you can implement this interface in your class, it's easier to just
use the :ref:`component_resource_translations_translatable-trait` class.

.. note::
For more detailed information go to `Sylius API TranslatableInterface`_.

.. _Sylius API TranslatableInterface: http://api.sylius.org/Sylius/Component/Resource/Model/TranslatableInterface.html

.. _component_resource_model_translation-interface:

TranslationInterface
--------------------

This interface should be implemented by a model responsible for keeping a single translation.

.. hint::
And as above, although you are completely free to create your own class implementing this interface,
it's already implemented in the :ref:`component_resource_translations_abstract-translation` class.

.. note::
For more detailed information go to `Sylius API TranslationInterface`_.

.. _Sylius API TranslationInterface: http://api.sylius.org/Sylius/Component/Resource/Model/TranslationInterface.html
32 changes: 32 additions & 0 deletions docs/components/Resource/service.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Service interfaces
==================

.. _component_resource_provider_locale-provider-interface:

LocaleProviderInterface
-----------------------

This interface should be implemented by a service responsible for managing locales.

.. note::
For more detailed information go to `Sylius API LocaleProviderInterface`_.

.. _Sylius API LocaleProviderInterface: http://api.sylius.org/Sylius/Component/Resource/Provider/LocaleProviderInterface.html

.. _component_resource_repository_translatable-resource-repository-interface:

TranslatableRepositoryInterface
-------------------------------

This interface should be implemented by a repository responsible for keeping the **LocaleProvider**
and an array of fields

This interface expects you to implement a way of setting an instance of **LocaleProviderInterface**,
and an array of translatable fields into your custom repository.

.. note::
This interface extends the :ref:`component_resource_repository_repository-interface`.

For more detailed information go to `Sylius API TranslatableResourceRepositoryInterface`_.

.. _Sylius API TranslatableResourceRepositoryInterface: http://api.sylius.org/Sylius/Component/Resource/Repository/TranslatableRepositoryInterface.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Basic Usage
===========
Translations
============

.. _book-translation:
.. _component_resource_translations_abstract-translation:

Implementing AbstractTranslation
--------------------------------
Expand All @@ -14,7 +14,7 @@ First let's create a class which will keep our translatable properties:
namespace Example\Model;
use Sylius\Component\Translation\Model\AbstractTranslation;
use Sylius\Component\Resource\Model\AbstractTranslation;
class BookTranslation extends AbstractTranslation
{
Expand All @@ -40,10 +40,10 @@ First let's create a class which will keep our translatable properties:
}
}
.. _book:
.. _component_resource_translations_translatable-trait:

Implementing AbstractTranslatable
---------------------------------
Using TranslatableTrait
-----------------------

Now the following class will be actually capable of translating the **title**:

Expand All @@ -53,10 +53,13 @@ Now the following class will be actually capable of translating the **title**:
namespace Example\Model;
use Sylius\Component\Translation\Model\AbstractTranslatable;
use Sylius\Component\Resource\Model\TranslatableInterface;
use Sylius\Component\Resource\Model\TranslatableTrait;
class Book extends AbstractTranslatable
class Book implements TranslatableInterface
{
use TranslatableTrait;
/**
* @return string
*/
Expand All @@ -78,12 +81,12 @@ Now the following class will be actually capable of translating the **title**:
As you could notice, inside both methods we use the ``translate`` method.
More specified explanation on what it does is described further on.

.. _component_translation_basic-translations:
.. _component_resource_translations_usage:

Using Translations
------------------

Once we have both abstract classes implemented we can start translating.
Once we have both classes implemented we can start translating.
So first we need to create a few instances of our translation class:

.. code-block:: php
Expand Down Expand Up @@ -153,23 +156,23 @@ You can always use the ``translate`` method by itself, but the same principal is

.. _\\RuntimeException: https://secure.php.net/manual/pl/class.runtimeexception.php

.. _component_translation_provider_locale-provider:
.. _component_resource_provider_locale-provider:

LocaleProvider
--------------

This service provides you with an easy way of managing locales.
The first parameter set in it's constructor is the current locale and the second, fallback.

In this example let's use the provider with our :ref:`Book <book>`
class which extends the :ref:`component_translation_model_abstract-translatable`:
In this example let's use the provider with our `Book`
class which uses the :ref:`component_resource_translations_translatable-trait`:

.. code-block:: php
<?php
use Example\Model\Book;
use Sylius\Component\Translation\Provider\LocaleProvider;
use Sylius\Component\Resource\Provider\LocaleProvider;
$provider = new LocaleProvider('de', 'en');
Expand All @@ -181,15 +184,15 @@ class which extends the :ref:`component_translation_model_abstract-translatable`
$book->getCurrentLocale(); // returns 'de'
$book->getFallbackLocale(); // returns 'en'
... and with an :ref:`component_translation_model_abstract-translation`
class such as the exemplary :ref:`BookTranslation <book-translation>` it goes:
... and with an :ref:`component_resource_translations_abstract-translation`
class such as the exemplary `BookTranslation` it goes:

.. code-block:: php
<?php
use Example\Model\BookTranslation;
use Sylius\Component\Translation\Provider\LocaleProvider;
use Sylius\Component\Resource\Provider\LocaleProvider;
$provider = new LocaleProvider('de', 'en');
Expand All @@ -200,4 +203,4 @@ class such as the exemplary :ref:`BookTranslation <book-translation>` it goes:
$translation->getLocale(); // returns 'de'
.. note::
This service implements the :ref:`component_translation_provider_locale-provider-interface`.
This service implements the :ref:`component_resource_provider_locale-provider-interface`.
2 changes: 1 addition & 1 deletion docs/components/Shipping/basic_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Shipping Method Translation
---------------------------

**ShippingMethodTranslation** allows shipping method's name translation according to given locales. To see how to use translation
please go to :ref:`component_translation_basic-translations`.
please go to :ref:`component_resource_translations_usage`.

Rule
----
Expand Down
6 changes: 3 additions & 3 deletions docs/components/Shipping/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ It has the following properties:
+---------------------+-------------------------------------------------------------------------+

.. note::
This model implements the :ref:`component_shipping_model_shipping-method-interface` and extends
:ref:`component_translation_model_abstract-translatable` class.
This model implements the :ref:`component_shipping_model_shipping-method-interface` and uses the
:ref:`component_resource_translations_translatable-trait`.

For more detailed information go to `Sylius API ShippingMethod`_.

Expand All @@ -163,7 +163,7 @@ It has the following properties:

.. note::
This model implements the :ref:`component_shipping_model_shipping-method-translation-interface` and extends
:ref:`component_translation_model_abstract-translation` class.
:ref:`component_resource_translations_abstract-translation` class.

Form more information go to `Sylius API ShippingMethodTranslation`_.

Expand Down
2 changes: 1 addition & 1 deletion docs/components/Taxonomy/interfaces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The **TaxonInterface** gives an object an ability to have Taxons assigned as chi
.. note::

This interface extends the :ref:`component_resource_model_code-aware-interface`,
:ref:`component_translation_model_translatable-interface`
:ref:`component_resource_model_translatable-interface`
and the :ref:`component_taxonomy_model_taxon-translation-interface`.

You will find more information about that interface in `Sylius API TaxonInterface`_.
Expand Down
12 changes: 0 additions & 12 deletions docs/components/Translation/index.rst

This file was deleted.

11 changes: 0 additions & 11 deletions docs/components/Translation/installation.rst

This file was deleted.

70 changes: 0 additions & 70 deletions docs/components/Translation/interfaces.rst

This file was deleted.

Loading

0 comments on commit 8609316

Please sign in to comment.