File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ class Database extends Translation implements DriverInterface
1414
1515 protected $ scanner ;
1616
17+ protected array $ groupTranslationCache = [];
18+
1719 protected array $ languageCache = [];
1820
1921 public function __construct ($ sourceLanguage , $ scanner )
@@ -184,18 +186,32 @@ public function getSingleTranslationsFor($language)
184186 */
185187 public function getGroupTranslationsFor ($ language )
186188 {
187- $ translations = $ this ->getLanguage ($ language )
189+ if (isset ($ this ->groupTranslationCache [$ language ])) {
190+ return $ this ->groupTranslationCache [$ language ];
191+ }
192+
193+ $ languageModel = $ this ->getLanguage ($ language );
194+
195+ if (is_null ($ languageModel )) {
196+ return collect ();
197+ }
198+
199+ $ translations = $ languageModel
188200 ->translations ()
189201 ->whereNotNull ('group ' )
190202 ->where ('group ' , 'not like ' , '%single ' )
191203 ->get ()
192204 ->groupBy ('group ' );
193205
194- return $ translations ->map (function ($ translations ) {
206+ $ result = $ translations ->map (function ($ translations ) {
195207 return $ translations ->mapWithKeys (function ($ translation ) {
196208 return [$ translation ->key => $ translation ->value ];
197209 });
198210 });
211+
212+ $ this ->groupTranslationCache [$ language ] = $ result ;
213+
214+ return $ result ;
199215 }
200216
201217 /**
You can’t perform that action at this time.
0 commit comments