wandi/i18n-bundle
WandiI18nBundle
1.0.2
2020-12-21 17:17 UTC
Requires
- php: >=5.5.0
- doctrine/common: ~2.7
- symfony/framework-bundle: ~3.0|~4.0
- symfony/property-access: ~3.0|~4.0
This package is auto-updated.
Last update: 2024-09-22 01:41:30 UTC
README
Wandi/I18nBundle 是一个用于辅助项目国际化的 Symfony 扩展包。
设置
通过 composer 安装
$ composer require wandi/i18n-bundle
注册扩展包
$bundles = [ // ... new \Wandi\I18nBundle\WandiI18nBundle(), ];
使用方法
实体
- 在你的实体中添加 TranslatableEntity 特性。
- 根据需要为每种使用的语言创建多个字段。
class Foo { use TranslatableEntity; // ... /** * @var string * * @ORM\Column(name="bar_fr", type="string", length=255) */ private $barFr; /** * @var string * * @ORM\Column(name="bar_en", type="string", length=255) */ private $barEn; }
视图和控制器
- 该特性将根据当前使用的语言自动使用正确的获取器。
视图
{{ Foo.bar }}
控制器
$foo->getBar();