Dynamically detect Language and add CSS accordingly

by Noman Muhammad

In blog sites the blog owner allows visitors to comment on his blog post. If the site is local or regional like Somewherein, Amar Blog some visitors have tendency to put comment in their native language, on the other hand some visitors always put comments in english. There is a small problem when displaying the comments on the site. If the blog owner has a class for the div where all the comments will be displayed and define font-family for english language then bangla comments will be very difficult to see and vice-versa. So if we can dynamically detect the language of each comments and define separate classes for different language we can show the comments in appropriate way. Google Code provides an API to detect the language of content. We can use this for our purpose. Here i'll show a simple implementation to assign different DIV class for different Languages.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<script src="http://www.google.com/jsapi?key=API_KEY"></script>
<script type="text/javascript">

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

function initialize() {
var text = document.getElementById("text").innerHTML;

// Detect the language of the text.
google.language.detect(text, function(result) {
var detected = document.getElementById("detected");
// If there wasn't an error in the request
if (!result.error) {
var langCode = result.language;
var langName;

// Loop through the languages enum so that we can find the actual name of the language.
// Learn about the languages enum here:
// http://code.google.com/apis/ajaxlanguage/documentation/reference.html#LangNameArray
for (var i in google.language.Languages) {
var thisLangCode = google.language.Languages[i];
if (thisLangCode == langCode) {
// If we find the language code, store the language name.
langName = i;
break;
}
}

// Se the detected language.
if(langName == "BENGALI")
{
document.getElementById("text").setAttribute("class", "bn");
}
else
{
document.getElementById("text").setAttribute("class", "en");
}
}
});
}
google.setOnLoadCallback(initialize);

</script>
</head>
<body>
<div id="content">
<div id="text">share-facts.blogspot.com</div>
<div id="detected"/>
</div>
</body>
</html>


Here content of the DIV with id="text" will be examined then the class of that DIV will added accordingly.

Note: on line 5 API_KEY will be replaced by a valid API key.

Simple cURL example using PHP

by Noman Muhammad

cURL library allows us to connect to different servers using a variety of protocols. This is used for transferring files with URL syntax. In most of the cases we use cURL to display a specific portion of another site in our site. By using cURL at first we retrieve the contents of the site that we targeted and then parse the retrieved contents to show the specific portion using preg_match(). Here I'll show a simple example to retrieve and show the stock market price in my site from Yahoo!. At first I have to open Yahoo! in my browser. Then view the source of the page and identify that the stock market price is shown in between <dl class="markets clearfix strong small"> and </dl>. So this is my targeted portion. I'll use this tag to excerpt my targeted portion from the total contents. Full code is as follows:


<html>
<head>
<title>cURL Example</title>
</head>
<body>
<div style="margin-left:30px">
<?php
//URL of targeted site
$url = "http://m.www.yahoo.com/";
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// grab URL and pass it to the browser

$output = curl_exec($ch);

//Regular expression to excerpt the targeted portion
preg_match('/<dl class="markets clearfix strong small">(.*)<\/dl>/is', $output, $matches);
echo $matches[0];

// close curl resource, and free up system resources
curl_close($ch);
?>
</div>
</body>
</html>


Very simple, isn't it? Now by using our own css we can show the data in our own way.

Fixing Transparent Image in IE6

by Noman Muhammad

IE6 doesn't support transparent image. There are many ways to use transparent image in IE6. Here is a way that I use to show the transparent image in IE6 using CSS. CSS part for it is as bellows.


#header
{
background:url(logo.png) no-repeat;
height:109px;
width:507px;
}

*html #header
{
background-image:none;
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="logo.png");
}


this "*html #header" part is only for IE6 i.e only IE6 will recognize this portion. One drawback of using this is we have to use absolute url to the image (i.e if logo.png is in the images folder(not in the css folder) of the site we have to write absolute url to that image. like: http://www.mysitename.com/images/logo.png).
Another drawback is links (i.e <a></a>) somwtimes become unclickable and forms become unfocusable. To get rid of it we have use postion:relative for a tag. i.e

a
{
postion:relative;
}

Bangla Typing using Google Transliteration

by Noman Muhammad

We can use Google Transliteration to type in Bengali on any web-site. It converts English characters to the characters used in Bengali. It offers us to type Bengali words phonetically in English script and then have them appear in Bengali. Its not translation, it does not change meaning rather it simply converts the sound of the word from English alphabet to Bengali alphabet. For example, typing "Bangladesh" transliterates into Bengali as বাংলাদেশ.
Its a small piece of code that stores on our browser(s). Visit this link to know how to enable this option to the various browsers.

Some Interesting Google Search Technique

by Noman Muhammad

We always search our query in Google. There are huge set of techniques by which we can search in Google more accurately. I collect and show some of them here that I frequently use. Those techniques are very simple but provide very fruitful result :) .

1. Whenever we search for more than one keyword (i.e. computer programming, here we use 2 key word. a) computer b) programming) at a time Google will handle this keyword using a method called Boolean Default. Google's Boolean default is 'AND'; that means if we enter query words without modifiers, Google will search for all of them. If we search for:

computer programming

Google will search for all the words. If we want to specify that either word is acceptable, we can put an 'OR' between each item:
computer OR programming

If we want to exclude a query item from search results, use a -.(minus sign or dash:
computer -programming

note that there is no space after the (-) sign.

2. To search for a phrase use "" surrounding the phrase. like:
"Some Interesting Google Search Technique"


3. Period (.) and Asterisk (*) can also be used as traditionally used.

4. To search anything from a specific site use 'site:site_name'.
google site:share-facts.blogspot.com

This will search for the term google only in the specified site.

note that there is no space after the (:) sign.

5. To restrict search to title of web pages we can use 'intitle:search_keyword'
intitle:google


6. Use 'inurl:search_keyword' to restrict search to the URLs of web pages.
inurl:google


7. To search in body text use 'intext:search_keyword'
intext:html


8.Searches for text in a page's link anchors
inanchor:"google desktop"


9. To search for a specific filetype use 'filetype:desired_file_type'
bangladesh filetype:pdf


10. To search a copy of the page that Google indexed even if that site/page is no longer available at its original URL or has since changed its content completely. This is particularly useful for site/pages that change often.
cache:share-facts.blogspot.com


11. To get the definition of search keyword 'define:search_keyword'.
define:physics


12. To find lyrics use
"lyrics_phrase" lyrics


13. To get the time of Dhaka
time dhaka

Adding Digg Button on Blogspot Post

by Noman Muhammad

Digg is the social content website where we submit our favorite content. Its a very good idea to have a button on the site content so that visitor easily submit that content to digg. To show digg button on blogger post we to put some code on the template.

1.) Find the below line on the blogger template (its found when "Expand Widget Templates" is clicked).

<p><data:post.body/></p>


2.) Now replace this above code with

<div style='float:left; margin-right:10px;'>
<script type='text/javascript'>
digg_url='<data:post.url/>';
</script>
<script src='http://digg.com/tools/diggthis.js' type='text/javascript'/>
</div>
<p><data:post.body/></p>

This will show the digg button on ur post's left top corner. To change button's orientation simply change div orientation.

Install Google Desktop on 64 bit Vista

by Noman Muhammad

Google Desktop can not be installed normally on 64 bit Windows Vista. But we can install it from command line by '/force'.

To do so, first download google desktop. Then open the Command prompt and go to the installer directory, type the command 'googledesktopsetup.exe /force' and press Enter. Thats all ...