mirror of
https://github.com/scummvm/scummvm-web.git
synced 2026-05-21 05:40:47 +00:00
WEB: Load localized data in models
This commit is contained in:
@@ -7,6 +7,8 @@ use Phpfastcache\Exceptions\PhpfastcacheDriverException;
|
||||
|
||||
abstract class BasicModel
|
||||
{
|
||||
const FILE_NOT_FOUND = 'The filename %s could not be found';
|
||||
|
||||
protected static $cache;
|
||||
|
||||
public function __construct()
|
||||
@@ -23,6 +25,22 @@ abstract class BasicModel
|
||||
}
|
||||
}
|
||||
|
||||
protected function getLocalizedFile($filename) {
|
||||
global $lang;
|
||||
if (!$lang) {
|
||||
$lang = DEFAULT_LOCALE;
|
||||
}
|
||||
$localizedFilename = DIR_DATA . "/$lang/$filename";
|
||||
$defaultFilename = DIR_DATA . "/" . DEFAULT_LOCALE . "/$filename";
|
||||
if (is_file($localizedFilename) && is_readable($localizedFilename)) {
|
||||
return $localizedFilename;
|
||||
} elseif (is_file($defaultFilename) && is_readable($defaultFilename)) {
|
||||
return $defaultFilename;
|
||||
} else {
|
||||
throw new \ErrorException(\sprintf(self::FILE_NOT_FOUND, $filename));
|
||||
}
|
||||
}
|
||||
|
||||
protected function saveToCache($data, $key = '')
|
||||
{
|
||||
if ($key) {
|
||||
|
||||
Reference in New Issue
Block a user