nlybe/multilingual

Multilingual content on Elgg posts and content

5.3 2024-02-05 22:46 UTC

This package is auto-updated.

Last update: 2024-04-05 23:24:32 UTC


README

Elgg 5.0

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:

  1. 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.

  1. 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);