This is quite different from op's question. You can do this when sending parameters for a constructor, but the problem was how to translate values in an associative array which is a static property of an object. It's something of a everyday occurrence, really, so finding a valuable solution would be most useful.
One way to do it would be through a static method I guess: class JobeetJobPeer extends BaseJobeetJobPeer { static public $types = array( 'full-time' => 'Full time', 'part-time' => 'Part time', 'freelance' => 'Freelance', ); public static function getTranslatedTypes() { $i18n_object = sfContext::getInstance()->getI18n(); return array_map(array($i18n_object, '__'), self::$types); } ..... On Jul 16, 9:34 pm, Alexandru-Emil Lupu <gang.al...@gmail.com> wrote: > i have this > > public function executeCommentsForPostFeed() > { > $text = $this->getRequestParameter('stripped_title'); > $date = sfDoctrineBlogTools::getDateFromRequest(); > > $this->post = sfDoctrineBlogPost::findByStrippedTitleAndDate($text, > $date); > > $this->forward404Unless($post); > $this->feed = sfFeedPeer::createFromObjects( > $comments, > array( > 'format' => $this->getRequestParameter('format', 'atom1'), > 'title' => sfDoctrineBlogTools::__('Comments on post "%1%" > from %2%', array('%1%' => $post->getTitle(), '%2%' => > sfConfig::get('app_sfSimpleBlog_title', ''))), > 'link' => > $this->getController()->genUrl('sfSimpleBlog/show?stripped_title='.$post->getStrippedTitle()), > 'authorName' => sfConfig::get('app_sfSimpleBlog_author', ''), > 'methods' => array('title' => 'getPostTitle', 'authorEmail' => > '') > ) > ); > $this->setTemplate('feed'); > } > > and this > > class sfDoctrineBlogTools > { > > public static function __($text, $args = array(), $catalogue = 'messages') > { > if (sfConfig::get('sf_i18n')) > { > return sfContext::getInstance()->getI18N()->__($text, $args, > $catalogue); > } > else > { > if (empty($args)) > { > $args = array(); > } > > // replace object with strings > foreach ($args as $key => $value) > { > if (is_object($value) && method_exists($value, '__toString')) > { > $args[$key] = $value->__toString(); > } > } > > return strtr($text, $args); > } > } > > On Thu, Jul 16, 2009 at 3:49 PM, Alexandru-Emil Lupu > <gang.al...@gmail.com>wrote: > > > > > I will paste in this topic my usage tonight .. when i will get home. > > Alecs > > > On Thu, Jul 16, 2009 at 3:39 PM, Crafty_Shadow <vankat...@gmail.com>wrote: > > >> The problem is not the loading order but the fact that php doesn't > >> allow this syntax: > >> static public $types = array( > >> 'full-time' => TextTools::__('Full time'), > >> 'part-time' => TextTools::__('Part time'), > >> ... > > >> Try it and you'll see. > >> It gives "unexpected '(', expecting ')'" because it anticipates the > >> closing parentheses for the array. > > >> On Jul 16, 3:31 pm, Alexandru-Emil Lupu <gang.al...@gmail.com> wrote: > >> > HI! > >> > i do not have access to the sources atm, but, i think it would work: > > >> > <?php class myTools{ > > >> > public static function __($text, $args = array(), $catalogue = > >> 'messages') > >> > { > >> > if (sfConfig::get('sf_i18n')) > >> > { > >> > return sfContext::getInstance()->getI18N()->__($text, $args, > >> > $catalogue); > >> > } > >> > else > >> > { > >> > if (empty($args)) > >> > { > >> > $args = array(); > >> > } > > >> > // replace object with strings > >> > foreach ($args as $key => $value) > >> > { > >> > if (is_object($value) && method_exists($value, '__toString')) > >> > { > >> > $args[$key] = $value->__toString(); > >> > } > >> > } > > >> > return strtr($text, $args); > >> > } > > >> > } > >> > }?> > > >> > practically i have rewritten the helper function into a class. > >> However... i > >> > have used in an action / component .. not in a Peer class... > >> > Those might be loaded a little bit earlier than I18N > > >> > Alecs > > >> > On Thu, Jul 16, 2009 at 11:37 AM, Crafty_Shadow <vankat...@gmail.com> > >> wrote: > > >> > > What you've written, setting an static property of an object as an > >> > > associative array with translation calls does not work. > >> > > I have had the same problem before, what I usually do is call the > >> > > widget with something along the lines of: > >> > > 'choices'=>array_map(array('TextTools ', '__'), JobeetJobPeer:: > >> > > $types) > > >> > > Unfortunately, when using this you can't rely on i18n-extract. > > >> > > If someone knows a better way, please do share. > > >> > > On Jul 16, 8:37 am, Mateusz Kaczmarek <mateusz.kaczma...@gmail.com> > >> > > wrote: > >> > > > I didn't mentioned that I have leatest php 5.2 version on debian. I > >> > > > think that php don't allow to set dynamic date to the class > >> variable. > >> > > > @Alexandru-Emil can You show Your implementation ? > > >> > > > On 15 Lip, 21:34, Mateusz Kaczmarek <mateusz.kaczma...@gmail.com> > >> > > > wrote: > > >> > > > > > TextTools != myTools > > >> > > > > Bad copy & paste :-), so this is no problem. > > >> > > > > I have syntax error here: 'full-time' => TextTools::__('Full > >> > > > > time'), > > >> > > > > On Jul 15, 9:21 pm, Gábor Fási <maerl...@gmail.com> wrote: > > >> > > > > > TextTools != myTools > >> > > > > > also, which line do you have the syntax error in? This part you > >> > > showed > >> > > > > > us looks fine to me. > > >> > > > > > On Wed, Jul 15, 2009 at 20:33, Mateusz > > >> > > > > > Kaczmarek<mateusz.kaczma...@gmail.com> wrote: > > >> > > > > > > Hmm. Are You sure ? I have something like this: > > >> > > > > > > class myTools { > >> > > > > > > public static function __($text) { > >> > > > > > > return sfContext::getInstance()->getI18N()->__($text); > >> > > > > > > } > >> > > > > > > } > > >> > > > > > > and this: > > >> > > > > > > static public $types = array( > >> > > > > > > 'full-time' => TextTools::__('Full time'), > >> > > > > > > 'part-time' => TextTools::__('Part time'), > >> > > > > > > 'freelance' => TextTools::__('Freelance'), > >> > > > > > > ); > > >> > > > > > > cause: Parse error: syntax error, unexpected '(', expecting > >> ')' > > >> > > > > > > On 15 Lip, 13:10, Alexandru-Emil Lupu <gang.al...@gmail.com> > >> > > wrote: > >> > > > > > >> When i need to add I18N support i have made a class called > >> > > "TextTools", > >> > > > > > >> which had a static method __() . Inside this method was a > >> call to > >> > > I18N > >> > > > > > >> object (i had to dig a little bit in sf code ). > >> > > > > > >> but, in the end, i was able to make a > > >> > > > > > >> // lib/model/JobeetJobPeer.php > >> > > > > > >> class JobeetJobPeer extends BaseJobeetJobPeer > >> > > > > > >> { > >> > > > > > >> static public $types = array( > >> > > > > > >> 'full-time' => TextTools::__('Full time'), > >> > > > > > >> 'part-time' => TextTools::__('Part time'), > >> > > > > > >> 'freelance' => TextTools::__('Freelance'), > >> > > > > > >> ); > > >> > > > > > >> // ... > > >> > > > > > >> } > > >> > > > > > >> The 18n:extract task performs a recursive search for > >> "__("+What > >> > > ever > >> > > > > > >> here+")".. If you'll digg the code, you'll figure it out ..,. > > >> > > > > > >> Also ... be aware that the templates call the __(" ") > >> function by > >> > > default > >> > > > > > >> ... but won't help you too much ... > > >> > > > > > >> On Wed, Jul 15, 2009 at 10:27 AM, Mateusz Kaczmarek < > > >> > > > > > >> mateusz.kaczma...@gmail.com> wrote: > > >> > > > > > >> > Hello, I have some trouble with i18n system. How to > >> translate > >> > > strings > >> > > > > > >> > in form items that are generated automaticaly for example > >> radio > >> > > > > > >> > buttons or select. I use pattern from Jobbet Tutorial and I > >> have > >> > > > > > >> > something like this: > > >> > > > > > >> > // lib/model/JobeetJobPeer.php > >> > > > > > >> > class JobeetJobPeer extends BaseJobeetJobPeer > >> > > > > > >> > { > >> > > > > > >> > static public $types = array( > >> > > > > > >> > 'full-time' => 'Full time', > >> > > > > > >> > 'part-time' => 'Part time', > >> > > > > > >> > 'freelance' => 'Freelance', > >> > > > > > >> > ); > > >> > > > > > >> > // ... > >> > > > > > >> > } > > >> > > > > > >> > and > > >> > > > > > >> > $this->widgetSchema['type'] = new sfWidgetFormChoice(array( > >> > > > > > >> > 'choices' => JobeetJobPeer::$types, > >> > > > > > >> > 'expanded' => true, > >> > > > > > >> > )); > > >> > > > > > >> > But when i use i18n:extract task, this string aren't > >> included in > >> > > > > > >> > result. How can I take advantages of great i18n in this > >> case ? > >> > > Thanx > >> > > > > > >> > in advance for help > > >> > > > > > >> -- > >> > > > > > >> As programmers create bigger & better idiot proof programs, > >> so the > >> > > universe > >> > > > > > >> creates bigger & better idiots! > >> > > > > > >> I am on web: http://www.alecslupu.ro/ > >> > > > > > >> I am on twitter:http://twitter.com/alecslupu > >> > > > > > >> I am on linkedIn:http://www.linkedin.com/in/alecslupu > >> > > > > > >> Tel: (+4)0748.543.798 > > >> > -- > >> > As programmers create bigger & better idiot proof programs, so the > >> universe > >> > creates bigger & better idiots! > >> > I am on web: http://www.alecslupu.ro/ > >> > I am on twitter:http://twitter.com/alecslupu > >> > I am on linkedIn:http://www.linkedin.com/in/alecslupu > >> > Tel: (+4)0748.543.798 > > > -- > > As programmers create bigger & better idiot proof programs, so the universe > > creates bigger & better idiots! > > I am on web: http://www.alecslupu.ro/ > > I am on twitter:http://twitter.com/alecslupu > > I am on linkedIn:http://www.linkedin.com/in/alecslupu > > Tel: (+4)0748.543.798 > > -- > As programmers create bigger & better idiot proof programs, so the universe > creates bigger & better idiots! > I am on web: http://www.alecslupu.ro/ > I am on twitter:http://twitter.com/alecslupu > I am on linkedIn:http://www.linkedin.com/in/alecslupu > Tel: (+4)0748.543.798 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~----------~----~----~----~------~----~------~--~---