private function fig_dictionary(Context $context) {
        //If a @source attribute is specified,
        //it means that when the target (view's language) is the same as @source,
        //then don't bother loading dictionary file, nor translating: just render the tag's children.

        $file = $this->dicFile;
        $filename = $context->view->getTranslationPath() . '/' . $context->view->getLanguage() . '/' . $file;

        $dictionary = new Dictionary($filename, $this->source);


        if ( ($context->view->getLanguage() == '') || ($this->source == $context->view->getLanguage()) ) {
            // If the current View does not specify a Language,
            // or if the dictionary to load is same language as View,
            // let's not care about i18n.
            // We will activate i18n only if the dictionary explicitly specifies a source,
            // which means that we cannot simply rely on contents of the fig:trans tags.
            // However, we still need to hook the Dictionary object as a placeholder,
            // so that subsequent trans tag for the given dic name and source will
            // simply render their contents.
            $context->addDictionary($dictionary, $this->dicName);
            return '';
        }

        //TODO: Please optimize here: cache the realpath of the loaded dictionaries,
        //so as not to re-load an already loaded dictionary in same View hierarchy.


        try {
            //Determine whether this dictionary was pre-compiled:
            if($context->view->getCachePath()) {
                $tmpFile = $context->getView()->getCachePath() . '/' . 'Dictionary' . '/' . $context->getView()->getLanguage() . '/' . $file . '.php';
                //If the tmp file already exists,
                if(file_exists($tmpFile)) {
                    //but is older than the source file,
                    if(file_exists($filename) && (filemtime($tmpFile) < filemtime($filename)) ) {
                        Dictionary::compile($filename, $tmpFile);
                    }
                } else {
                    Dictionary::compile($filename, $tmpFile);
                }
                $dictionary->restore($tmpFile);
            }

            //If we don't even have a temp folder specified, load the dictionary for the first time.
            else {
                $dictionary->load();
            }
        } catch(FileNotFoundException $ex) {
            throw new FileNotFoundException('Translation file not found: file=' . $filename .
                ', language=' . $context->view->getLanguage() .
                ', source=' . $context->getFilename(),
                $context->getFilename() );
        }


        //Hook the dictionary to the current file.
        //(in fact this will bubble up the message as high as possible, ie:
        //to the highest parent which does not bear a dictionary of same name)
        $context->addDictionary($dictionary, $this->dicName);
        return '';
    }
private function fig_dictionary(Context $context) {
        //If a @source attribute is specified,
        //it means that when the target (view's language) is the same as @source,
        //then don't bother loading dictionary file, nor translating: just render the tag's children.

        $file = $this->dicFile;
        $filename = $context->view->getTranslationPath() . '/' . $context->view->getLanguage() . '/' . $file;

        $dictionary = new Dictionary($filename, $this->source);


        if ( ($context->view->getLanguage() == '') || ($this->source == $context->view->getLanguage()) ) {
            // If the current View does not specify a Language,
            // or if the dictionary to load is same language as View,
            // let's not care about i18n.
            // We will activate i18n only if the dictionary explicitly specifies a source,
            // which means that we cannot simply rely on contents of the fig:trans tags.
            // However, we still need to hook the Dictionary object as a placeholder,
            // so that subsequent trans tag for the given dic name and source will
            // simply render their contents.
            $context->addDictionary($dictionary, $this->dicName);
            return '';
        }

        //TODO: Please optimize here: cache the realpath of the loaded dictionaries,
        //so as not to re-load an already loaded dictionary in same View hierarchy.


        try {
            //Determine whether this dictionary was pre-compiled:
            if($context->view->getCachePath()) {
                $tmpFile = $context->getView()->getCachePath() . '/' . 'Dictionary' . '/' . $context->getView()->getLanguage() . '/' . $file . '.php';
                //If the tmp file already exists,
                if(file_exists($tmpFile)) {
                    //but is older than the source file,
                    if(file_exists($filename) && (filemtime($tmpFile) < filemtime($filename)) ) {
                        Dictionary::compile($filename, $tmpFile);
                    }
                } else {
                    Dictionary::compile($filename, $tmpFile);
                }
                $dictionary->restore($tmpFile);
            }

            //If we don't even have a temp folder specified, load the dictionary for the first time.
            else {
                $dictionary->load();
            }
        } catch(FileNotFoundException $ex) {
            throw new FileNotFoundException('Translation file not found: file=' . $filename .
                ', language=' . $context->view->getLanguage() .
                ', source=' . $context->getFilename(),
                $context->getFilename() );
        }


        //Hook the dictionary to the current file.
        //(in fact this will bubble up the message as high as possible, ie:
        //to the highest parent which does not bear a dictionary of same name)
        $context->addDictionary($dictionary, $this->dicName);
        return '';
    }
