This repository was archived by the owner on Sep 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 156
Document alternate locale handling #755
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
Alternate Locale Handling | ||
========================= | ||
|
||
.. versionadded:: 1.1 | ||
Support for handling alternate locales was added in SeoBundle version 1.1.0. | ||
|
||
Alternate locales are a way of telling search engines how to find translations | ||
of the current page. The SeoBundle provides a way to manage alternate locales | ||
and render them together with the other SEO information. | ||
|
||
When the alternate locale handling is set up and found alternates, you will | ||
find links like the following in the ``<head>`` part of your HTML pages: | ||
|
||
.. code-block:: html | ||
|
||
<link rel="alternate" href="/fr/le-titre" hreflang="fr"> | ||
<link rel="alternate" href="/de/der-titel" hreflang="de"> | ||
|
||
When using PHPCR-ODM, there is almost no work to do, as the bundle can use the | ||
Doctrine meta data to figure out which translations exists for a content. More | ||
information on translating content with the PHPCR-ODM is in the chapter | ||
:doc:`Doctrine PHPCR-ODM Multilanguage Support <../phpcr_odm/multilang>`. | ||
|
||
Setting Up Alternate Locale Support | ||
----------------------------------- | ||
|
||
Enable alternate locale support: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# app/config/config.yml | ||
cmf_seo: | ||
alternate_locale: ~ | ||
|
||
.. code-block:: xml | ||
|
||
<!-- app/config/config.xml --> | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services"> | ||
<config xmlns="http://cmf.symfony.com/schema/dic/seo"> | ||
<alternate-locale /> | ||
</config> | ||
</container> | ||
|
||
.. code-block:: php | ||
|
||
$container->loadFromExtension('cmf_seo', array( | ||
'alternate_locale' => true, | ||
)); | ||
|
||
If you are using PHPCR-ODM, enabling ``phpcr: ~`` in the seo bundle | ||
configuration will activate a listener that extracts the alternate locales | ||
from the PHPCR-ODM meta data. For other storage systems, you will need to | ||
write a provider and configure the bundle to use that provider - see below. | ||
|
||
Rendering Alternate Locales | ||
--------------------------- | ||
|
||
The alternate locales are rendered together with the other SEO metadata by the | ||
twig function ``sonata_seo_metadatas``. | ||
|
||
Creating a Custom Alternate Locales Provider | ||
-------------------------------------------- | ||
|
||
The alternate locale provider is asked to provide translated URLs for a content | ||
object. The bundle comes with a provider for PHPCR-ODM. For other persistence | ||
layers or custom requirements on the translated URLs you need to create your | ||
own provider implementing the ``AlternateLocaleProviderInterface``. For some | ||
inspiration, have a look at | ||
``Symfony\Cmf\Bundle\SeoBundle\Doctrine\Phpcr\AlternateLocaleProvider``. | ||
|
||
Define a service for your provider, so that you can configure the seo bundle to | ||
use your custom alternate locale provider instead of the default one. Set the | ||
``alternate_locale.provider_id`` to the service you just created: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# app/config/config.yml | ||
cmf_seo: | ||
alternate_locale: | ||
provider_id: alternate_locale.provider | ||
|
||
.. code-block:: xml | ||
|
||
<!-- app/config/config.xml --> | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services"> | ||
<config xmlns="http://cmf.symfony.com/schema/dic/seo"> | ||
<alternate-locale provider-id="alternate_locale.provider" /> | ||
</config> | ||
</container> | ||
|
||
.. code-block:: php | ||
|
||
$container->loadFromExtension('cmf_seo', array( | ||
'alternate_locale' => array ( | ||
'provider_id' => 'alternate_locale.provider', | ||
), | ||
)); | ||
|
||
.. versionadded:: 1.2 | ||
When :doc:`Sitemaps <sitemap>` are enabled, alternate locales are also | ||
added to the Sitemap. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ SeoBundle | |
seo_aware | ||
extractors | ||
sitemap | ||
alternate_locale | ||
error_pages | ||
configuration | ||
twig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing versionadded for alternate locale
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have a look into the changelog for that. I think it is available from 1.1 but i can he wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added this, it was added in version 1.1 according to the changelog, and to the versionadded note in the configuration section