Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use DrupalCoreLanguageLanguageManager;
- $standard_languages = LanguageManager::getStandardLanguageList();
- foreach($standard_languages as $key => $val){
- if($val[0] == "English"){
- echo $key; //write your code
- }
- }
- You can do it with this function.
- function getCode($find) {
- // Getting all the languages.
- $languages = Drupal::service('language_manager')->getStandardLanguageList();
- $code = NULL;
- foreach ($languages as $code => $names) {
- for($i = 0; $i < count($names); $i++) {
- if ($names[$i] == $find) {
- return $code;
- }
- }
- }
- return $code;
- }
- // Language to search.
- $find = 'French';
- // Calling the function.
- $code = getCode($find);
- // If you have the devel module installed you can use the dpm function.
- dpm($code);
Add Comment
Please, Sign In to add comment