Làm thế nào để có được ngôn ngữ hiện tại site 8 | Drupal 8

Làm thế nào để có được ngôn ngữ hiện tại site 8

Submitted by editor on Fri, 11/06/2015 - 10:57
Question

làm thế Nào để có được sự hiện được chọn ngôn ngữ (hiện tại trang hay dùng ngôn ngữ) lập trình ở Drupal8 ?

Drupal 8

//Để có được những lanuage mã:
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();

 

//Để có được tên ngôn ngữ:
$language =  \Drupal::languageManager()->getCurrentLanguage()->getName();

 

Drupal 7

global $language;
$language=$language->language;

 

Comments

Navneet Singh (not verified)

Sun, 01/15/2017 - 10:18

Drupal 7:

global $language;
// return lang code;
return $language->language;

Drupal 8:

return $language = \Drupal::languageManager()->getCurrentLanguage()->getId();

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.