コード例 #1
0
 public function testLoadWithSymfonyFormat()
 {
     $loader = new XliffLoader();
     $expected = new MessageCatalogue();
     $expected->setLocale('en');
     $expected->add(XliffMessage::create('foo1')->setDesc('foo1')->setLocaleString('bar')->setNew(false));
     $expected->add(XliffMessage::create('foo2')->setDesc('foo2')->setLocaleString('bar')->setNew(false));
     $expected->add(XliffMessage::create('foo3')->setDesc('foo3')->setLocaleString('bar')->setNew(false));
     $expected->add(XliffMessage::create('foo4')->setDesc('foo4')->setLocaleString('bar')->setNew(false));
     $this->assertEquals($expected, $loader->load(__DIR__ . '/Symfony/xliff/old_format.xml', 'en'));
 }
コード例 #2
0
 /**
  * Get message object by key
  * 
  * @param type $bundle
  * @param type $locale
  * @param type $messageKey
  * @param type $domain
  * @return bool false or string message
  */
 public function getMessage($bundle, $locale, $messageKey, $domain = 'messages')
 {
     try {
         $filename = $this->getFilename($bundle, $locale, $domain);
     } catch (FileNotFoundException $e) {
         return false;
     }
     // todo maybe: load other than xliff files
     // switch format, if xlf or xliff...
     $loader = new XliffLoader();
     $messages = $loader->load($filename, $locale, $domain);
     $reflect = new \ReflectionClass($messages);
     $refDomains = $reflect->getProperty('domains');
     $refDomains->setAccessible(true);
     $r = $refDomains->getValue($messages);
     $messageCollection = $r[$domain];
     $messageArray = $messageCollection->all();
     if (isset($messageArray[$messageKey])) {
         return $messageArray[$messageKey];
     }
     return false;
 }
コード例 #3
0
 /**
  * Show list of message by bundle, locale and domain
  * 
  * @param Request $request
  * @return type
  */
 public function listTranslationsAction(Request $request)
 {
     $bundle = $request->get('bundle');
     $locale = $request->get('locale');
     $domain = $request->get('domain');
     if (!$domain) {
         $domain = 'messages';
     }
     $bundles = $this->container->getParameter('kernel.bundles');
     $kernel = $this->container->get('kernel');
     $path = $kernel->locateResource('@' . $bundle);
     $localeFiles = $this->container->get('geschke_bundle_admin_translatorguibundle.locale_files');
     $messageFiles = $localeFiles->getLanguages($path);
     $localeFile = null;
     foreach ($messageFiles as $localeData) {
         if ($localeData['locale'] == $locale && $localeData['domain'] == $domain) {
             $localeFile = $localeData;
             break;
         }
     }
     // build array with all current languages in the bundle
     $countMessageFiles = count($messageFiles);
     for ($i = 0; $i < $countMessageFiles; $i++) {
         if ($messageFiles[$i]['domain'] != $domain) {
             unset($messageFiles[$i]);
             continue;
         }
         if (!isset($csp_l10n_sys_locales[$messageFiles[$i]['locale']]) && !isset($csp_l10n_langs[$messageFiles[$i]['locale']])) {
             $messageFiles[$i]['unknown'] = true;
         }
         if (strlen($messageFiles[$i]['locale']) > 2) {
             if (isset($csp_l10n_sys_locales[$messageFiles[$i]['locale']])) {
                 $messageFiles[$i]['additional'] = $csp_l10n_sys_locales[$messageFiles[$i]['locale']];
             }
         }
     }
     $filename = $path . 'Resources/translations/' . $localeFile['file'];
     // todo maybe: load other than xliff files
     // switch format, if xlf or xliff...
     $translator = $this->get('translator');
     $loader = new XliffLoader();
     $messages = $loader->load($filename, $locale);
     $reflect = new \ReflectionClass($messages);
     $refDomains = $reflect->getProperty('domains');
     $refDomains->setAccessible(true);
     $r = $refDomains->getValue($messages);
     $messageCollection = $r['messages'];
     $messageArray = $messageCollection->all();
     $cnt = count($messageArray);
     $page = $request->get('page') ? $request->get('page') : 1;
     $itemsPerPage = 25;
     $paginator = new Paginator($page, $cnt, $itemsPerPage);
     $offset = $paginator->getOffset();
     $messages = array_slice($messageArray, $offset, $itemsPerPage);
     $uri = $this->get('router')->generate('geschke_admin_translator_gui_translation_edit', array('bundle' => $bundle, 'locale' => $locale));
     $paginator->setBaseUrl($uri);
     $messageTranslation = new MessageTranslation();
     $form = $this->createFormBuilder($messageTranslation)->add('locale', 'hidden')->add('message_reference', 'textarea', array('disabled' => true, 'required' => false))->add('message', 'textarea', array('disabled' => true))->add('translation', 'textarea')->getForm();
     $localeReference = new LocaleReference($request, $this->get('logger'));
     return $this->render('GeschkeAdminTranslatorGUIBundle:Language:list.html.twig', array('mainnav' => '', 'bundle' => $bundle, 'locale' => $locale, 'localeReference' => $localeReference->getLocaleReference(), 'domain' => $domain, 'messages' => $messages, 'messageFiles' => $messageFiles, 'form' => $form->createView(), 'paginator' => $paginator));
 }