X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FTechnique.php;h=cc94327389a5d3476939c9a830398ee6fb5c3166;hb=212561cf1c6724b52c490104f5a2b4c3418b1c62;hp=2eb0a941125434b8b68712f11ad3d2c164a08209;hpb=6976d85a7117de53f7d42dee3de1f6b8fcb9726d;p=alttp.git diff --git a/app/Models/Technique.php b/app/Models/Technique.php index 2eb0a94..cc94327 100644 --- a/app/Models/Technique.php +++ b/app/Models/Technique.php @@ -4,11 +4,17 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\App; class Technique extends Model { use HasFactory; + public static function locale2lang($locale) { + if (strtolower(substr($locale, 0, 2)) == 'de') return 'de'; + return 'en'; + } + public function chapters() { return $this ->belongsToMany(Technique::class, 'technique_chapter', 'parent_id', 'child_id') @@ -28,6 +34,16 @@ class Technique extends Model return $this->hasMany(TechniqueTranslation::class); } + public function getTranslatedProperty($prop, $lang = null) { + if (is_null($lang)) $lang = App::getLocale(); + foreach ($this->translations as $translation) { + if ($translation->locale == $lang) { + return $translation->{$prop}; + } + } + return $this->{$prop}; + } + protected $casts = [ 'index' => 'boolean', 'requirements' => 'array',