Beispiel #1
0
 /**
  * Used to convert an object to its translated version if a langauge is set and the object is supported.
  * If no langauge is set, the $data is not an object or the object isn't supported (not implemented by the module that created it)
  * it'll be returned without modification.
  *
  * If multilanguage is not enabled, the data is returned without modification.
  */
 public static function getTranslation($data)
 {
     if (!Config::get('multilanguage.enabled')) {
         return $data;
     }
     if (is_array($data)) {
         foreach ($data as $k => $v) {
             $data[$k] = self::getTranslation($v);
         }
     } elseif (self::$_currentLang && is_object($data) && isset($data->id)) {
         $bits = explode('_', strtolower(get_class($data)));
         // Get module and content type from model name (ex: Module_TypeModel)
         $module = $bits[0];
         $type = str_replace('model', '', $bits[1]);
         Log::debug('multilanguage', sprintf('Translating view data %s:%s', $module, $type));
         $content = Multilanguage::content()->where('module', '=', $module)->andWhere('type', '=', $type)->andWhere('type_id', '=', $data->id)->andWhere('language_id', '=', self::$_currentLang->id)->first();
         // If a conversion for the current content type has been found for the current language
         if ($content) {
             // Get text items, if any
             if ($textItems = Multilanguage::text()->where('content_id', '=', $content->id)->all()) {
             }
             foreach ($textItems as $i) {
                 $data->{$i->name} = $i->content;
             }
             // Set property to new translated version
             // Get textarea items, if any
             if ($textareaItems = Multilanguage::textarea()->where('content_id', '=', $content->id)->all()) {
             }
             foreach ($textareaItems as $i) {
                 $data->{$i->name} = $i->content;
             }
             // Set property to new translated version
             // Get files, if any
             // TODO
         }
     } elseif (self::$_currentLang && is_string($data)) {
         $hash = md5($data);
         // Use hash as lookup so we can index the database column
         if ($string = Multilanguage::stringcontent()->where('hash', '=', $hash)->first()) {
             $translation = Multilanguage::string()->where('stringcontent_id', '=', $string->id)->andWhere('language_id', '=', self::$_currentLang->id)->first();
             if ($translation) {
                 $data = $translation->content;
             }
         } else {
             Multilanguage::stringcontent()->insert(array('hash' => $hash, 'content' => $data));
         }
     }
     return $data;
 }
Beispiel #2
0
 /**
  * Deletes an actual stored string and redirects back to manage strings page. This will
  * also delete any translations associated with it.
  */
 public static function delete($stringId)
 {
     Multilanguage::string()->where('stringcontent_id', '=', $stringId)->delete();
     if (Multilanguage::stringcontent()->delete($stringId)) {
         Message::ok('String deleted successfully.');
     } else {
         Message::error('Error deleting string, please try again.');
     }
     Url::redirect('admin/multilanguage/strings/manage');
 }