承接 demondogsl/yii2-translate-manager 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

Latest Version on Packagist Software License Total Downloads

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 .json or .xml file.
  • Export - Export your translations to .json or .xml file.
  • 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.php Yii2 Basic /config/web.php add Translate Manager in modules.

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_translation for 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.php Yii2 Basic /config/web.php add Translate Manager in components.
'components' => [
    'translateManager' => [
        'class' => 'DemonDogSL\translateManager\Component'
    ]
]
  • In your project file, Yii2 Advanced /backend/config/main.php Yii2 Basic /config/web.php add Translate Manager in bootstrap.
'bootstrap' => [
    'translateManager' => [
        'class' => 'DemonDogSL\translateManager\Component'
    ],
],
  • In your project file, Yii2 Advanced /backend/config/main.php Yii2 Basic /config/web.php add I18n in components and your language.
'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

Languages

Scan

Scan

Optimize

Optimize

Export

Export

Translate Interface

Translate_Interface

Translate Mode Button

Translate_Mode_Button

Translate Mode Button Translation

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 demondogsl/yii2-translate-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.61k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 22
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-20