Skip to content
Snippets Groups Projects
Commit a195533e authored by Markus Beh's avatar Markus Beh Committed by Demian Katz
Browse files

Add ability to use theme-specific language files.

Wording definitions from parent themes will be inherited
or overwritten respecting the theme inheritance hierarchy.
parent 09a65ec7
No related merge requests found
......@@ -187,6 +187,24 @@ class Manager
return $this->directoryCreationError;
}
/**
* Create a new file cache for the given theme name if neccessary. Return
* the name of the cache.
*
* @param string $themeName Name of the theme
*
* @return string
*/
public function addLanguageCacheForTheme($themeName)
{
$cacheName = 'languages-' . $themeName;
$this->createFileCache(
$cacheName,
$this->getCacheDir() . 'languages/' . $themeName
);
return $cacheName;
}
/**
* Create a "no-cache" setting.
*
......
......@@ -91,6 +91,18 @@ class ExtendedIni implements FileLoaderInterface
$this->reader = ($reader === null) ? new ExtendedIniReader() : $reader;
}
/**
* Add additional directories to the path stack.
*
* @param array|string $pathStack Path stack addition(s).
*
* @return void
*/
public function addToPathStack($pathStack)
{
$this->pathStack = array_merge($this->pathStack, (array)$pathStack);
}
/**
* Load method defined by FileLoaderInterface.
*
......
......@@ -385,5 +385,56 @@ class Initializer
$current->setPaths($templatePathStack);
}
}
// Add theme specific language files for translation
$this->updateTranslator($themes);
}
/**
* Support method for setUpThemes() - add theme specific language files for
* translation.
*
* @param array $themes Theme configuration information.
*
* @return void
*/
protected function updateTranslator($themes)
{
$pathStack = [];
foreach (array_keys($themes) as $theme) {
$dir = APPLICATION_PATH . '/themes/' . $theme . '/languages';
if (is_dir($dir)) {
$pathStack[] = $dir;
}
}
if (!empty($pathStack)) {
try {
$translator = $this->serviceManager->get('VuFind\Translator');
$pm = $translator->getPluginManager();
$pm->get('extendedini')->addToPathStack($pathStack);
} catch (\Zend\Mvc\Exception\BadMethodCallException $e) {
// This exception likely indicates that translation is disabled,
// so we can't proceed.
return;
}
// Override the default cache with a theme-specific cache to avoid
// key collisions in a multi-theme environment.
try {
$cacheManager = $this->serviceManager->get('VuFind\CacheManager');
$cacheName = $cacheManager->addLanguageCacheForTheme($theme);
$translator->setCache($cacheManager->getCache($cacheName));
} catch (\Exception $e) {
// Don't let a cache failure kill the whole application, but make
// note of it:
$logger = $this->serviceManager->get('VuFind\Logger');
$logger->debug(
'Problem loading cache: ' . get_class($e) . ' exception: '
. $e->getMessage()
);
}
}
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment