nlybe / multilingual
Elgg帖子内容的多语言内容
5.3
2024-02-05 22:46 UTC
Requires
- php: >=7.2
- composer/installers: >=1.0.8
Conflicts
- elgg/elgg: <5.0
README
Elgg帖子内容的多语言内容。
特性
- 在插件设置中启用页面(pages插件)的多语言内容选项
- 在插件设置中启用站点页面(externalpages插件)的多语言内容选项
- 与外部页面扩展兼容
- 可以从其他插件中用于翻译Elgg对象的特定字段
- 建议使用语言选择器插件来更改站点语言
如何使用
假设你有一个名为MyElggObject的Elgg对象,并且你需要为标题、描述和位置字段添加翻译。为了使用多语言翻译这些字段,你必须执行以下操作:
- 在start.php或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); }
此代码将在所有MyElggObject实体菜单中添加子项编辑翻译。当点击编辑翻译时,将打开一个表单,用于为站点的所有启用语言翻译标题、描述和位置字段。
- 在标题、描述和位置字段中的任何地方,执行以下替换:
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);