xanweb/c5-js-localization
Composer 安装命令:
composer require xanweb/c5-js-localization
包简介
Concrete5 Localization
README 文档
README
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();
xanweb/c5-js-localization 适用场景与选型建议
xanweb/c5-js-localization 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 484 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 03 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「library」 「concrete5」 「concrete5-v8」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 xanweb/c5-js-localization 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 xanweb/c5-js-localization 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 xanweb/c5-js-localization 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Inbox pattern process implementation for your Laravel Applications
A collection of useful utilities for concrete5 developers
Core library that defines common interfaces used by the rest of the intahwebz..
ConcreteCMS Common
Handle External Assets for Concrete5
ConcreteCMS Helpers Suite
统计信息
- 总下载量: 484
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-03-29