function outdatedbrowser_get_language_file_path in Outdated Browser 8
Same name and namespace in other branches
- 7 outdatedbrowser.module \outdatedbrowser_get_language_file_path()
Gets the path of the appropriate language file of Outdated Browser plugin.
1 call to outdatedbrowser_get_language_file_path()
- outdatedbrowser_page_attachments in ./
outdatedbrowser.module - Implements hook_page_attachments().
File
- ./
outdatedbrowser.module, line 57 - Outdated Browser module file.
Code
function outdatedbrowser_get_language_file_path() {
$result = '';
$config = \Drupal::config('outdatedbrowser.settings');
if (!($library_path = $config
->get('lang_files_path'))) {
$library_path = 'libraries/outdated-browser/outdatedbrowser/lang';
//TODO - get the libraries path with some function
}
$langfile_pattern = $library_path . "/%s.html";
$current_language = \Drupal::languageManager()
->getCurrentLanguage();
$default_language = \Drupal::languageManager()
->getDefaultLanguage();
if (file_exists(\Drupal::service('file_system')
->realpath(sprintf($langfile_pattern, $current_language
->getId())))) {
// A translation file for the active interface language was found.
$result = sprintf($langfile_pattern, $current_language
->getId());
}
elseif (file_exists(\Drupal::service('file_system')
->realpath(sprintf($langfile_pattern, $default_language
->getId())))) {
// A translation file for the default system language was found (fallback).
$result = sprintf($langfile_pattern, $default_language
->getId());
}
elseif (file_exists(\Drupal::service('file_system')
->realpath(sprintf($langfile_pattern, 'en')))) {
// An english translation file was found (second and last fallback method).
$result = sprintf($langfile_pattern, 'en');
}
return $result;
}