private function fig_dictionary ( Context $ context ) { //If a @source attribute is specified, //it means that when the target (view's language) is the same as @source, //then don't bother loading dictionary file, nor translating: just render the tag's children. $ file = $ this -> dicFile ; $ filename = $ context -> view -> getTranslationPath ( ) . '/' . $ context -> view -> getLanguage ( ) . '/' . $ file ; $ dictionary = new Dictionary ( $ filename , $ this -> source ) ; if ( ( $ context -> view -> getLanguage ( ) == '' ) || ( $ this -> source == $ context -> view -> getLanguage ( ) ) ) { // If the current View does not specify a Language, // or if the dictionary to load is same language as View, // let's not care about i18n. // We will activate i18n only if the dictionary explicitly specifies a source, // which means that we cannot simply rely on contents of the fig:trans tags. // However, we still need to hook the Dictionary object as a placeholder, // so that subsequent trans tag for the given dic name and source will // simply render their contents. $ context -> addDictionary ( $ dictionary , $ this -> dicName ) ; return '' ; } //TODO: Please optimize here: cache the realpath of the loaded dictionaries, //so as not to re-load an already loaded dictionary in same View hierarchy. try { //Determine whether this dictionary was pre-compiled: if ( $ context -> view -> getCachePath ( ) ) { $ tmpFile = $ context -> getView ( ) -> getCachePath ( ) . '/' . 'Dictionary' . '/' . $ context -> getView ( ) -> getLanguage ( ) . '/' . $ file . '.php' ; //If the tmp file already exists, if ( file_exists ( $ tmpFile ) ) { //but is older than the source file, if ( file_exists ( $ filename ) && ( filemtime ( $ tmpFile ) < filemtime ( $ filename ) ) ) { Dictionary :: compile ( $ filename , $ tmpFile ) ; } } else { Dictionary :: compile ( $ filename , $ tmpFile ) ; } $ dictionary -> restore ( $ tmpFile ) ; } //If we don't even have a temp folder specified, load the dictionary for the first time. else { $ dictionary -> load ( ) ; } } catch ( FileNotFoundException $ ex ) { throw new FileNotFoundException ( 'Translation file not found: file=' . $ filename . ', language=' . $ context -> view -> getLanguage ( ) . ', source=' . $ context -> getFilename ( ) , $ context -> getFilename ( ) ) ; } //Hook the dictionary to the current file. //(in fact this will bubble up the message as high as possible, ie: //to the highest parent which does not bear a dictionary of same name) $ context -> addDictionary ( $ dictionary , $ this -> dicName ) ; return '' ; }
Loads a language XML file, to be used within the current view.

If a Temp path was specified in the View,
we try to compile (serialize) the XML key-value collection and store
the serialized form in a 'Dictionary/(langcode)' subfolder of the temp path.

@param Context $context

@return string
@throws FileNotFoundException
@throws \figdice\exceptions\DictionaryDuplicateKeyException
Loads a language XML file to be used within the current view .