定制 xanweb/c5-js-localization 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

xanweb/c5-js-localization

最新稳定版本:v2.0.1

Composer 安装命令:

composer require xanweb/c5-js-localization

包简介

Concrete5 Localization

README 文档

README

Latest Version on Packagist Software License

Pass translations and any other information from php to javascript

Installation

Include library to your composer.json

composer require xanweb/c5-js-localization

Usage

Register \Xanweb\C5\JsLocalization\ServiceProvider on package start or include it in /application/config/app.php

For Backend:

1- Add listener to BackendAssetLocalizationLoad::NAME on your package start or under /application/bootstrap/app.php:

use Xanweb\C5\JsLocalization\Event\BackendAssetLocalizationLoad;

$this->app['director']->addListener(BackendAssetLocalizationLoad::NAME, function (BackendAssetLocalizationLoad $event) {
    $event->getAssetLocalization()->mergeWith([
        'i18n' => [
            'confirm' => t('Are you sure?'),
            'maxItemsExceeded' => t('Max items exceeded, you cannot add any more items.'),
            'pageNotFound' => t('Page not found'),
            'colorPicker' => [
                'cancelText' => t('Cancel'),
                'chooseText' => t('Choose'),
                'togglePaletteMoreText' => t('more'),
                'togglePaletteLessText' => t('less'),
                'noColorSelectedText' => t('No Color Selected'),
                'clearText' => t('Clear Color Selection'),
            ]
        ],
        'editor' => [
            'initRichTextEditor' => $this->app['editor']->getEditorInitJSFunction(),
        ],
    ]);
});

2- Include the required asset to your view:

$view->requireAsset('javascript-localized', 'xw/backend');

3- You can now use your data within javascript file:

alert(xw_backend.i18n.confirm);

// Init Editor Example:
xw_backend.editor.initRichTextEditor($('#myTextareaField'));

For Frontend:

1- Add listener to FrontendAssetLocalizationLoad::NAME on your package start or under /application/bootstrap/app.php:

use Xanweb\C5\JsLocalization\Event\FrontendAssetLocalizationLoad;

$this->app['director']->addListener(FrontendAssetLocalizationLoad::NAME, function (FrontendAssetLocalizationLoad $event) {
    $event->getAssetLocalization()->mergeWith([
        'i18n' => [
            'message' => t('Are you sure?'),
        ],
        'methods' => [
            'showMessage' => 'function(){ alert("Website: ' . Core::make('site')->getSite()->getSiteName() . '"); }',
        ],
    ]);
});

2- Include the required asset to your view:

$view->requireAsset('javascript-localized', 'xw/frontend');

3- You can now use your data within javascript file:

alert(xw_frontend.i18n.message);

// Execute function:
xw_frontend.methods.showMessage();

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-03-29