Ejemplo n.º 1
0
 /**
  * Fill LanguageStringTranslation objects from array.
  *
  * @param Language $language
  * @param array $values
  */
 protected function fillTranslationsFromForm(Language $language, array $values)
 {
     foreach (LanguageStringQuery::create()->find() as $string) {
         $field = sha1($string->getId());
         if ($values[$field] != '') {
             // ignore empty string as we want to keep fallback in that case
             // find existing translation
             $translation = LanguageStringTranslationQuery::create()->filterByLanguage($language)->filterByLanguageString($string)->findOne();
             // create new?
             if (!$translation) {
                 $translation = new LanguageStringTranslation();
                 $translation->setLanguage($language);
                 $translation->setLanguageString($string);
             }
             // set new translation and save
             $translation->setTranslation($values[$field]);
             $translation->save();
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Create non-existing language strings based on used variables (ie called L() or Curry_Language::get())
  *
  * @return void
  */
 public static function updateLanguageStrings()
 {
     $used = array_unique(self::$used);
     $existing = LanguageStringQuery::create()->select('Id')->find()->toArray();
     $new = array_diff($used, $existing);
     foreach ($new as $id) {
         try {
             $s = new LanguageString();
             $s->setId($id)->save();
         } catch (Exception $e) {
         }
     }
     LanguageStringQuery::create()->filterById($used, Criteria::IN)->update(array('LastUsed' => 'now'));
 }