5 ms·
"this gem is awesome".to_spanish # = "esta joya es impresionante"
- dholowiski 16y agoThis is why even us die hard php coders sometimes yearn for RoR. .to_spanish !
- nwmcsween 16y agoNot 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.
- deleted 16y ago[deleted]
- nowarninglabel 16y agohttp://code.google.com/p/gtranslate-api-php/ http://code.google.com/p/gtranslate-api-php/ $gt = new Gtranslate; echo "Translating [Ciao mondo] Italian to English => ".$gt->it_to_en("Ciao mondo");
- Tomek_ 16y agoBut still not as elegant as: echo "Ciao mondo"->it_to_en(); would be.
- viraptor 16y agoIt'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);`
- steveklabnik 16y agoI'd rather have the common case be gorgeous and have the uncommon case require a some workaround, than have every case look like crap.
- Tomek_ 16y agoActually 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.
- rbanffy 16y agoI 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_lang/string_methods.rb https://github.com/jimmycuadra/to_lang/blob/master/lib/to_la... module.
- arethuza 16y agoEven boring old C# can do that.
- ryanpetrich 16y agoNot true. That's just a compiler trick
- troels 16y agoYou're quite right, but in all fairness, the following would be a saner interface in php: italian_to_spanish("Ciao mondo");
- dholowiski 16y agoThank you for proving my point.
- alxp 16y agoDrupal'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.
- callmeed 16y agoWhat's causing this? ruby-1.8.7-p302 > "Where is the bathroom?".to_spanish => "\302\277D\303\263nde est\303\241 el ba\303\261o?"
- comron 16y agoListed under "Roadmap" in the readme is the following: Investigate Unicode support for Ruby 1.8. to_lang has only been tested with 1.9. Do you have a copy of 1.9 to test with?
- callmeed 16y agoAh, yes. Much better: ruby-1.9.2-p0 > "Where is the bathroom?".to_spanish => "¿Dónde está el baño?" Thanks
- rsoto 16y agoAccents and special chars, I think it is trying to output "¿Dónde está el baño?"
- deleted 16y ago[deleted]
- carbon8 16y agoRuby 1.8 displays non-ascii characters in the shell using octal escape sequences. \302\277 is ¿, \303\263 is ó and so forth. It should be fine to work with (eg, saving to a database or displaying in a template) as long as you know the encoding. I just glanced at the code, but it looks like it just takes whatever the Google Translate API gives it, which I'm guessing is UTF-8.
- deleted 16y ago[deleted]
- djhworld 16y agohow does the gem failover if the machine it is being used on isn't connected to the internet?
- getsat 16y agoYou would get a SocketError exception from getaddrinfo because HTTParty (which uses Net::HTTP) can't lookup the hostname. If the hostname is already resolved, you'd get a Errno::EHOSTUNREACH exception from connect because there is no route to Google's servers.
- Uchikoma 16y agoLeaky abstraction http://www.joelonsoftware.com/articles/LeakyAbstractions.html http://www.joelonsoftware.com/articles/LeakyAbstractions.htm...
- getsat 16y agoHey, I didn't say it was awesome, I was just reporting what actually happens. :)
- burgerbrain 16y agoIn other words, "poorly".
- alvatar 16y agoJust in case you didn't know, and you have plans to actually use Google Translate for translating web pages into Spanish... please don't. I haven't seen a single sentence with more than 3-4 words translated properly from English to Spanish. Even the examples shown in the README make no sense in Spanish.
- Tomek_ 16y agoReally? From my experience English to Spanish translation works pretty well in Google Translate. I've been using it a lot when I started to live in Spain and my Spanish skills were not too great yet: people were actually complementing me for how good my (written) Spanish is and were in huge shock when they met me in person and it turned out that I barely can formulate any sentence. True story.
- ollysb 16y agoA few years back an ex-girlfriend of mine did an erasmus year over in Spain and I ended up making friends with a whole bunch of people that I could barely converse with. They've always been very impressed at far my Spanish has come in IM, thank you babel fish.
- paradoja 16y agoIt depends... most of what's translated is understandable for a native speaker, but it will be clear that it wasn't written by one. If you need to communicate with a Spanish speaker, it will work quite well. If you need to write a brochure or something formal... better get someone to translate for you.
- Tomek_ 16y agoWell, that's quite obvious, Google Translate is not perfect, e.g. overuses "Usted/Ustedes" or often gets lost when there's a lot of pronouns and missed "yo", "tu", "el", but: a) with a little big of knowledge about the language and bit of editing you can overcome most of those stuff b) even without editing it makes most of the stuff readable/understandable c) works much better that competitive products (babblefish).
- jbpr 16y agoAnother similar project: https://github.com/caius/gtranslate https://github.com/caius/gtranslate
- swah 16y agoTranslate fail already... user won't understand that 'joya' means a Ruby gem :)
- burgerbrain 16y agoIn context, and with the slightest amount of deductive reasoning, I don't see why they wouldn't.
- swah 16y agoSure, but those can read basic english too.
- deleted 16y ago[deleted]
- stevenbedrick 16y agoSince this gem appears to use Google's public API, one important thing to keep in mind is that there's probably a hard limit on the amount of text that can be translated at one go. I've found that throwing more than a thousand or so characters at GT's API results in their server throwing "URI too long" errors, since it only works via HTTP GET. Disclaimer: This might have changed in the five or six months since I last messed around with Google's API, or, alternatively, this gem could be doing something clever to try and get around the problem. Either way, I'd suggest checking it out.
- alex_c 16y agoFrom memory, other limitations include 100,000 characters per day, and limits on where the API can be used (e.g. can't use it for paid services).
- mjuhl24 16y agoThis is cool, but no one should ever use this. I've used the google translator frequently, and while it's good, it always requires me to use my knowledge of the language I'm translating to in order to create a more correct and meaningful translation. If you really want a site or app that is multilingual, you need a human with good knowledge of the language to do your translations.