nlybe / multilingual
Multilingual content on Elgg posts and content
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:elgg-plugin
Requires
- php: >=7.2
- composer/installers: >=1.0.8
Conflicts
- elgg/elgg: <5.0
README
Multilingual content on Elgg posts and content.
Features
- Option to enable multilingual content for pages (pages plugin) in plugin settings
- Option to enable multilingual content for site pages (externalpages plugin) in plugin settings
- Compatible with External pages Extended
- It can be used from other plugins for translating specific field of Elgg Objects
- The Language selector plugin is suggested for changing site languages
How to use
Let's say that you have an Elgg Object called MyElggObject and you need to add translation for the fields title, description and location. You have to do the following in order to use the Multilingual for translating these fields:
- Add the lines below on start.php or bootstrap.php:
use Multilingual\MultilingualOptions; if (elgg_is_active_plugin('multilingual')) { $options = [ 'title' => ['type' => 'text', 'label' => 'myplugin:title', 'annotate' => false], 'description' => ['type' => 'longtext', 'label' => 'myplugin:description', 'annotate' => false], 'location' => ['type' => 'location', 'label' => 'myplugin:location', 'annotate' => false], ]; MultilingualOptions::setSubtypeForTranslation(MyElggObject::SUBTYPE, $options); }
This code will add the sub-item Edit translations on all MyElggObject entities menu. When click on Edit translations a form will open for translating the fields title, description and location for all enabled languages of the site.
- Wherever any of the fields title, description and location appear, make the following replacements:
use Multilingual\MultilingualOptions; // $title = $entity->title; # to be replaced by $title = MultilingualOptions::getFieldValue('title', $entity); // $description = $entity->description; # to be replaced by $description = MultilingualOptions::getFieldValue('description', $entity); // $location = $entity->location; # to be replaced by $location = MultilingualOptions::getFieldValue('location', $entity);