BUG Fix i18nTextCollector restriction to specific modules

i18nTextCollector takes an argument to restrict text collection to specific modules.
This used to restrict by limiting the modules scanned by the text collector. But
modules can actually provide translations for other modules (see for e.g.
CMSMenu#provideI18nEntities)

This patch changes the text collector to scan all modules, and then apply the restriction
to the output
This commit is contained in:
Hamish Friedlander 2012-07-25 11:39:39 +12:00
parent dc18c51f32
commit b25b45aab4

View File

@ -75,21 +75,12 @@ class i18nTextCollector extends Object {
public function run($restrictToModules = null) { public function run($restrictToModules = null) {
//Debug::message("Collecting text...", false); //Debug::message("Collecting text...", false);
$modules = array(); $modules = scandir($this->basePath);
$themeFolders = array(); $themeFolders = array();
// A master string tables array (one mst per module) // A master string tables array (one mst per module)
$entitiesByModule = array(); $entitiesByModule = array();
//Search for and process existent modules, or use the passed one instead
if($restrictToModules && count($restrictToModules)) {
foreach($restrictToModules as $restrictToModule) {
$modules[] = basename($restrictToModule);
}
} else {
$modules = scandir($this->basePath);
}
foreach($modules as $index => $module){ foreach($modules as $index => $module){
if($module != 'themes') continue; if($module != 'themes') continue;
else { else {
@ -145,6 +136,13 @@ class i18nTextCollector extends Object {
} }
} }
// Restrict modules we update to just the specified ones (if any passed)
if($restrictToModules && count($restrictToModules)) {
foreach (array_diff(array_keys($entitiesByModule), $restrictToModules) as $module) {
unset($entitiesByModule[$module]);
}
}
// Write each module language file // Write each module language file
if($entitiesByModule) foreach($entitiesByModule as $module => $entities) { if($entitiesByModule) foreach($entitiesByModule as $module => $entities) {
$this->getWriter()->write($entities, $this->defaultLocale, $this->baseSavePath . '/' . $module); $this->getWriter()->write($entities, $this->defaultLocale, $this->baseSavePath . '/' . $module);