rainbowmorel

第 558 位会员

会员
个人信息
  • 加入于 2018-06-26 09:40:29
  • 最后登录时间 3个月前
个人成就
  • 发表文章次数 6
  • 发布回复次数 5
  • 个人主页浏览次数 0
appapi模块 翻译无法使用4个月前

给小程序用的。。 原来是用 appserver ...

appapi模块 翻译无法使用4个月前

appfront是可以翻译出来

appapi模块 翻译无法使用4个月前
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/26
 * Time: 14:35
 */

namespace appapi\local\local_modules\Xcx\controllers;


use fec\helpers\CRequest;
use fecshop\app\appapi\modules\AppapiController;
use Yii;
use yii\base\Application;

class ProductController extends AppapiController
{
    public function actionIndex()
    {
        $params = CRequest::param();
        $id = $params['id'];
        $product = Yii::$service->product->getByPrimaryKey($id);
        $product = $product->attributes;

        foreach ($product['image']['gallery'] as $key => $item) {
            $product['image']['gallery'][$key]['image'] = Yii::$service->product->image->getUrl($item['image']);
        }

        $product['custom_option_attr_group'] = Yii::$service->product->getCustomOptionAttrInfo($product['attr_group']);

        Yii::$service->page->translate->category = 'appfront';
        Yii::$app->language = 'zh_CN';

        foreach ($product['custom_option_attr_group'] as $attr => $v_info) {
            var_dump( Yii::$service->page->translate->__(ucwords(str_replace("-"," ",str_replace("_"," ",$attr))).':'));
            exit();
            $product['custom_option_attr_group'][$attr]['label'] =  Yii::$service->page->translate->__(ucwords(str_replace("-"," ",str_replace("_"," ",$attr))).':');
        }



        echo json_encode([
            'product' => $product
        ]);
        exit();
    }
}






























appapi/config/mian.php

<?php

$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
);

return [
    'id' => 'app-api',
    // 设置时区,查看php 支持的所支持的时区列表  :http://www.php.net/manual/zh/timezones.php
    'timeZone' => 'UTC',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'appapi\controllers',
    'modules' => $modules,
    //'bootstrap' => ['log'],
    //'bootstrap'    => ['assetsAutoCompress'],
    // 自定义组件
    'components' => [
        /*
        'assetsAutoCompress' =>
         [
             'class'             => '\skeeks\yii2\assetsAuto\AssetsAutoCompressComponent',
             'enabled'           => true,
             'jsCompress'        => true,
             'cssFileCompile'    => true,
             'jsFileCompile'     => true,
         ],
         */
        'session' => [
            /*
             * // use mongodb for session.
             * 'class' => 'yii\mongodb\Session',
             * 'db' => 'mongodb',
             * 'sessionCollection' => 'session',
             */
            'class' => 'yii\redis\Session',
            'timeout' => 86400 * 7,
            'keyPrefix' => 'appapi_session',
            'redis' => [
                'database' => 3,
            ],
        ],
        'cache' => [
            /*
             * // use mongodb for cache.
             * 'class' => 'yii\mongodb\Cache',
             */
            'class' => 'yii\redis\Cache',
            'keyPrefix' => 'appapi_cache',
            'redis' => [
                'database' => 4,
            ],
        ],
        'user' => [
            // 【默认】不开启速度限制的 User Model
            'identityClass' => 'fecshop\models\mysqldb\AdminUser',
            // 开启速度限制的 User Model
            //'identityClass' => 'fecshop\models\mysqldb\adminUser\AdminUserAccessToken',

            //'enableAutoLogin' => true,
        ],
        'i18n' => [
            'translations' => [
                'appfront' => [
                    'class' => 'fecshop\yii\i18n\PhpMessageSource',
                    'basePaths' => [
                        '@appfront/languages',
                    ],
                    'sourceLanguage' => 'zh_CN', // 如果 en_US 也想翻译,那么可以改成en_XX。
                ],
            ],
        ],
    ],
    // 自定义参数
    'params' => $params,
];

Your Site Analytics