Получить переводчик

@internal
@return \Zend_Translate
197690
public function getTranslator()
    {
        if (!$this->_translator) {

			$this->_translator = new \Zend_Translate(   
				'gettext', 
				CMSROOT . 'lang',  
				$this->_locale,  
				array('scan'=>\Zend_Translate::LOCALE_FILENAME)
			); 

        }
        return $this->_translator;
    }
454655
public function getDataTableTranslationsAction()
    {
        // Get the current language
        $container = new Container('meliscms');
        $locale = $container['melis-lang-locale'];
    
        $translator = $this->getServiceLocator()->get('translator');
    
        $transData = array(
            'sEmptyTable' => $translator->translate('tr_meliscms_dt_sEmptyTable'),
            'sInfo' => $translator->translate('tr_meliscms_dt_sInfo'),
            'sInfoEmpty' => $translator->translate('tr_meliscms_dt_sInfoEmpty'),
            'sInfoFiltered' => $translator->translate('tr_meliscms_dt_sInfoFiltered'),
            'sInfoPostFix' => $translator->translate('tr_meliscms_dt_sInfoPostFix'),
            'sInfoThousands' => $translator->translate('tr_meliscms_dt_sInfoThousands'),
            'sLengthMenu' => $translator->translate('tr_meliscms_dt_sLengthMenu'),
            'sLoadingRecords' => $translator->translate('tr_meliscms_dt_sLoadingRecords'),
            'sProcessing' => $translator->translate('tr_meliscms_dt_sProcessing'),
            'sSearch' => $translator->translate('tr_meliscms_dt_sSearch'),
            'sZeroRecords' => $translator->translate('tr_meliscms_dt_sZeroRecords'),
            'oPaginate' => array(
                'sFirst' => $translator->translate('tr_meliscms_dt_sFirst'),
                'sLast' => $translator->translate('tr_meliscms_dt_sLast'),
                'sNext' => $translator->translate('tr_meliscms_dt_sNext'),
                'sPrevious' => $translator->translate('tr_meliscms_dt_sPrevious'),
            ),
            'oAria' => array(
                'sSortAscending' => $translator->translate('tr_meliscms_dt_sSortAscending'),
                'sSortDescending' => $translator->translate('tr_meliscms_dt_sSortDescending'),
            ),
        );
    
        return new JsonModel($transData);
    }
793782
private static function translator()
    {
        $files = ['Lang', 'Smiley'];
        $folder = static::$root.'Translator'.'/';

        self::call($files, $folder);

        $files = ['LanguageKeyNotFoundException', 'LanguageNotSupportedException'];
        $folder = static::$root.'Translator/Exceptions'.'/';

        self::call($files, $folder);
    }
120501
public static function getDefaultTranslator()
    {
        if (null === self::$_defaultTranslator) {
            require_once 'Zend/Registry.php';
            if (Zend_Registry::isRegistered('Zend_Translate')) {
                $translator = Zend_Registry::get('Zend_Translate');
                if ($translator instanceof Zend_Translate_Adapter) {
                    return $translator;
                } elseif ($translator instanceof Zend_Translate) {
                    return $translator->getAdapter();
                }
            }
        }

        return self::$_defaultTranslator;
    }
302413
protected function getImportTranslator()
    {
        $translator = parent::getImportTranslator();

        if ($translator instanceof \Gems_Model_Translator_AnswerTranslatorAbstract) {
            // Set answer specific options
            $surveyId = isset($this->formData['survey']) ? $this->formData['survey'] : null;
            $tokenCompleted = isset($this->formData['tokenCompleted']) ?
                    $this->formData['tokenCompleted'] :
                    \Gems_Model_Translator_AnswerTranslatorAbstract::TOKEN_ERROR;
            $skipUnknownPatients = isset($this->formData['skipUnknownPatients']) &&
                    $this->formData['skipUnknownPatients'];
            $noToken = isset($this->formData['noToken']) ?
                    $this->formData['noToken'] :
                    \Gems_Model_Translator_AnswerTranslatorAbstract::TOKEN_ERROR;

            $trackId = isset($this->formData['track']) ? $this->formData['track'] : null;

            $translator->setSurveyId($surveyId);
            $translator->setSkipUnknownPatients($skipUnknownPatients);
            $translator->setTokenCompleted($tokenCompleted);
            $translator->setNoToken($noToken);
            $translator->setTrackId($trackId);
        }

        return $translator;
    }
923633
public function translate($key)
    {
        if ($this->translations === null) {
            $this->loadTranslations();
        }

        if (!isset($this->translations[$key])) {
            // the key if $this is already the fallback translator
            return $this !== self::$fallbackTranslator ? self::$fallbackTranslator->translate($key) : $key;
        }

        return  $this->translations[$key];
    }
