<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>I@laoer.com &#187; Google</title>
	<atom:link href="http://i.laoer.com/tag/google/feed" rel="self" type="application/rss+xml" />
	<link>http://i.laoer.com</link>
	<description>技术、生活、感悟 -- Laoer的博客</description>
	<lastBuildDate>Mon, 30 Jan 2012 10:03:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Google AdSense西联汇款收款</title>
		<link>http://i.laoer.com/google-adsense-western-union.html</link>
		<comments>http://i.laoer.com/google-adsense-western-union.html#comments</comments>
		<pubDate>Tue, 02 Jun 2009 06:30:23 +0000</pubDate>
		<dc:creator>Laoer</dc:creator>
				<category><![CDATA[博客文章]]></category>
		<category><![CDATA[Google]]></category>

		<guid isPermaLink="false">http://i.laoer.com/?p=341</guid>
		<description><![CDATA[上两次收Google Adsense的汇款，都是采用支票的方式，时间长，而且在中国银行办理还需要50-60元的手续费，后来在网上看到Google AdSense可以采用西联汇款收款，我也把我Google AdSense帐户里的付款方式改为了西联汇款，帐户里够了100美金，上个月底就看到了付款详情，今天我到农业银行，提取了这笔汇款，没有手续费，我直接换成人民币现金取走。 在设置西联汇款的时候有几个地方注意，它页面上虽然写了“为了领取您的付款，您需要持有政府核发的与以下收款人姓名完全一致的有效证件。”，但是在填写收款人姓名的时候还是写英文，并注意姓名的顺序，比如你的名字是“张三”，那要在“收款人名”填写“San”，“收款人姓”填写“Zhang”，到时持你的身份证到银行取款，是没有问题的。 在国内，西联汇款的代理机构是农业银行和邮政储蓄，在http://www.westernunion.cn/sc/location_search.php可以查到代理的网点，但好像不太准，我今天去的江宁路农业银行在上面就没有，我想应该是大一点的分行或是支行都应该有这样的业务。 到农业银行后先填写两张单子，一个是西联汇款的收汇单，里面收汇人和发汇人姓名地址都写英文，也就是你Google AdSense里留的信息，汇款监控号码非常重要，这也是表示这笔汇款的依据，另一张单子是个人结汇申请书，结汇类型是“现汇”，结汇资金入账方式选“取现”，结汇资金来源就选“其他”，结汇用途写“零用”，其实可以随便写的，之后一些必要的签字等等，连同身份证交给柜台上之后会按照当前的汇率兑换为人民币，拿到人民币就OK啦。]]></description>
			<content:encoded><![CDATA[<p>上两次收Google Adsense的汇款，都是采用支票的方式，时间长，而且在中国银行办理还需要50-60元的手续费，后来在<a href="http://blog.s135.com/post/400/" target="_blank">网上</a>看到Google AdSense可以采用西联汇款收款，我也把我Google AdSense帐户里的付款方式改为了西联汇款，帐户里够了100美金，上个月底就看到了付款详情，今天我到农业银行，提取了这笔汇款，没有手续费，我直接换成人民币现金取走。</p>
<p>在设置西联汇款的时候有几个地方注意，它页面上虽然写了“为了领取您的付款，您需要持有政府核发的与以下收款人姓名完全一致的有效证件。”，但是在填写收款人姓名的时候还是写英文，并注意姓名的顺序，比如你的名字是“张三”，那要在“收款人名”填写“San”，“收款人姓”填写“Zhang”，到时持你的身份证到银行取款，是没有问题的。</p>
<p>在国内，西联汇款的代理机构是农业银行和邮政储蓄，在<a href="http://www.westernunion.cn/sc/location_search.php" target="_blank">http://www.westernunion.cn/sc/location_search.php</a>可以查到代理的网点，但好像不太准，我今天去的江宁路农业银行在上面就没有，我想应该是大一点的分行或是支行都应该有这样的业务。</p>
<p>到农业银行后先填写两张单子，一个是西联汇款的收汇单，里面收汇人和发汇人姓名地址都写英文，也就是你Google AdSense里留的信息，汇款监控号码非常重要，这也是表示这笔汇款的依据，另一张单子是个人结汇申请书，结汇类型是“现汇”，结汇资金入账方式选“取现”，结汇资金来源就选“其他”，结汇用途写“零用”，其实可以随便写的，之后一些必要的签字等等，连同身份证交给柜台上之后会按照当前的汇率兑换为人民币，拿到人民币就OK啦。</p>
]]></content:encoded>
			<wfw:commentRss>http://i.laoer.com/google-adsense-western-union.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用Google API来取得Google帐户的联系人列表</title>
		<link>http://i.laoer.com/grab-google-contacts-by-google-api.html</link>
		<comments>http://i.laoer.com/grab-google-contacts-by-google-api.html#comments</comments>
		<pubDate>Thu, 12 Mar 2009 03:34:37 +0000</pubDate>
		<dc:creator>Laoer</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web2.0]]></category>
		<category><![CDATA[Google]]></category>

		<guid isPermaLink="false">http://i.laoer.com/?p=153</guid>
		<description><![CDATA[昨天写了一篇从Web Mail里取得用户通讯录的方法的文章，里面提到了Google的Account Authentication API，今天我们就用Account Authentication API和Google Contacts Data API来做一个取得Google帐户联系人的测试。 首先我们要看一下Account Authentication API，对于网络应用来说我们选择对网络应用程序的验证，对网络应用程序的验证也提供了 OAuth 和 AuthSub 两种认证方式，我们选择AuthSub的认证方式，认证过程如下图 用户在第三方Web应用上向Google Accounts Authentication发送AuthSub的HTTP请求，如果用户没有登录Google，则会显示登录页面，用户登录之后，会提示用户是否接受或拒绝这个第三方Web应用的访问请求，如果用户同意，Google就会生成一个token，转回第三方Web应用，第三方Web应用凭此token，可以请求Google的相关Sevice，比如联系人的服务，从而取得相关数据。 AuthSub有两种接口，一个是AuthSubRequest(A call to this method sends the user to a Google Accounts web page, where the user is given the opportunity to log in and grant Google account access to the web application. If successful, Google [...]]]></description>
			<content:encoded><![CDATA[<p>昨天写了一篇从Web Mail里取得用户通讯录的方法的文章，里面提到了Google的<a href="http://code.google.com/intl/zh-CN/apis/accounts/" target="_blank">Account Authentication API</a>，今天我们就用<a href="http://code.google.com/intl/zh-CN/apis/accounts/" target="_blank">Account Authentication API</a>和<a href="http://code.google.com/apis/contacts/" target="_blank">Google Contacts Data API</a>来做一个取得Google帐户联系人的测试。</p>
<p>首先我们要看一下<a href="http://code.google.com/intl/zh-CN/apis/accounts/" target="_blank">Account Authentication API</a>，对于网络应用来说我们选择<a href="http://code.google.com/intl/zh-CN/apis/accounts/docs/AuthForWebApps.html">对网络应用程序的验证</a>，对网络应用程序的验证也提供了 <a href="http://code.google.com/intl/zh-CN/apis/accounts/docs/OAuth.html">OAuth</a> 和 <a href="http://code.google.com/intl/zh-CN/apis/accounts/docs/AuthSub.html">AuthSub</a> 两种认证方式，我们选择AuthSub的认证方式，认证过程如下图</p>
<p><img class="alignnone size-full wp-image-154" title="Google Authsub Diagram" src="http://i.laoer.com/wp-content/uploads/2009/03/authsubdiagram.png" alt="Google Authsub Diagram" width="600" /></p>
<p>用户在第三方Web应用上向Google Accounts Authentication发送AuthSub的HTTP请求，如果用户没有登录Google，则会显示登录页面，用户登录之后，会提示用户是否接受或拒绝这个第三方Web应用的访问请求，如果用户同意，Google就会生成一个token，转回第三方Web应用，第三方Web应用凭此token，可以请求Google的相关Sevice，比如联系人的服务，从而取得相关数据。</p>
<p>AuthSub有两种接口，一个是<a href="http://code.google.com/intl/zh-CN/apis/accounts/docs/AuthSub.html#AuthSubRequest">AuthSubRequest</a>(A call to this method sends the user to a Google Accounts web page, where the user is given the opportunity to log in and grant Google account access to the web application. If successful, Google provides a single-use authentication token, which the web application can use to access the user&#8217;s Google service data.)另一个是<a href="http://code.google.com/intl/zh-CN/apis/accounts/docs/AuthSub.html#AuthSubSessionToken">AuthSubSessionToken</a>(A call to this method allows the web application to exchange a single-use token for a session token)，按照Google文档的理解，<a href="http://code.google.com/intl/zh-CN/apis/accounts/docs/AuthSub.html#AuthSubRequest">AuthSubRequest</a>是一个单次的认证，<a href="http://code.google.com/intl/zh-CN/apis/accounts/docs/AuthSub.html#AuthSubSessionToken">AuthSubSessionToken</a>应该是带会话(Session)的。</p>
<p>我们就举Google提供的例子</p>
<pre>https://www.google.com/accounts/AuthSubRequest?
   next=http%3A%2F%2Fwww.yourwebapp.com%2Fshowcalendar.html
   &amp;scope=http%3A%2F%2Fwww.google.com%2Fcalendar%2Ffeeds%2F
   &amp;session=1
   &amp;secure=1</pre>
<p>https://www.google.com/accounts/AuthSubRequest就是AuthSub请求的地址，next表示认证之后要转回的地址，一般就是第三方Web应用的地址，也就是你网站的一个地址，Google会把token附带到这个地址后面，scope是你要请求的Google服务地址，这个例子里是要访问Google日历的数据，另外两个参数看Google的文档吧。</p>
<p>接下来，我们要取得Google帐户的联系人，我们先看看Google提供了多少可以访问的服务吧，访问<a href="http://code.google.com/intl/zh-CN/apis/gdata/" target="_blank">Google数据API</a>，Google提供的数据还着不少，有日历、文档、图书搜索、网路相册等等，当然也包括我们所需要的<a href="http://code.google.com/intl/zh-CN/apis/contacts/" target="_blank">联系人的API</a>，Google数据API要好好了解一下，总体来说Google提供一个Gdata的数据格式，和RSS的feed类似的格式，通过相关服务的访问地址，就可以返回Gdata数据，至于Gdata的读取，已经有了很多程序语言的封装好的程序(<a href="http://code.google.com/intl/zh-CN/apis/gdata/clientlibs.html" targer="_blank">http://code.google.com/intl/zh-CN/apis/gdata/clientlibs.html</a>)，直接用就可以了，我们用PHP举例，PHP对Gdata的封装，是Zend Framework里的Gdata包，在<a href="http://framework.zend.com/download/gdata" target="_blank">http://framework.zend.com/download/gdata</a>下载就可以了，但是现在Zend Gdata的包里没有直接的Google contacts的组件，但不要紧，通过Zend Gdata里基础数据的访问，可以取得Google contacts。</p>
<p>我们看看Google Contacts Data API的<a href="http://code.google.com/intl/zh-CN/apis/contacts/developers_guide_protocol.html" target="_blank">开发人员指南</a>吧，取得联系人的Feed URL是</p>
<pre>http://www.google.com/m8/feeds/contacts/<var>userEmail</var>/full
或 

http://www.google.com/m8/feeds/contacts/default/full</pre>
<p>那我们就用PHP来写一个取得联系人的程序吧</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Zend/Loader.php'</span><span style="color: #339933;">;</span>
Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Zend_Gdata'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Zend_Gdata_AuthSub'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Zend_Gdata_ClientLogin'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Zend_Gdata_Query'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Zend_Gdata_Feed'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$my_contacts</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.google.com/m8/feeds/contacts/default/full'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span> <span style="color: #990000;">isset</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_SESSION</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cal_token'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_GET</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'token'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// You can convert the single-use token to a session token.</span>
		<span style="color: #000088;">$session_token</span> <span style="color: #339933;">=</span> Zend_Gdata_AuthSub<span style="color: #339933;">::</span><span style="color: #004000;">getAuthSubSessionToken</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_GET</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'token'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Store the session token in our session.</span>
		<span style="color: #000088;">$_SESSION</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cal_token'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$session_token</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Display link to generate single-use token</span>
		<span style="color: #000088;">$googleUri</span> <span style="color: #339933;">=</span> Zend_Gdata_AuthSub<span style="color: #339933;">::</span><span style="color: #004000;">getAuthSubTokenUri</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'http://'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_SERVER</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_NAME'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_SERVER</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$my_contacts</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Click &lt;a href='<span style="color: #006699; font-weight: bold;">$googleUri</span>'&gt;here&lt;/a&gt; &quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;to authorize this application.&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exit</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Create an authenticated HTTP Client to talk to Google.</span>
<span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> Zend_Gdata_AuthSub<span style="color: #339933;">::</span><span style="color: #004000;">getHttpClient</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_SESSION</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cal_token'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$gdata</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$client</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_Query <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$my_contacts</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//$query-&gt;setMaxResults(10);</span>
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMaxResults</span> <span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">2000</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFeed</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$query</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$feed</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$entry</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000088;">$parts</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getExtensionElements</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$parts</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$p</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$element</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDOM</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tagName</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'email'</span> <span style="color: #339933;">:</span>
				<span style="color: #b1b100;">print</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Email: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAttribute</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'address'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'phoneNumber'</span> <span style="color: #339933;">:</span>
				<span style="color: #b1b100;">print</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Phone: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">default</span> <span style="color: #339933;">:</span>
				<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>放在你服务器上运行一下吧（别忘了Zend Gdata包要加进去）。</p>
]]></content:encoded>
			<wfw:commentRss>http://i.laoer.com/grab-google-contacts-by-google-api.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>从JavaEye上找的Google翻译JavaScript脚本</title>
		<link>http://i.laoer.com/google-translate-javascript-from-javaeye.html</link>
		<comments>http://i.laoer.com/google-translate-javascript-from-javaeye.html#comments</comments>
		<pubDate>Mon, 23 Feb 2009 07:10:49 +0000</pubDate>
		<dc:creator>Laoer</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Google]]></category>

		<guid isPermaLink="false">http://i.laoer.com/?p=99</guid>
		<description><![CDATA[在Blog或新闻发布的时候，我们希望URL是一段有意义的字串，例如我Blog里的《Linux下切分Tomcat的catalina.out日志文件》文章链接是http://i.laoer.com/2009/02/18/rotating-catalina-out-in-tomcat-using-cronolog/，这样有利于SEO（搜索引擎优化），对于我们母语为中文的小虾，有时候要翻译标题还是有点头疼的，还好有了Google翻译，让翻译的事情变得简单了一点，但对于开发者，怎么使用户也方便的翻译，特别是在写Blog的时候就能把标题翻译好，还要动点脑筋，我看到JavaEye里发布新闻的地方有个“让Google帮助生成永久链接”的功能挺好的，看了一下他们的源码，得到以下这段，顺别也解释一下 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 &#60;script type=&#34;text/javascript&#34; src=&#34;http://www.google.com/jsapi&#34;&#62;&#60;/script&#62; //载入Google的jsapi &#160; &#60;script type=&#34;text/javascript&#34;&#62; &#160; function slugify&#40;str&#41; &#123; //这个方法应该是将字符转为小写，并把一些特殊字符转为&#34;-&#34; return str.toLowerCase&#40;&#41;.replace&#40;/[^a-z0-9-_]+/g, '-'&#41;.replace&#40;/^-&#124;-$/g, ''&#41;; &#125; &#160; google.load&#40;&#34;language&#34;, &#34;1&#34;&#41;; //载入Google的language Ajax库 &#160; function translate_title&#40;&#41; &#123; //这里就是翻译文章标题了，里面的方法需要jQuery支持，之前要引入jQuery的包，这里就省略了 if&#40;$F&#40;&#34;news_title&#34;&#41;.blank&#40;&#41;&#41; &#123; alert&#40;&#34;请先填写标题&#34;&#41;; return; [...]]]></description>
			<content:encoded><![CDATA[<p>在Blog或新闻发布的时候，我们希望URL是一段有意义的字串，例如我Blog里的《Linux下切分Tomcat的catalina.out日志文件》文章链接是http://i.laoer.com/2009/02/18/rotating-catalina-out-in-tomcat-using-cronolog/，这样有利于SEO（搜索引擎优化），对于我们母语为中文的小虾，有时候要翻译标题还是有点头疼的，还好有了<a href="http://translate.google.cn/" target="_blank">Google翻译</a>，让翻译的事情变得简单了一点，但对于开发者，怎么使用户也方便的翻译，特别是在写Blog的时候就能把标题翻译好，还要动点脑筋，我看到<a href="http://www.javaeye.com" target="_blank">JavaEye</a>里发布新闻的地方有个“让Google帮助生成永久链接”的功能挺好的，看了一下他们的源码，得到以下这段，顺别也解释一下</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;http://www.google.com/jsapi&quot;&gt;&lt;/script&gt; //载入Google的jsapi
&nbsp;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>  
&nbsp;
  <span style="color: #003366; font-weight: bold;">function</span> slugify<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//这个方法应该是将字符转为小写，并把一些特殊字符转为&quot;-&quot;</span>
    <span style="color: #000066; font-weight: bold;">return</span> str.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/[^a-z0-9-_]+/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'-'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^-|-$/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  google.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;language&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//载入Google的language Ajax库</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">function</span> translate_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//这里就是翻译文章标题了，里面的方法需要jQuery支持，之前要引入jQuery的包，这里就省略了</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$F<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;news_title&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">blank</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;请先填写标题&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;news_slug_url&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;正在翻译中...&quot;</span><span style="color: #339933;">;</span>
    google.<span style="color: #660066;">language</span>.<span style="color: #660066;">translate</span><span style="color: #009900;">&#40;</span>$F<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;news_title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;zh&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;en&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>result.<span style="color: #660066;">error</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;news_slug_url&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> slugify<span style="color: #009900;">&#40;</span>result.<span style="color: #660066;">translation</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>  
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>这里有个地方要说一下，<a href="http://code.google.com/apis/ajaxlibs/" target="_blank">Google的Ajax库API</a>还是挺好的，可以load几种Ajax的库，另外<a href="http://code.google.com/intl/zh-CN/webtoolkit/" target="_blank">Google的Web 工具</a>包也可以看看。</p>
]]></content:encoded>
			<wfw:commentRss>http://i.laoer.com/google-translate-javascript-from-javaeye.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

