1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-13 10:15:28 +02:00

Add @LostKobrakai PR #52 - Implement a way for modules to supply translations, plus some related updates

Co-authored-by: LostKobrakai <benni@kobrakai.de>
This commit is contained in:
Ryan Cramer
2021-07-02 12:38:22 -04:00
parent 15d2982dcd
commit ccc3d1f5bb
6 changed files with 317 additions and 58 deletions

View File

@@ -4974,9 +4974,9 @@ class Modules extends WireArray {
if(!in_array($id, $this->moduleIDs)) unset($this->modulesLastVersions[$id]);
}
if(count($this->modulesLastVersions)) {
$this->wire('cache')->save(self::moduleLastVersionsCacheName, $this->modulesLastVersions, WireCache::expireReserved);
$this->wire()->cache->save(self::moduleLastVersionsCacheName, $this->modulesLastVersions, WireCache::expireReserved);
} else {
$this->wire('cache')->delete(self::moduleLastVersionsCacheName);
$this->wire()->cache->delete(self::moduleLastVersionsCacheName);
}
}
@@ -5355,6 +5355,48 @@ class Modules extends WireArray {
return $cnt;
}
/**
* Get module language translation files
*
* @param Module|string $module
* @return array Array of translation files including full path, indexed by basename without extension
* @since 3.0.181
*
*/
public function getModuleLanguageFiles($module) {
$module = $this->getModuleClass($module);
if(empty($module)) return array();
$path = $this->wire()->config->paths($module);
if(empty($path)) return array();
$pathHidden = $path . '.languages/';
$pathVisible = $path . 'languages/';
if(is_dir($pathVisible)) {
$path = $pathVisible;
} else if(is_dir($pathHidden)) {
$path = $pathHidden;
} else {
return array();
}
$items = array();
$options = array(
'extensions' => array('csv'),
'recursive' => false,
'excludeHidden' => true,
);
foreach($this->wire()->files->find($path, $options) as $file) {
$basename = basename($file, '.csv');
$items[$basename] = $file;
}
return $items;
}
/**
* Enables use of $modules('ModuleName')
*