1297620
public function run()
    {
        Model::unguard();

        $config = config('netcore.module-translate.menu');

        $menuItems = [
            'leftAdminMenu' => [
                [
                    'name'            => 'Translate',
                    'icon'            => 'fa fa-globe',
                    'type'            => 'url',
                    'value'           => '#',
                    'module'          => 'Translate',
                    'is_active'       => 1,
                    'active_resolver' => 'admin.translations.*,admin.languages.*',
                    'parameters'      => json_encode([]),
                    'children'        => [
                        [
                            'name'            => 'Translations',
                            'type'            => 'route',
                            'value'           => 'admin.translations.index',
                            'module'          => '',
                            'is_active'       => 1,
                            'active_resolver' => 'admin.translations.*',
                            'parameters'      => json_encode([])
                        ],
                        [
                            'name'            => 'Languages',
                            'type'            => 'route',
                            'value'           => 'admin.languages.index',
                            'module'          => '',
                            'is_active'       => 1,
                            'active_resolver' => 'admin.languages.*',
                            'parameters'      => json_encode([])
                        ],
                    ]
                ],
            ]
        ];

        foreach ($menuItems as $key => $items) {
            $menu = Menu::firstOrCreate([
                'key' => $key
            ]);

            $translations = [];
            foreach (TransHelper::getAllLanguages() as $language) {
                $translations[$language->iso_code] = [
                    'name' => ucwords(preg_replace(array('/(?<=[^A-Z])([A-Z])/', '/(?<=[^0-9])([0-9])/'), ' $0', $key))
                ];
            }
            $menu->updateTranslations($translations);

            foreach ($items as $item) {
                $row = $menu->items()->firstOrCreate(array_except($item, ['name', 'value', 'parameters', 'children']));

                $translations = [];
                foreach (TransHelper::getAllLanguages() as $language) {
                    $translations[$language->iso_code] = [
                        'name'       => $item['name'],
                        'value'      => $item['value'],
                        'parameters' => $item['parameters']
                    ];
                }
                $row->updateTranslations($translations);

                foreach ($item['children'] as $child) {
                    $child['menu_id'] = $menu->id;

                    if ((!$config['translations'] && $child['name'] == 'Translations') || (!$config['languages'] && $child['name'] == 'Languages')) {
                        continue;
                    }

                    $c = $row->children()->firstOrCreate(array_except($child, ['name', 'value', 'parameters']));
                    $translations = [];
                    foreach (TransHelper::getAllLanguages() as $language) {
                        $translations[$language->iso_code] = [
                            'name'       => $child['name'],
                            'value'      => $child['value'],
                            'parameters' => $child['parameters']
                        ];
                    }
                    $c->updateTranslations($translations);
                }
            }
        }
    }
592189
public function getTranslator()
    {
        if (null === $this->translator) {
            $this->translator = $this->container->get('thelia.translator');
        }
        return $this->translator;
    }
156616
public static function exportTranslations()
    {
        $translations = new Translations();
        $loc = Localization::getInstance();
        $loc->pushActiveContext(Localization::CONTEXT_SYSTEM);
        try {
            $app = Application::getFacadeApplication();
            $db = $app->make('database')->connection();
            $r = $db->executeQuery('select treeID from Trees order by treeID asc');
            while ($row = $r->fetch()) {
                try {
                    $tree = static::getByID($row['treeID']);
                } catch (Exception $x) {
                    $tree = null;
                }
                if (isset($tree)) {
                    /* @var $tree Tree */
                    $treeName = $tree->getTreeName();
                    if (is_string($treeName) && ($treeName !== '')) {
                        $translations->insert('TreeName', $treeName);
                    }
                    $rootNode = $tree->getRootTreeNodeObject();
                    /* @var $rootNode TreeNode */
                    if (isset($rootNode)) {
                        $rootNode->exportTranslations($translations);
                    }
                }
            }
        } catch (Exception $x) {
            $loc->popActiveContext();
            throw $x;
        }
        $loc->popActiveContext();

        return $translations;
    }
451902
public function val() {
        $translation = $this->translator->getTranslation(ValueUtils::val($this->key), ValueUtils::val($this->parameters));
        if ($translation === null) {
            $translation = '???'.ValueUtils::val($this->key).'???';
        }
        return $translation;
    }
