Skip to content

Commit

Permalink
Merge pull request #71 from AsgardCms/bugfix/translation-backwards-co…
Browse files Browse the repository at this point in the history
…mpatability

Fixing centralised translations and slight refactoring
  • Loading branch information
nWidart committed Nov 25, 2015
2 parents 3cb2f09 + 13d4bf6 commit c23054c
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions Providers/CoreServiceProvider.php
Expand Up @@ -193,11 +193,9 @@ protected function registerLanguageNamespace(Module $module)
if ($this->hasPublishedTranslations($langPath)) {
$this->loadTranslationsFrom($langPath, $moduleName);
}
if (array_key_exists('Translation', $this->app['modules']->enabled())) {
$translationModulePath = $this->app['modules']->find('Translation')->getPath() . "/Resources/lang/{$moduleName}";
if ($this->hasCentralisedTranslations($translationModulePath)) {
$this->loadTranslationsFrom($translationModulePath, $moduleName);
}

if ($this->moduleHasCentralisedTranslations($module)) {
$this->loadTranslationsFrom($this->getCentralisedTranslationPath($module), $moduleName);
} else {
$this->loadTranslationsFrom($module->getPath() . '/Resources/lang', $moduleName);
}
Expand Down Expand Up @@ -286,11 +284,27 @@ private function hasPublishedTranslations($path)
}

/**
* @param string $translationModulePath
* Does a Module have it's Translations centralised in the Translation module?
* @param Module $module
* @return bool
*/
private function hasCentralisedTranslations($translationModulePath)
private function moduleHasCentralisedTranslations(Module $module)
{
return is_dir($translationModulePath);
if (! array_has($this->app['modules']->enabled(), 'Translation')) {
return false;
}

return is_dir($this->getCentralisedTranslationPath($module));
}

/**
* Get the absolute path to the Centralised Translations for a Module (via the Translations module)
* @param Module $module
* @return string
*/
private function getCentralisedTranslationPath(Module $module)
{
return $this->app['modules']->find('Translation')->getPath() . "/Resources/lang/{$module->getName()}";
}
}

0 comments on commit c23054c

Please sign in to comment.