/**
  * {@inheritDoc}
  *
  * @param ObjectManager $manager Object Manager
  *
  * @return void
  */
 public function load(ObjectManager $manager)
 {
     $deGerman = new Translatable();
     $deGerman->setId('i18n-de-German');
     $deGerman->setDomain('i18n');
     $deGerman->setLocale('de');
     $deGerman->setOriginal('German');
     $deGerman->setTranslated('Deutsch');
     $deGerman->setIsLocalized(true);
     $manager->persist($deGerman);
     $deEnglish = new Translatable();
     $deEnglish->setId('i18n-de-English');
     $deEnglish->setDomain('i18n');
     $deEnglish->setLocale('de');
     $deEnglish->setOriginal('English');
     $deEnglish->setTranslated('Englisch');
     $deEnglish->setIsLocalized(true);
     $language = new TranslatableLanguage();
     $language->setRef(ExtReference::create('Language', 'de'));
     $deEnglish->setLanguage($language);
     $manager->persist($deEnglish);
     $manager->flush();
 }
 /**
  * {@inheritDoc}
  *
  * @param ObjectManager $manager Object Manager
  *
  * @return void
  */
 public function load(ObjectManager $manager)
 {
     $deAdmin = new Translatable();
     $deAdmin->setId('i18n-de-Administration');
     $deAdmin->setDomain('core');
     $deAdmin->setLocale('de');
     $deAdmin->setOriginal('Administration');
     $deAdmin->setTranslated('Die Administration');
     $deAdmin->setIsLocalized(true);
     $language = new TranslatableLanguage();
     $language->setRef(ExtReference::create('Language', 'de'));
     $deAdmin->setLanguage($language);
     $manager->persist($deAdmin);
     $frAdmin = new Translatable();
     $frAdmin->setId('i18n-fr-Administration');
     $frAdmin->setDomain('core');
     $frAdmin->setLocale('fr');
     $frAdmin->setOriginal('Administration');
     $frAdmin->setIsLocalized(false);
     $language = new TranslatableLanguage();
     $language->setRef(ExtReference::create('Language', 'fr'));
     $frAdmin->setLanguage($language);
     $manager->persist($frAdmin);
     $enAdmin = new Translatable();
     $enAdmin->setId('i18n-en-Administration');
     $enAdmin->setDomain('core');
     $enAdmin->setLocale('en');
     $enAdmin->setOriginal('Administration');
     $enAdmin->setTranslated('Administration');
     $enAdmin->setIsLocalized(true);
     $language = new TranslatableLanguage();
     $language->setRef(ExtReference::create('Language', 'en'));
     $enAdmin->setLanguage($language);
     $manager->persist($enAdmin);
     /*** THIS TRANSLATABLES HERE SHOULD *NOT* BE TRANSLATED FOR TESTS ***/
     $deTablet = new Translatable();
     $deTablet->setId('i18n-de-Tablet');
     $deTablet->setDomain('core');
     $deTablet->setLocale('de');
     $deTablet->setOriginal('Tablet');
     $deTablet->setIsLocalized(false);
     $language = new TranslatableLanguage();
     $language->setRef(ExtReference::create('Language', 'de'));
     $deTablet->setLanguage($language);
     $manager->persist($deTablet);
     $frTablet = new Translatable();
     $frTablet->setId('i18n-fr-Tablet');
     $frTablet->setDomain('core');
     $frTablet->setLocale('fr');
     $frTablet->setOriginal('Tablet');
     $frTablet->setIsLocalized(false);
     $language = new TranslatableLanguage();
     $language->setRef(ExtReference::create('Language', 'fr'));
     $frTablet->setLanguage($language);
     $manager->persist($frTablet);
     $enTablet = new Translatable();
     $enTablet->setId('i18n-en-Tablet');
     $enTablet->setDomain('core');
     $enTablet->setLocale('en');
     $enTablet->setOriginal('Tablet');
     $enTablet->setTranslated('Tablet');
     $enTablet->setIsLocalized(true);
     $language = new TranslatableLanguage();
     $language->setRef(ExtReference::create('Language', 'en'));
     $enTablet->setLanguage($language);
     $manager->persist($enTablet);
     $manager->flush();
 }
Exemple #3
0
 /**
  * [In|Up]serts a Translatable object using an array with language strings.
  *
  * @param array $values array with language strings; key should be language id
  * @throws \Exception
  *
  * @return void
  */
 public function insertTranslatable(array $values)
 {
     if (!isset($values[$this->getDefaultLanguage()])) {
         throw new \Exception(sprintf('Creating new Translatable without "%s" key is not support yet.', $this->getDefaultLanguage()));
     }
     $original = $values[$this->getDefaultLanguage()];
     if ($this->isTranslatableContext()) {
         $languages = $this->getLanguages();
         \array_walk($languages, function ($locale) use($original, $values) {
             $isLocalized = false;
             $translated = '';
             if (array_key_exists($locale, $values)) {
                 $translated = $values[$locale];
                 $isLocalized = true;
             }
             $translatable = new TranslatableDocument();
             $translatable->setId('i18n-' . $locale . '-' . $original);
             $translatable->setLocale($locale);
             $translatable->setDomain($this->getTranslatableDomain());
             $translatable->setOriginal($original);
             $translatable->setTranslated($translated);
             $translatable->setIsLocalized($isLocalized);
             $translatableLang = new TranslatableLanguage();
             $translatableLang->setRef('/i18n/language/' . $locale);
             $translatable->setLanguage($translatableLang);
             $this->translatable->insertRecord($translatable);
         });
     }
 }