function LocaleFileManager::getInterfaceTranslationFiles
Get interface translation files present in the translations directory.
Parameters
array $projects: (optional) Project names from which to get the translation files and history. Defaults to all projects.
array $langcodes: (optional) Language codes from which to get the translation files and history. Defaults to all languages.
Return value
array An array of interface translation files keyed by their URI.
File
-
core/
modules/ locale/ src/ File/ LocaleFileManager.php, line 53
Class
- LocaleFileManager
- Provide Locale File helper methods.
Namespace
Drupal\locale\FileCode
public function getInterfaceTranslationFiles(array $projects = [], array $langcodes = []) : array {
\Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.compare');
$files = [];
$projects = $projects ?: array_keys($this->localeProjectStorage
->getProjects());
$langcodes = $langcodes ?: array_keys(locale_translatable_language_list());
// Scan the translations directory for files matching a name pattern
// containing a project name and language code: {project}.{langcode}.po or
// {project}-{version}.{langcode}.po.
// Only files of known projects and languages will be returned.
$directory = TranslationsStream::basePath();
$result = [];
if (is_dir($directory)) {
$result = $this->fileSystem
->scanDirectory($directory, '![a-z_]+(\\-[0-9a-z\\.\\-\\+]+|)\\.[^\\./]+\\.po$!', [
'recurse' => FALSE,
]);
}
foreach ($result as $file) {
// Recreate file object, detect the project name and version from the file
// name.
$file = LocaleFile::createFromPath($file->filename, $file->uri);
if (in_array($file->project, $projects) && in_array($file->langcode, $langcodes)) {
$files[$file->uri] = $file;
}
}
return $files;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.