src/Service/MelisCoreTranslationService.php
public function getTranslationMessages($locale = 'en_EN', $textDomain = 'default')
    {
        // Get the translation service, so we would be able to fetch the current configs
        $translator = $this->getServiceLocator()->get('translator');
        $translation = $translator->getTranslator();
        $messages = array();

        // process to access the private properties of translation service
        $reflector = new \ReflectionObject($translation);
        $property = $reflector->getProperty('files');
        $property->setAccessible(true);
        $files = (array)$property->getValue($translation);

        if($files) {
            // re-add translation file to a new Translation Class Object
            if(isset($files['default']['*'])) {
                foreach($files['default']['*'] as $transKey => $transValues)
                {
                    $this->addTranslationFile('phparray', $transValues['filename'], 'default', $locale);
                }

                // Load Translation Messages
                if (!isset($this->messages[$textDomain][$locale])) {
                    $this->loadMessages($textDomain, $locale);
                }

                // This is where the translated mesage are stored
                $translatedMessages =  (array)$this->messages[$textDomain][$locale];


                $messages = array();
                $key = '';
                foreach($translatedMessages as $translationKey => $translationValues) {
                    $key =  str_replace("'", "\'", $translationKey);
                    $messages[$key] = str_replace("'", "\'", $translationValues);
                }
            }

        }



        return $messages;

    }
public function getTranslationMessages($locale = 'en_EN', $textDomain = 'default')
    {
        // Get the translation service, so we would be able to fetch the current configs
        $translator = $this->getServiceLocator()->get('translator');
        $translation = $translator->getTranslator();
        $messages = array();

        // process to access the private properties of translation service
        $reflector = new \ReflectionObject($translation);
        $property = $reflector->getProperty('files');
        $property->setAccessible(true);
        $files = (array)$property->getValue($translation);

        if($files) {
            // re-add translation file to a new Translation Class Object
            if(isset($files['default']['*'])) {
                foreach($files['default']['*'] as $transKey => $transValues)
                {
                    $this->addTranslationFile('phparray', $transValues['filename'], 'default', $locale);
                }

                // Load Translation Messages
                if (!isset($this->messages[$textDomain][$locale])) {
                    $this->loadMessages($textDomain, $locale);
                }

                // This is where the translated mesage are stored
                $translatedMessages =  (array)$this->messages[$textDomain][$locale];


                $messages = array();
                $key = '';
                foreach($translatedMessages as $translationKey => $translationValues) {
                    $key =  str_replace("'", "\'", $translationKey);
                    $messages[$key] = str_replace("'", "\'", $translationValues);
                }
            }

        }



        return $messages;

    }
public function getTranslationMessages ( $ locale = 'en_EN' , $ textDomain = 'default' ) { // Get the translation service, so we would be able to fetch the current configs $ translator = $ this -> getServiceLocator ( ) -> get ( 'translator' ) ; $ translation = $ translator -> getTranslator ( ) ; $ messages = array ( ) ; // process to access the private properties of translation service $ reflector = new \ ReflectionObject ( $ translation ) ; $ property = $ reflector -> getProperty ( 'files' ) ; $ property -> setAccessible ( true ) ; $ files = ( array ) $ property -> getValue ( $ translation ) ; if ( $ files ) { // re-add translation file to a new Translation Class Object if ( isset ( $ files [ 'default' ] [ '*' ] ) ) { foreach ( $ files [ 'default' ] [ '*' ] as $ transKey => $ transValues ) { $ this -> addTranslationFile ( 'phparray' , $ transValues [ 'filename' ] , 'default' , $ locale ) ; } // Load Translation Messages if ( ! isset ( $ this -> messages [ $ textDomain ] [ $ locale ] ) ) { $ this -> loadMessages ( $ textDomain , $ locale ) ; } // This is where the translated mesage are stored $ translatedMessages = ( array ) $ this -> messages [ $ textDomain ] [ $ locale ] ; $ messages = array ( ) ; $ key = '' ; foreach ( $ translatedMessages as $ translationKey => $ translationValues ) { $ key = str_replace ( "'" , "\'" , $ translationKey ) ; $ messages [ $ key ] = str_replace ( "'" , "\'" , $ translationValues ) ; } } } return $ messages ; }
Re-imports translation files from all the modules and re-writes it
so it can be used in Javascript or any other scripts that would like
to use translation on their messages
@param String $locale
@param string $textDomain
@return Array
Re - imports translation files from all the modules and re - writes it so it can be used in Javascript or any other scripts that would like to use translation on their messages