function moment_library_moment_pre_load_locale in Moment.js 7.2
Implements callback_libraries_info__callbacks__pre-load().
1 string reference to 'moment_library_moment_pre_load_locale'
- moment_libraries_info in ./
moment.module - Implements hook_libraries_info().
File
- ./
moment.module, line 223 - Moment.js integration.
Code
function moment_library_moment_pre_load_locale(array &$library) {
if (!variable_get('preprocess_js', 0)) {
// Drupal.t() does not work without JS aggregation.
if (isset($library['integration files']['moment']['js']['js/moment.locale.js'])) {
unset($library['integration files']['moment']['js']['js/moment.locale.js']);
if (empty($library['integration files']['moment']['js'])) {
unset($library['integration files']['moment']['js']);
if (empty($library['integration files']['moment'])) {
unset($library['integration files']['moment']);
}
}
}
}
$has_locales = FALSE;
foreach (array_keys($library['files']['js']) as $file_path) {
if (preg_match('/locales(\\.min){0,1}\\.js$/', $file_path)) {
$has_locales = TRUE;
break;
}
}
if (!$has_locales) {
// Language code, e.g. ’hu’ or ’en-us’.
$lang_code = drupal_strtolower($GLOBALS['language']->language);
$file_path = "locale/{$lang_code}.js";
if (file_exists("{$library['library path']}/{$file_path}")) {
$library['files']['js'][$file_path] = [];
}
elseif (strpos($lang_code, '-') !== FALSE) {
list($lang_code) = explode('-', $lang_code);
$file_path = "locale/{$lang_code}.js";
if (file_exists("{$library['library path']}/{$file_path}")) {
$library['files']['js'][$file_path] = [];
}
}
}
}