如何将i18n学说翻译整合到zend框架中?

时间:2012-03-01 22:25:17

标签: zend-framework internationalization doctrine-orm

假设我有一个简单的实体UserType。我想usertype可用于各种语言,因为它将出现在UI的下拉列表中。我该如何设置i18n才能在我的项目中工作?在文档中并不清楚。

<?php

namespace Entities;

/**
 * @Entity (repositoryClass="Repositories\UserType") 
 * @Table(name="usertypes") 
 * @HasLifecycleCallbacks
 */
class UserType {

    /**
     * @Id @Column(type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    private $id;

    /** @Column(type="string", length=30,unique=TRUE) */
    private $usertype;

    /** @Column(type="boolean") */
    private $active;


    public function __construct() {

        $this->active = true;
    }

    /**
     * @return the $id
     */
    public function getId() {
        return $this->id;
    }

    /**
     * @return the $usertype
     */
    public function getUserType() {
        return $this->usertype;
    }

    /**
     * @return the $active
     */
    public function getActive() {
        return $this->active;
    }

    /**
     * @param field_type $usertype
     */
    public function setUsertype($usertype) {
        $this->usertype = $usertype;
    }

    /**
     * @param field_type $active
     */
    public function setActive($active) {
        $this->active = $active;
    }

}

1 个答案:

答案 0 :(得分:0)

您只需在评论区块中为可转换字段添加“@gedmo:Translatable”

<?php

namespace Entities;

/**
 * @Entity (repositoryClass="Repositories\UserType") 
 * @Table(name="usertypes") 
 * @HasLifecycleCallbacks
 */
class UserType {

    /**
     * @Id @Column(type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @gedmo:Translatable
     * @Column(type="string", length=30,unique=TRUE)
     */
    private $usertype;

    /** @Column(type="boolean") */
    private $active;

    /**
     * @gedmo:Locale
     */
    private $locale;

    public function __construct() {

        $this->active = true;
    }

    /**
     * @return the $id
     */
    public function getId() {
        return $this->id;
    }

    /**
     * @return the $usertype
     */
    public function getUserType() {
        return $this->usertype;
    }

    /**
     * @return the $active
     */
    public function getActive() {
        return $this->active;
    }

    /**
     * @param field_type $usertype
     */
    public function setUsertype($usertype) {
        $this->usertype = $usertype;
    }

    /**
     * @param field_type $active
     */
    public function setActive($active) {
        $this->active = $active;
    }

    public function setTranslatableLocale($locale)
    {
        $this->locale = $locale;
    }

}