igor-benko-pimcore-plugin / language-switcher
A Pimcore plugin for easier switching between languages in document hierarchies
Installs: 407
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 1
Forks: 1
Open Issues: 2
Type:pimcore-plugin
Requires
- php: >=5.4.0
- pimcore/installer-plugin: >=1
Requires (Dev)
- symfony/yaml: >=2.6.4
This package is auto-updated.
Last update: 2024-11-15 22:19:46 UTC
README
LanguageSwitcher is a Pimcore plugin that makes managing multi-lingual websites a whole lot easier and straightforward. Its main function is to find related nodes in parallel branches and to easily create menus for jumping to the same subpage in other languages - in the frontend and in the backend.
Switching between branches is very easy. You can also open current page in all languages at once.
If there is no coressponding page in other branch, then the parent node is returned.
Frontend language menu
Integrating language menu to your website is as easy as adding this to view:
// This example links to parallel pages but has a label of a branch (eg. En, It, De, ...) <ul> <?php $languageSwitcher = new LanguageSwitcher\Switcher($this->document); foreach ($languageSwitcher->getEntries() as $entry) { $path = $entry->getPath(); $isActiveClass = $entry->isActive()?"active":""; echo "<li class=\"{$isActiveClass}\"><a href=\"{$path}\">" . $entry->getBranchLabel() . "</a></li>"; } ?> </ul>
// This example links to parallel pages and has a label of a parallel page (eg. Contacts, Contatti, Kontakt, ...) <ul> <?php $languageSwitcher = new LanguageSwitcher\Switcher($this->document); foreach ($languageSwitcher->getEntries() as $entry) { $path = $entry->getPath(); $isActiveClass = $entry->isActive()?"active":""; echo "<li class=\"{$isActiveClass}\"><a href=\"{$path}\">" . $entry->getLabel() . "</a></li>"; } ?> </ul>
// You can use any other property to display <ul> <?php $languageSwitcher = new LanguageSwitcher\Switcher($this->document); foreach ($languageSwitcher->getEntries() as $entry) { $path = $entry->getPath(); $isActiveClass = $entry->isActive()?"active":""; echo "<li class=\"{$isActiveClass}\"><a href=\"{$path}\">"; if ($entry->isActive()) { echo $entry->getLabel(); } else { echo $entry->getPage()->getProperty("shortLabel"); } echo "</a></li>"; } ?> </ul>
Switching between branches in the backend
You can either switch/open just one language or open a page in all languages at once. This makes it very easy to edit one page in multiple languages.
Installing
Add this line to the require
section of your composer.json and install it with composer:
"igor-benko-pimcore-plugin/language-switcher": "dev-master"
Install it from Extension manager:
This adds predefined property for selecting branch roots and website setting for selecting the parent node.
Set parent node
If your language structure is like this you don't need to change the parent node:
Home:
- en
- de
- it
If you have language nodes in a subfolder like this than you need to set it as a parent node in Website Settings:
Home:
- languages
- en
- de
- it
Set branch roots
Branch roots must be direct descendants of the parent node. You need to add a property with key languageSwitcherBranchRoot
to each branch root.
The property MUST be inheritable. Plugin setup procedure creates a predefined property for you that you can use. After you create the property, drag and drop the branch root to Value field of property.
Copyright and license
Developed by: Igor Benko
License: BSD-3-Clause