add cache for languages, make function to laravel translate

This commit is contained in:
Milos Holba
2021-03-19 20:17:12 +01:00
parent ba7d6be249
commit c8dedd44c4
9 changed files with 119 additions and 580 deletions

View File

@@ -5,6 +5,8 @@ use App\FileManagerFolder;
use App\User;
use App\Setting;
use App\Share;
use App\Language;
use App\LanguageString;
use ByteUnits\Metric;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
@@ -802,3 +804,29 @@ function set_time_by_user_timezone($time)
return Carbon::parse($time);
}
function _t($key)
{
if (Cache::has('language_strings')) {
//Check if cash has string
$strings = Cache::get('language_strings')
->languageStrings
->toArray();
// Find the string by key
foreach($strings as $string) {
if($string['key'] === $key) {
return $string['value'];
}
}
}
$language = Language::whereLocale(get_setting('language'))
->first();
// If cash dont have string return string from database
return LanguageString::whereLangAndKey($language->locale, $key)
->first()
->value;
}