public function get($locale)
 {
     if (!array_key_exists($locale, $this->translations)) {
         $this->translations[$locale] = Translation::where('group_id', $this->group_id)->where('locale', $locale)->first();
     }
     return $this->translations[$locale];
 }
Пример #2
0
 public static function getTranslation($i18n_id, $locale_id = null)
 {
     $locale_id = $locale_id === null ? App::getLocale() : $locale_id;
     $cachePrefix = 'Eloquentizr::getTranslation:' . $locale_id . ':';
     if (Cache::has($cachePrefix . $i18n_id)) {
         return Cache::get($cachePrefix . $i18n_id);
     }
     $translation = Translation::where('i18n_id', '=', $i18n_id)->where('locale_id', '=', $locale_id)->first();
     if (empty($translation)) {
         $text = null;
     } else {
         $text = $translation->text;
     }
     Cache::put($cachePrefix . $i18n_id, $text, 60);
     return $text;
 }
 public static function bootTranslatable()
 {
     static::deleted(function ($model) {
         Translation::where('model', '=', get_class($model))->where('model_id', '=', $model->id)->delete();
     });
 }
Пример #4
0
 /**
  * Additional Method
  *
  * @var string
  */
 public function translate($i18n_id)
 {
     return Translation::where('i18n_id', '=', $i18n_id)->where('locale_id', '=', App::getLocale())->first()->text;
 }