869755
public function editAction()
    {
        $default    = false;
        $params     = $this->params();
        $request    = $this->getRequest();
        $locator    = $this->getServiceLocator();
        $model      = $locator->get( 'Grid\Core\Model\SubDomain\Model' );
        /* @var $form \Zend\Form\Form */
        $form       = $locator->get( 'Form' )
                              ->create( 'Grid\Core\SubDomain' );

        if ( ( $id = $params->fromRoute( 'id' ) ) )
        {
            $subDomain = $model->find( $id );

            if ( empty( $subDomain ) )
            {
                $this->getResponse()
                     ->setStatusCode( 404 );

                return;
            }

            if ( empty( $subDomain->subdomain ) )
            {
                $default = true;

                $form->get( 'subdomain' )
                     ->setRequired( false );
            }
        }
        else
        {
            if ( ! $this->getServiceLocator()
                        ->get( 'Grid\User\Model\Permissions\Model' )
                        ->isAllowed( 'subDomain', 'create' ) )
            {
                $this->getResponse()
                     ->setStatusCode( 403 );

                return;
            }

            $subDomain = $model->create( array() );
        }

        /* @var $form \Zend\Form\Form */
        $form->setHydrator( $model->getMapper() )
             ->bind( $subDomain );

        if ( $request->isPost() )
        {
            $form->setData( $request->getPost() );

            if ( $form->isValid() && $subDomain->save() )
            {
                if ( $default && ! empty( $subDomain->subdomain ) )
                {
                    $newDefault = $model->create( array(
                        'subdomain'         => '',
                        'locale'            => $subDomain->locale,
                        'defaultLayoutId'   => $subDomain->defaultLayoutId,
                        'defaultContentId'  => $subDomain->defaultContentId,
                    ) );

                    $newDefault->save();
                }

                $this->messenger()
                     ->add( 'subDomain.form.success',
                            'subDomain', Message::LEVEL_INFO );

                return $this->redirect()
                            ->toRoute( 'Grid\Core\SubDomain\List', array(
                                'locale' => (string) $this->locale(),
                            ) );
            }
            else
            {
                $this->messenger()
                     ->add( 'subDomain.form.failed',
                            'subDomain', Message::LEVEL_ERROR );
            }
        }

        $form->setCancel(
            $this->url()
                 ->fromRoute( 'Grid\Core\SubDomain\List', array(
                        'locale' => (string) $this->locale(),
                    ) )
        );

        return array(
            'form'      => $form,
            'subDomain' => $subDomain,
        );
    }
603894
public static function exportTranslations()
    {
        $translations = new Translations();
        $categories = PermissionKeyCategory::getList();
        foreach ($categories as $cat) {
            $permissions = static::getList($cat->getPermissionKeyCategoryHandle());
            foreach ($permissions as $p) {
                $translations->insert('PermissionKeyName', $p->getPermissionKeyName());
                if ($p->getPermissionKeyDescription()) {
                    $translations->insert('PermissionKeyDescription', $p->getPermissionKeyDescription());
                }
            }
        }

        return $translations;
    }
781764
public function getTranslationsAttribute()
    {
        $translationData = [];
        $translations = Translation::where('entity_id', $this->id)->where('entity_type', get_class($this))->get();

        foreach ($translations as $translation) {
            $translationData[] = $translation->data->attributes;
        }

        return $translationData;
    }
695129
protected function customizeTranslation()
	{
		$message 		= \Sifo\FilterPost::getInstance()->getString( 'msgid' );
		$id_message 	= null;
		if ( is_numeric( $message ) )
		{
			$id_message = $message;
		}
		$instance			= $this->getParsedParam( 'instance' );
		$translator_model 	= new I18nTranslatorModel();

		$id_message = $translator_model->getTranslation( $message, $id_message );

		$result = array( 'status' => 'KO', 'msg' => 'This Message or ID doesn\'t exist.' );
		if ( $id_message )
		{
			$result = array( 'status' => 'OK', 'msg' => 'Message successfully customized.' );
			if( !$translator_model->customizeTranslation( $id_message, $instance ) )
			{
				$result = array( 'status' => 'KO', 'msg' => 'This message is already customized in this instance.' );
			}
		}

		return $result;
	}
780904
public function translatedAttributes() {
        if(! $attributes = isset($this['translatedAttributes']) ? $this['translatedAttributes'] : null) {
            $class = $this->classTranslation();

            $attributes = (new $class)
                ->getFillable();

            $attributes = array_except(array_flip($attributes),  [
                'language_id' ,
                str_singular($this->getModel()->getTable()) . '_id'
            ]);

            $attributes = array_flip($attributes);
        }

        return $attributes;
    }
727435
public function getOldPasswordElement()
    {
        $element = $this->getElement($this->_oldPasswordFieldName);

        if (! $element) {
            // Field current password
            $element = new \Zend_Form_Element_Password($this->_oldPasswordFieldName);
            $element->setLabel($this->_('Current password'));
            $element->setAttrib('size', 40);
            $element->setRenderPassword(true);
            $element->setRequired(true);
            $element->addValidator(
                    new \Gems_User_Validate_UserPasswordValidator($this->user, $this->_('Wrong password.'))
                    );

            $this->addElement($element);
        }

        return $element;
    }
654510
private function getTranslation()
    {
        $operatorTranslation = null;
        foreach ($this->entity->getTranslations() as $translation) {
            if ($translation->getLocale() == $this->locale) {
                $operatorTranslation = $translation;
            }
        }
        if (!$operatorTranslation) {
            $operatorTranslation = new OperatorTranslation();
            $operatorTranslation->setLocale($this->locale);
            $operatorTranslation->setOperator($this->entity);
            $this->entity->addTranslation($operatorTranslation);
        }

        return $operatorTranslation;
    }