HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers33/bbec.nl/app/Komma/Translations/Translation.php
<?php

namespace Komma\Translations;


class Translation extends \Komma\Kms\Translations\Models\Translation
{

    protected $translations;

    public function __construct()
    {
        parent::__construct();
    }


    //load translations into $this->translations
    private function loadTranslations(){

        //if $this->translations is filled return
        if(isset($this->translations)) return;

        //Get the set language of the app

        $translations = Translation::where('language_id', 104)
            ->select('code_name', 'translation')
            ->get();

        //push to the translation on codeName as objects
        $translationsObject = (object)[];
        foreach ($translations as $translation){
            $codename = $translation->code_name;
            $translationsObject->$codename = $translation->translation;
        }
        $this->translations = $translationsObject;
    }

    public function get($codeName)
    {
        $this->loadTranslations();

        //check if codename exists in the db translations else get the app translations
        if(isset($this->translations->$codeName) && $this->translations->$codeName != '' && $this->translations->$codeName != null) return $this->translations->$codeName;
        else return $trans = trans('translations.'.$codeName);
    }

    public function has($codeName)
    {
        $this->loadTranslations();

        if( ! isset($this->translations->$codeName)) return false;
        if ($this->translations->$codeName == null) return false;
        if ($this->translations->$codeName == '') return false;
        return true;
    }
}