Mahdi Taghizadeh I'm who I'm!

19Nov/095

Translating your content title using Google Translate API to use in a URL

Following my previous posts on How to handle non-English characters in ASP.NET MVC routes, Build pretty clean URL for your dynamic pages using JavaScript and Non English Words in URL I decided to share another simple tip that let you translate what your user inserts as content’s title (that can be a blog post title, a page name or a news headline) automatically using Google Translate API.

Let me explain it with an example. Suppose that you have a news system in Persian language and your end user enters a Persian phrase like “این یک عنوان خبر است” as the headline of a news story. From SEO point of view it’s better we include original headline words in URL (like something that I explained in this post) instead of using an integer ID or GUID (e.g. /news/?id=1 or /news/1.aspx, etc.) but as we discussed on in that post, including non-English characters in URLs is not the best way! I just wanted to have something like /news/story/this-is-a-title and didn’t want to force user translate his words into English in order to use in URL field.

A few days ago I was thinking on this topic and decided to try a trick to utilize Google Translate API (which has recently started supporting Persian language as well) to translate such titles into meaningful English phrases and then clean them using the way I described in this post.

Fortunately, thanks to Google API simplicity it was so easy and straightforward. Here’s what I wrote:

  1. First you should include Google API JavaScript source in your page:
    [cc lang='html4strict' line_numbers='false'][/cc]
  2. Add this JavaScript code to your page:
    [cc lang='javascript' line_numbers='false']
    $(document).ready(function() {

    $("#contentPage_Title").blur(function() { parseUrl($("#contentPage_Title").val()) });

    });

    google.load("language", "1");

    function parseUrl(url) {

    $("#loadingImage").attr("style", function() { return "display: inline;" });

    google.language.translate(url, "fa", "en", function(result) {

    if (!result.error) {

    var url = (result.translation + " ").replace(/[^a-zA-Z0-9]+/g, "-");

    $("#contentPage_Url").val(url.slice(0, url.length - 1).toLowerCase());

    $("#loadingImage").attr("style", function() { return "display: none;" });

    }

    });

    }
    [/cc]

You’re done! Now, let me explain the code a little. First using jQuery, you tell the DOM to fire parseUrl() event as soon as you enter the title and go to the next field, then, we load Google Translate service into our script, call translate function to translate from “fa” (Persian) to “en” (English) and finally clean the result using our old trick. That’s all and no magic here!

Please note that we show and hide a “Loading” element (e.g.: a loading image) before and after we call AJAX translate function. So user can see something is happening behind the scene.

kick it on DotNetKicks.com

15Oct/076

reCAPTCHA: Free CAPTCHA Solution For Your Website

Recently (and specially after Web 2.0 revolution) many websites started to use more complicated CAPTCHA solutions on their websites in order to prevent spam and bot attacks. There are many free solutions and tools for users and developers to implement CAPTCHA technology in their applications. There are also many ASP.NET controls and components for this approach but many of them are so simple to hijack or don't offer features that these days we see on professional websites (some features like reload function, voice, etc.).

A few days ago I found a link to reCAPTCHA on Yahoo!. reCAPTCHA is a free (but professional) tool for basic users and also developers. To use this service you should first signup, receive an API Key for your website (you can receive as many as you need) and use one of easy-to-install plugnins provided. And good news for ASP.NET developers is that you can download and use a server side control and enjoy reCAPTCHA with two lines of code! The API Key guarantees your website and prevents attackers collect answers from visitors and use them. There are three different themes to choose.

If you want to use reCAPTCHA on a Web 2.0 website you can use AJAX API just by adding this line of code to you html or webform file:

I strongly suggest you download and test this tool in your web applications.

Quick Links: reCAPTCHA.net | Live Demo | Why reCAPTCHA | Signup | reCAPTCHA.NET Control | Email Protection With reCAPTCHA

3Oct/070

Some ASP.NET Articles

Omar Al Zabir has recently listed 10 cool articles about ASP.NET, AJAX, ... which he has published this year. From my personal view these articles are interesting:

25Sep/075

New Gmail UI Coming

Since its launch, Gmail has been one of the most popular free email services on the web. Ease of use, huge storage space, amazing AJAX interface, POP3 features, etc. make Gmail a good choice for those who look for a free email service.

I think the sole weakness of Gmail is its very simple user interface. There were some movements to improve Gmail UI; for example Gmail Skins and Better Gmail extensions for FireFox. These days a blog post appeared on various blogs and websites such as Mashabale, Googling Google and BlogoWogo talking about a new Gmail UI. Everything started from a "Newer Version" word translation request on Google In Your Language program that was found by a user [See this image].

After Gmail Mobile inhancements in these days, it seems that Google wants to surprise their users with a great work in near future. We should wait!

P.S.: I think from the beauty point of view, only Google Analytics is pretty and eye catching and all other just offer powerfull features not a good looking environment!

Filed under: AJAX, Web, Web 2.0 5 Comments
17Sep/070

AJAX Loading Indicator GIF Generator

AjaxLoad is a good website for you to generate eye catching loading indicators in gif format. Just choose your desired indicator type from a list, choose background and foreground colors and click on Generate It!, then you can see a preview and download it as a .gif file easily.

Filed under: AJAX, Tools, Web 2.0 No Comments
1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|126|127|128|129|130|131|132|133|134|135|136|137|138|139|140|141|142|143|144|145|146|147|148|149|150|151|152|153|154|155|156|157|158|159|160|161|162|163|164|165|166|167|168|169|170|171|172|173|174|175|176|177|178|179|180|181|182|183|184|185|186|187|188|189|190|191|192|193|194|195|196|197|198|199|200|201|202|203|204|205|206|207|208|209|210|211|212|213| viagra sale in india in chemists sustituto de viagra pay with paypal for viagara viagra te koop in nederland levitra india generic average age for viagra viagra stories little blue pill yahoo the best viagra with no prescription vaginal viagra suppositories side effects ordering viagra online xxx pill viagra for man order viagra viagra online viagra from canada generic viagra shipped to the usa overnight infinimax viagra buy viagra without a prescription viagra with dapoxetine overnight deliveryAccutane Online Doxycycline online Buy Cheap Lexapro Online No Prescription Prednisone Online Buy Accutane No Prescription