Guest User

Untitled

a guest
Dec 14th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. use DrupalCoreLanguageLanguageManager;
  2. $standard_languages = LanguageManager::getStandardLanguageList();
  3.  
  4. foreach($standard_languages as $key => $val){
  5. if($val[0] == "English"){
  6. echo $key; //write your code
  7.  
  8. }
  9. }
  10.  
  11. You can do it with this function.
  12.  
  13. function getCode($find) {
  14. // Getting all the languages.
  15. $languages = Drupal::service('language_manager')->getStandardLanguageList();
  16. $code = NULL;
  17.  
  18. foreach ($languages as $code => $names) {
  19. for($i = 0; $i < count($names); $i++) {
  20. if ($names[$i] == $find) {
  21. return $code;
  22. }
  23. }
  24. }
  25. return $code;
  26. }
  27.  
  28. // Language to search.
  29. $find = 'French';
  30. // Calling the function.
  31. $code = getCode($find);
  32. // If you have the devel module installed you can use the dpm function.
  33. dpm($code);
Add Comment
Please, Sign In to add comment