getAvailableLocales as protected getAvailableLocalesTranslations;
}
+ protected $_translations = [];
+
/**
* @var array
*/
public function getTranslations(string $key = null): array
{
if ($key !== null) {
+ if (isset($this->_translations[$key])) {
+ return $this->_translations[$key];
+ }
+ start_measure('Get translation of ' . $key);
$this->guardAgainstNonTranslatableAttribute($key);
$attrs = $this->getAttributes();
if (!isset($attrs[$key])) {
}
if ($key === 'slug') {
- return array_filter($v, function ($value) {
+ $res = array_filter($v, function ($value) {
return $value !== null;
});
} else {
- return array_filter($v, function ($value) {
+ $res = array_filter($v, function ($value) {
return $value !== null && $value !== '';
});
}
+ $this->_translations[$key] = $res;
+ stop_measure('Get translation of ' . $key);
+ return $res;
}
start_measure('Get all translations');
- $res= array_reduce($this->getTranslatableAttributes(), function ($result, $item) {
+ $res = array_reduce($this->getTranslatableAttributes(), function ($result, $item) {
$result[$item] = $this->getTranslations($item);
return $result;