/**
* @param string $lang
* @param bool $force
* @return array|null|string
*
* @throws \Jarves\Exceptions\BundleNotFoundException
*/
public function loadMessages($lang = 'en', $force = false)
{
if (!$this->isValidLanguage($lang)) {
$lang = 'en';
}
if ($this->messages && isset($this->messages['__lang']) && $this->messages['__lang'] == $lang && $force == false) {
return null;
}
if (!$lang) {
return null;
}
$code = 'core/lang/' . $lang;
$this->messages = $this->cacher->getFastCache($code);
$md5 = '';
$bundles = array();
foreach ($this->jarves->getBundles() as $bundleName => $bundle) {
$path = $bundle->getPath();
if ($path) {
$path .= "/Resources/translations/{$lang}.po";
if (file_exists($path)) {
$md5 .= @filemtime($path);
$bundles[] = $bundleName;
}
}
}
$md5 = md5($md5);
if (!$this->messages || count($this->messages) == 0 || !isset($this->messages['__md5']) || $this->messages['__md5'] != $md5) {
$this->messages = array('__md5' => $md5, '__plural' => $this->getPluralForm($lang), '__lang' => $lang);
foreach ($bundles as $key) {
$file = $this->jarves->resolvePath("@{$key}/{$lang}.po", 'Resources/translations');
$po = $this->getLanguage($file);
$this->messages = array_merge($this->messages, $po['translations']);
}
$this->cacher->setFastCache($code, $this->messages);
}
include_once $this->getPluralPhpFunctionFile($lang);
return $this->messages;
}