src/Graviton/I18nBundle/Translator/Translator.php
public function translate($original)
    {
        $cached = $this->getFromCache($original);
        if (is_array($cached)) {
            return $cached;
        }

        $translations = $this->translationCollection->find(['original' => $original])->toArray();
        $baseArray = [];

        foreach ($translations as $item) {
            $baseArray[$item['language']] = $item['localized'];
        }

        $translation = [];
        foreach ($this->getLanguages() as $language) {
            if (isset($baseArray[$language])) {
                $translation[$language] = $baseArray[$language];
            } else {
                $translation[$language] = $original;
            }
        }

        // ensure existence of default language
        $translation[$this->defaultLanguage] = $original;

        $this->saveToCache($original, $translation);

        return $translation;
    }
public function translate($original)
    {
        $cached = $this->getFromCache($original);
        if (is_array($cached)) {
            return $cached;
        }

        $translations = $this->translationCollection->find(['original' => $original])->toArray();
        $baseArray = [];

        foreach ($translations as $item) {
            $baseArray[$item['language']] = $item['localized'];
        }

        $translation = [];
        foreach ($this->getLanguages() as $language) {
            if (isset($baseArray[$language])) {
                $translation[$language] = $baseArray[$language];
            } else {
                $translation[$language] = $original;
            }
        }

        // ensure existence of default language
        $translation[$this->defaultLanguage] = $original;

        $this->saveToCache($original, $translation);

        return $translation;
    }
public function translate ( $ original ) { $ cached = $ this -> getFromCache ( $ original ) ; if ( is_array ( $ cached ) ) { return $ cached ; } $ translations = $ this -> translationCollection -> find ( [ 'original' => $ original ] ) -> toArray ( ) ; $ baseArray = [ ] ; foreach ( $ translations as $ item ) { $ baseArray [ $ item [ 'language' ] ] = $ item [ 'localized' ] ; } $ translation = [ ] ; foreach ( $ this -> getLanguages ( ) as $ language ) { if ( isset ( $ baseArray [ $ language ] ) ) { $ translation [ $ language ] = $ baseArray [ $ language ] ; } else { $ translation [ $ language ] = $ original ; } } // ensure existence of default language $ translation [ $ this -> defaultLanguage ] = $ original ; $ this -> saveToCache ( $ original , $ translation ) ; return $ translation ; }
translate a string, returning an array with translations

@param string $original original string

@return array translation array
translate a string returning an array with translations