Laravel语言翻译在第一个路径上没有加载



我一直在本地化项目中工作,在我的应用程序中,语言翻译文件没有在某些页面中加载。我不知道loadPath函数有什么问题。在我的应用程序用户可以改变那里的语言配置文件部分和变化的工作完美地在同一会话。但是当用户注销并登录到应用程序时,用户没有看到他/她的首选语言。

这里是我的代码

protected function loadPath($path, $locale, $group)
{
    if ( App::runningInConsole() ) {
        return parent::loadPath( $path, $locale, $group );
    }
    $domain  =  get_subdomain();
    $dir  =  "lang/{$locale}/{$domain}";
    $key  =  $dir.'/'.$group.'.php';

    if(Session::has($key)){
        $results = Session::get($key);
        $d = json_encode($results);
        view::share('lang',$d);
        return $results;
    }else{
        $this->s3 = App::make('aws')->factory(tenent_aws_config())->get('s3');
        $domain = get_subdomain();
        $bucket = "localbulkload";
        $dir = "lang/{$locale}/{$domain}";
        $langList = $this->s3->getIterator('ListObjects',[
            "Bucket"    => $bucket,
            'Prefix' => "lang/$locale/{$domain}"
        ]);
        foreach ($langList as $langObject){
            $object = $this->s3->getObject([
                "Bucket" => $bucket,
                "Key" => $langObject['Key']
            ]);
            $key = $langObject['Key'];
            $string = ($object['Body']);
            $results = eval("?>$string");
            Session::put($key,$results,60);
        }
        $info = $this->s3->doesObjectExist(
            $bucket,
            $dir . "/" . $group . ".php");
        if ($info === false) {
            if($this->files->exists($full = "{$path}/template/{$group}.php")) {
                $results = $this->files->getRequire($full);
                $d = json_encode($results);
                view::share('lang',$d);
                return $results;
            }
            else{
                $this->files->exists($full = "{$path}/en/{$group}.php");
                $results = $this->files->getRequire($full);
                $d = json_encode($results);
                view::share('lang',$d);
                return $results;
            }
        }
    }
    return array();
}

我该如何解决这个问题?

我发现一些不需要的语言文件加载到我的函数,我删除它们,我只按需加载文件。现在它工作得很好。这是我的工作代码

protected function loadPath($path, $locale, $group)
{
    if (App::runningInConsole()) {
        return parent::loadPath($path, $locale, $group);
    }

    $domain  =  get_subdomain();
    $dir  =  "lang/{$locale}/{$domain}";
    $key  =  $dir.'/'.$group.'.php';
    if(Session::has($key)){
        $results = Session::get($key);
        $d = json_encode($results);
        view::share('lang',$d);
        return $results;
    }else{
        $this->s3 = App::make('aws')->factory(tenent_aws_config())->get('s3');
        $domain = get_subdomain();
        $bucket = "localbulkload";
        $dir = "lang/{$locale}/{$domain}";
        $info = $this->s3->doesObjectExist(
            $bucket,
            $dir . "/" . $group . ".php");
        if($info ){
            $object = $this->s3->getObject([
                "Bucket" => $bucket,
                "Key" => $dir . "/" . $group . ".php"
            ]);
            $key = $object['Key'];
            $string = ($object['Body']);
            $results = eval("?>$string");
            Session::put($key,$string);
            $d = json_encode($results);
            view::share('lang',$d);
            return $results;
        }
        else{
            if($this->files->exists($full = "{$path}/template/{$group}.php")) {
                $results = $this->files->getRequire($full);
                $d = json_encode($results);
                view::share('lang',$d);
                return $results;
            }
            else{
                $this->files->exists($full = "{$path}/en/{$group}.php");
                $results = $this->files->getRequire($full);
                $d = json_encode($results);
                view::share('lang',$d);
                return $results;
            }
        }
    }
    return array();
}

最新更新