ippey / weglot-integration
WEGLOT集成
0.2.0
2021-01-04 03:12 UTC
Requires
- craftcms/cms: ^3.0.0
- weglot/weglot-php: ^1.0
Requires (Dev)
- codeception/codeception: ^3.0
- vlucas/phpdotenv: ^3.0
This package is auto-updated.
Last update: 2024-09-19 22:35:23 UTC
README
Weglot集成
要求
此插件需要Craft CMS 3.0.0-beta.23或更高版本。您还需要Weglot账户。
安装
要安装此插件,请按照以下说明操作。
-
打开您的终端并转到Craft项目目录
cd /path/to/project
-
然后告诉Composer加载插件
composer require Ippey/weglot-integration
-
在控制面板中,转到设置 → 插件,然后点击“安装”按钮以安装weglot-integration。
weglot-integration概述
此插件通过Weglot提供轻松切换语言的功能。Weglot会自动翻译,而不是您手动操作。

配置
您需要从Weglot仪表板获取API密钥,并在设置页面保存它。此插件使用“JavaScript集成”。当您设置Weglot项目时,请点击“使用JavaScript集成”。
如何使用
Twig扩展
自动翻译
更新 您不需要使用Twig过滤器。此插件会自动添加script标签。
您可以在页面右下角看到语言切换器。如果您切换到其他语言,页面将自动翻译。
手动翻译
如果您想手动翻译,请使用以下Twig过滤器。
{{ '攻殻機動隊' | weglot_translate('ja', 'en') }}
Ghost in the Shell.
服务
您也可以在PHP代码中使用插件的服务进行翻译。
$text = 'Spirited Away'; $from = 'en'; $to = 'ja'; $translated = \ippey\weglotintegration\Weglotintegration::getInstance()->weglotService->translate($text, $from, $to); echo ($translated); // 千と千尋の神隠し