2017-10-17 35 views
0

我想顯示在阿拉伯語中的國家列表,如標題中提到的,它在localhost上正常工作,但不在我的遠程服務器上!
我在config.yml阿拉伯設置爲默認語言:Symfony:CountryType翻譯在遠程服務器上不起作用

parameters: 
    locale: ar 

framework: 
    #esi: ~ 
    translator: { fallbacks: ['%locale%'] } 

這是本地機器上的名單:
enter image description here 這是我所得到的遠程服務器上:
enter image description here 這是我的FormType:

public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     $builder 
      ->add('fullName', TextType::class, array(
       'required' => true, 
      )) 
      ->add('email', EmailType::class, array(
       'required' => true, 
      )) 
      ->add('country', CountryType::class) 
      ->add($builder->create(
       'birthday', TextType::class, array(
        'required' => false, 
       )) 
       ->addModelTransformer(new DateTransformer('Y-m-d')) 
      ) 
      ->add('username', TextType::class, array(
       'required' => true, 
      )) 
      ->add('password', PasswordType::class, array(
       'required' => true, 
      )) 
     ; 

     if($builder->getData()->getId() != null){ 
      $builder->add('image', AttachmentWithoutDescriptionType::class); 
     } 
    } 

我在這裏錯過了什麼?

回答

0

請檢查遠程服務器上的php.ini文件中是否有以下參數值:intl.default_locale。 CountryType使用Locale::getDefault()來猜測用戶的語言環境。

如果您使用的是Apache Web服務器,您可以在您的.htaccess文件中放置一個參數來覆蓋php.ini的值。

php_value intl.default_locale ar_AR 

或者乾脆硬編碼值到您的前端控制器(app.php,app_dev.php和命令)

\Locale::setDefault('ar_AR'); 

如果您需要的語言環境動態變化,你應該實現一個區域監聽器,並設置所需的語言環境使用下面的代碼片段。

+0

以及如何更改它而不觸及'php.ini'?我無法訪問它。我如何強制CountryType始終使用阿拉伯語言? – SlimenTN

+0

更新了我的答案。 –

+0

當我在app_dev.php中對其進行硬編碼時,出現此錯誤:'Symfony \ Component \ Intl \ Locale \ Locale :: setDefault()未實現。請安裝「intl」擴展程序以獲得完整的本地化功能。# – SlimenTN