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/SBogers10/zuiderbos.komma.pro/app/Komma/Translations/Translation.php
<?php

namespace Komma\Translations;

use Komma\LanguageService;

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
        $languageService = new LanguageService();
        $lang = $languageService->getCurrentLanguageId();

        $translations = self::where('language_id', $lang)
            ->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;
    }
}