我一直在进行本地化项目,在我的应用中,某些页面中没有加载语言翻译文件。我不知道我的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();
}
我该如何解决这个问题?
答案 0 :(得分:0)
我在我的功能上发现了一些不需要的语言文件,我将其删除,我只按需加载文件。现在它的工作正常。这是我的工作代码
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();
}