public static function videojs_utility::resolveLanguage in Video.js (HTML5 Video Player) 7.3
Tries to find a language based on the input
Parameters
$input: String containing a language code or language name.
Return value
NULL if nothing found, array with code and name if found.
1 call to videojs_utility::resolveLanguage()
- videojs_field_formatter_view in ./
videojs.module - Implements hook_field_formatter_view().
File
- includes/
videojs.utility.inc, line 147 - This file will be used to keep all utility functions.
Class
- videojs_utility
- Helper functions for the Video.js module.
Code
public static function resolveLanguage($input) {
if (empty($input) || !is_string($input)) {
return NULL;
}
$input = trim($input);
if (strlen($input) < 2) {
return NULL;
}
include_once DRUPAL_ROOT . '/includes/iso.inc';
$languages = _locale_get_predefined_list();
// Try to match on language code.
if (strlen($input) === 2 && isset($languages[strtolower($input)])) {
$input = strtolower($input);
return array(
$input,
isset($languages[$input][1]) ? $languages[$input][1] : $languages[$input][0],
);
}
// Try to match on English or native language name.
foreach ($languages as $code => $lang) {
if ($lang[0] === $input || isset($lang[1]) && $lang[1] === $input) {
return array(
$code,
$input,
);
}
}
return NULL;
}