demondogsl/yii2-translate-manager
Composer 安装命令:
composer require demondogsl/yii2-translate-manager
包简介
Translation management extension for Yii 2 ported to Bootstrap 5 by Cristian Garcia Copete <cristian@demondog.es>
README 文档
README
This Extension is based in lajax/yii2-translate-manager that was ported for works with Bootstrap 5 and Php 8.3 by KrishDemonDog.
Introduction
This extension provides a simple translating interface for the multilingual elements of your project. This extension offers:
- Scan - Automatically detect new elements of the language. Duplications are filtered out automatically during project scanning.
- Optimize - Unused language elements will be removed from the database.
- Import - Import your translations from
.jsonor.xmlfile. - Export - Export your translations to
.jsonor.xmlfile. - You can exclude files, folders or categories to prevent them from being translated.
Contributing
Please read and follow the instructions in the Contributing guide.
Installation
Via Composer
composer require demondogsl/yii2-translate-manager "*"
Migration
Run the following command in Terminal for database migration:
php yii migrate --migrationPath vendor/demondogsl/yii2-translate-manager/migrations
Config
Turn on the Translate Manager:
- In your project file, Yii2 Advanced
/backend/config/main.phpYii2 Basic/config/web.phpadd Translate Manager inmodules.
IMPORTANT Optional values overwrite Default Values.
'modules' => [ 'translateManager' => [ 'class' => 'DemonDogSL\translateManager\Module', // required 'root' => '@example', // optional Directory of the project scan. Can be an Array with other instances. For example: ['@backend', '@common', '@frontend']. For Default is '@app' 'allowedIPs' => ['0.0.0.0'], // optional IP addresses from which the translation interface is accessible. For Default is ['127.0.0.1'] 'roles' => ['@'], // optional For setting access levels to the translating interface. For Default is [] 'tmpDir' => '@example', // optional Writable directory for the client-side temporary javascript language files. Can be '@backend/runtime'. For Default is '@runtime' 'ignoredCategories' => ['example'], // optional These categories won't be scanned. For Default is ['yii'] 'onlyCategories' => ['example'], // optional Only these categories will be scanned. For Default is [] 'ignoredItems' => ['example'], // optional These files will not be processed. For Default is ['.svn', '.git', '.gitignore', '.gitkeep', '.hgignore', '.hgkeep', '/messages', '/BaseYii.php', 'runtime', 'bower', 'nikic'] 'tables' => [ // optional Database Tables that will be scanned. For Default not exists [ 'connection' => 'db', 'table' => '{{%example}}', // Table name 'columns' => ['example1', 'example2'], // Names of columns 'category' => 'database-table-name', ] ], ], ],
- In our migration we added table
language_force_translationfor translate your ENUM values of your tables, if you want use it only add next code.
'tables' => [ [ 'connection' => 'db', 'table' => 'language_force_translation', 'columns' => ['value'], 'category' => 'database-table-name' ] ]
- In your project file, Yii2 Advanced
/backend/config/main.phpYii2 Basic/config/web.phpadd Translate Manager incomponents.
'components' => [ 'translateManager' => [ 'class' => 'DemonDogSL\translateManager\Component' ] ]
- In your project file, Yii2 Advanced
/backend/config/main.phpYii2 Basic/config/web.phpadd Translate Manager inbootstrap.
'bootstrap' => [ 'translateManager' => [ 'class' => 'DemonDogSL\translateManager\Component' ], ],
- In your project file, Yii2 Advanced
/backend/config/main.phpYii2 Basic/config/web.phpadd I18n incomponentsand yourlanguage.
'language' => 'en-GB', 'components' => [ 'i18n' => [ 'translations' => [ '*' => [ 'class' => 'yii\i18n\DbMessageSource', 'db' => 'db', 'sourceLanguage' => 'xx-XX', // Your language 'sourceMessageTable' => '{{%language_source}}', 'messageTable' => '{{%language_translate}}', 'cachingDuration' => 86400, 'enableCaching' => true, ], ], ], ],
Usage
Register Translate Manager scripts
To translate static messages in JavaScript files it is necessary to register the files. You have two ways to do it.
Call the following method in each action:
\DemonDogSL\translateManager\helpers\Language::registerAssets();
Or create a Controller that extends Yii Controller
IMPORTANT All your Controllers must extend this New Controller
namespace backend\controllers; use DemonDogSL\translateManager\helpers\Language; class Controller extends \yii\web\Controller { public function init() { Language::registerAssets(); parent::init(); } }
Activate Translate Mode
This is Optional.
Display a button to switch text to translation mode.
// Default echo \DemonDogSL\translateManager\widgets\ToggleTranslate::widget(); // If you want change position echo \DemonDogSL\translateManager\widgets\ToggleTranslate::widget([ 'position' => 'example', // optional Can be 'top-left', 'top-right', 'bottom-left' or 'bottom-right'. For Default is 'bottom-left' ]);
Examples of use
- JavaScript
ddt.t('Hello'); ddt.t('Hello {name}!', {name:'World'});
- PHP
Yii::t('example', 'Hello'); Yii::t('example', 'Hello {name}!', ['name' => 'World']);
- Translate Mode Button
IMPORTANT Translate Mode Button does not support the translation of HTML attributes
use DemonDogSL\translateManager\models\DDT; DDT::t('example', 'Hello'); DDT::t('example', 'Hello {name}!', ['name' => 'World']);
Translate Manager URL
/translateManager/language/list /translateManager/language/scan /translateManager/language/optimize /translateManager/language/import /translateManager/language/export
Change log
Please see Changelog for more information on what has changed recently.
License
Same licence as lajax/yii2-translate-manager
The MIT License (MIT). Please see License for more information.
Screenshots
Languages
Scan
Optimize
Export
Translate Interface
Translate Mode Button
Translate Mode Button Translation
Links
demondogsl/yii2-translate-manager 适用场景与选型建议
demondogsl/yii2-translate-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.61k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 09 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「module」 「extension」 「language」 「translate」 「yii2」 「bootstrap5」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 demondogsl/yii2-translate-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 demondogsl/yii2-translate-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 demondogsl/yii2-translate-manager 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Easy to use i18n translation PHP class for multi-language websites
Package for convenient work with Laravel's localization features
Store your language lines in the database, yaml or other sources
A custom URL rule class for Yii 2 which allows to create translated URL rules
Set Links with a specific language parameter
统计信息
- 总下载量: 1.61k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-20






