mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 11:48:08 +08:00
docs(translation): 添加临时语言环境设置文档
This commit is contained in:
parent
f12cc94a67
commit
a3bd38fd0d
@ -34,7 +34,7 @@ return [
|
||||
];
|
||||
```
|
||||
|
||||
## 配置语言环境
|
||||
## 配置默认语言环境
|
||||
|
||||
关于国际化组件的相关配置都是在 `config/autoload/translation.php` 配置文件里设定的,你可以按照实际需要修改它。
|
||||
|
||||
@ -52,6 +52,30 @@ return [
|
||||
];
|
||||
```
|
||||
|
||||
### 配置临时语言环境
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\Contract\TranslatorInterface;
|
||||
|
||||
class FooController
|
||||
{
|
||||
/**
|
||||
* @Inject
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
public function index()
|
||||
{
|
||||
// 只在当前请求或协程生命周期有效
|
||||
$this->translator->setLocale('zh_CN');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
# 翻译字符串
|
||||
|
||||
## 通过 TranslatorInterface 翻译
|
||||
|
Loading…
Reference in New Issue
Block a user