<?php
 class vB_Language { use vB_Trait_NoSerialize; protected static $phraseGroups = []; protected static $languageCache = []; public static function preloadPhraseGroups($phraseGroups) { if (!is_array($phraseGroups)) { self::$phraseGroups[] = $phraseGroups; } else { self::$phraseGroups = array_merge(self::$phraseGroups, $phraseGroups); } } public static function getPhraseInfo($languageId, $phraseGroups = []) { if (!$languageId) { $languageId = vB::getDatastore()->getOption('languageid'); } $phrasegroups = array_unique(array_merge(self::$phraseGroups, $phraseGroups, ['global'])); sort($phrasegroups); $params = [ 'languageid' => $languageId, 'phrasegroups' => $phrasegroups, ]; self::$phraseGroups = []; $cacheKey = md5(json_encode($params)); $phraseinfo = self::getPhraseCache($cacheKey); if (!$phraseinfo) { $phraseinfo = vB::getDbAssertor()->getRow('fetchLanguage', $params); if ($phraseinfo) { vB_Phrase::addPhrases(['global' => unserialize($phraseinfo['phrasegroup_global'])]); self::setPhraseCache($cacheKey, $phraseinfo); } } return $phraseinfo; } private static function getPhraseCache($cacheKey) { if (empty(self::$languageCache[$cacheKey])) { $result = vB_Cache::instance()->read($cacheKey); if (!empty($result)) { self::$languageCache[$cacheKey] = $result; return $result; } else { return null; } } else { return self::$languageCache[$cacheKey]; } } private static function setPhraseCache($cacheKey, $data) { self::$languageCache[$cacheKey] = $data; vB_Cache::instance()->write($cacheKey, $data, false, 'vB_Language_languageCache'); } } 