https://github.com/overtrue/translator
PHP多语言支持工具
https://github.com/overtrue/translator
Last synced: 3 months ago
JSON representation
PHP多语言支持工具
- Host: GitHub
- URL: https://github.com/overtrue/translator
- Owner: overtrue
- License: mit
- Created: 2014-09-16T04:11:02.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2019-07-15T06:52:11.000Z (over 6 years ago)
- Last Synced: 2025-04-04T20:09:33.754Z (9 months ago)
- Language: PHP
- Size: 8.79 KB
- Stars: 38
- Watchers: 3
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Translator
==========
PHP多语言支持工具
## Usage
1. 目录结构举例:
```shell
app/
|-- i18n/
| |-- zh_CN/
| | |-- all.php # return array('key' => 'pattern');
| |-- en_US/
...
```
2. 在字符串中使用变量:
```php
//app/i18n/en_US/all.php
pattern
'user_not_exists' => 'user {name} not exists.',
...
);
```
3. 使用Translator:
```php
trans('user_not_exists.', ['name' => $username]);
// output: 'user overtrue not exists.'
//格式化指定的字符串:
echo $translator->format('user {name} not exists.', ['name' => $username]);
// output: 'user overtrue not exists.'
```
## PHP 扩展包开发
> 想知道如何从零开始构建 PHP 扩展包?
>
> 请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— [《PHP 扩展包实战教程 - 从入门到发布》](https://learnku.com/courses/creating-package)
##License
MIT