News for hackers. Stuff that matters.
Re:"this gem is awesome".to_spanish # = "esta joya es impres... by dholowiski on Wednesday January 12, 2011 @12:45AM (#2095140)
This is why even us die hard php coders sometimes yearn for RoR. .to_spanish !
Re:"this gem is awesome".to_spanish # = "esta joya es impres... by nwmcsween on Wednesday January 12, 2011 @01:23AM (#2095215)
Not trying to be pedantic but the gem has nothing to do with ror - it just extends the string class and adds to_x methods for each language.
Re:"this gem is awesome".to_spanish # = "esta joya es impres... by nowarninglabel on Wednesday January 12, 2011 @02:18AM (#2095315)
http://code.google.com/p/gtranslate-api-php/

$gt = new Gtranslate; echo "Translating [Ciao mondo] Italian to English => ".$gt->it_to_en("Ciao mondo");

Re:"this gem is awesome".to_spanish # = "esta joya es impres... by rbanffy on Wednesday January 12, 2011 @05:44AM (#2095665)
I think your example demonstrates very well why one would yearn for Ruby. The ability to give an extra method to a base class allows you to build very expressive code.

edit: and, BTW, the to_spanish method is not defined in the https://github.com/jimmycuadra/to_lang/blob/master/lib/to_la... module.

Re:"this gem is awesome".to_spanish # = "esta joya es impres... by troels on Wednesday January 12, 2011 @10:03AM (#2096323)
You're quite right, but in all fairness, the following would be a saner interface in php:

    italian_to_spanish("Ciao mondo");
Re:"this gem is awesome".to_spanish # = "esta joya es impres... by arethuza on Wednesday January 12, 2011 @07:00AM (#2095856)
Even boring old C# can do that.
Re:"this gem is awesome".to_spanish # = "esta joya es impres... by ryanpetrich on Wednesday January 12, 2011 @11:45AM (#2096705)
Not true. That's just a compiler trick
Re:"this gem is awesome".to_spanish # = "esta joya es impres... by Tomek_ on Wednesday January 12, 2011 @05:40AM (#2095660)
But still not as elegant as: echo "Ciao mondo"->it_to_en(); would be.
Re:"this gem is awesome".to_spanish # = "esta joya es impres... by viraptor on Wednesday January 12, 2011 @08:24AM (#2096031)
It's only elegant until you have two libraries which want to add `foo` to a `Bar`. Then you're in the world of pain compared to writing `lib1->foo($myBar);`
Re:"this gem is awesome".to_spanish # = "esta joya es impres... by Tomek_ on Wednesday January 12, 2011 @11:16AM (#2096590)
Actually I agree, I'm rather against giving programmers ability to extend native objects at free will, but I'm still for strings being objects in PHP, or even having "everything-is-an-object" approach there.
Re:"this gem is awesome".to_spanish # = "esta joya es impres... by steveklabnik on Wednesday January 12, 2011 @09:39AM (#2096258)
I'd rather have the common case be gorgeous and have the uncommon case require a some workaround, than have every case look like crap.
Re:"this gem is awesome".to_spanish # = "esta joya es impres... by dholowiski on Wednesday January 12, 2011 @04:09PM (#2097711)
Thank you for proving my point.
Re:"this gem is awesome".to_spanish # = "esta joya es impres... by alxp on Wednesday January 12, 2011 @07:27AM (#2095904)
Drupal's localization infrastructure is quite nice. Instead of 'echo' you use the function t() which lets users use a GUI to translate all tokens in a Drupal site.