wandi/i18n-bundle

WandiI18nBundle

安装: 70

依赖: 0

建议者: 0

安全性: 0

星标: 2

关注者: 5

分支: 0

公开问题: 0

类型:symfony-bundle

1.0.2 2020-12-21 17:17 UTC

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();