Studio moh


Curry gives me the best ideas

Posted on Thursday, July 24th, 2008 at 12:15 am

So, I made curry tonight, and it gave me a really good idea:

What options does a non-English speaking user have when visiting an English-only website?
My server logs tell me they use Babelfish.

The problem with Babelfish (or any net-translator) is that it breaks the website. It pushes it through a Find-and-Replace dictionary of terms that completely changes your site. It also tends to ignore cookies, and really butchers your Javascript because of cross-domain issues.

What can web developers do?
What can you do if you don't have the funds to hire an extensive localization team?

Why not use Javascript to cycle through all the elements on a page that need to be translated (menu items, headlines, form labels, etc), and push them through to a web service (like, Yahoo! Pipes) to translate it for you! Use JSONP to get the results back and replace the text of the elements dynamically as they're loaded/translated.

$('h2, form p, form label, legend').each(function() {
var item = $(this);
var translate = encodeURI($(this).text());
$.getJSON('http://pipes.yahoo.com/pipes/pipe.run?_id=NsgXF0pZ3RG4DUvBjtzu1g&_render=json&translateStr=' + translate + '&_callback=?', function(data) {
item.text(data.value.items[0].translation);
});
});


I actually made a more optimized version that took an array of items to speed up translation/load time, but Yahoo! Pipes was down when I tried to save it, so it wouldn't let me. (I would also like to have it talk to a Flash file to dynamically save/cache translations as they're made).

Machine translation isn't perfect, but it's better than making your users go to Babelfish just to figure out how to login.

How Dylan avoids widows

Posted on Tuesday, July 22nd, 2008 at 12:05 am

Typographical widows, that is. Learning jQuery (an excellent blog, even for the power users) had a wonderful post on how to use jQuery to append widows.

(If you didn't take a print class in high school, a widow is a word that ends on the next line like
this.

This is a print master's nightmare and a typographical no-no.)

Their solution uses regular expressions, which is nice, but not the most efficient way to split strings, and a bit of a memory hog on older systems.

Why not use CSS property white-space: nowrap;?


$('h2').each(function() {
var h2Contents = $(this).html().split(" ");
h2Contents[h2Contents.length-2] = '<span style="white-space: nowrap; color: red;">' + h2Contents[h2Contents.length-2];
h2Contents[h2Contents.length-1] = h2Contents[h2Contents.length-1] + '</span>';
$(this).html(h2Contents.join(' '));
});


This snippit of jQuery wraps the last two words of every H2 tag with a span tag that has an inline style that prevents line-breaks. The result? No more widows without the performance hit of Regex.
« Older

Search

Tag Cloud

Feeds