<?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/"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
>

<channel>
	<title>クレコ &#187; CodeIgniter</title>
	<atom:link href="http://creco.net/tag/codeigniter/feed/" rel="self" type="application/rss+xml" />
	<link>http://creco.net</link>
	<description>East or west, home is best.</description>
	<lastBuildDate>Fri, 27 Nov 2009 13:26:56 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://creco.net/tag/codeigniter/feed/" />
		<item>
		<title>検索エンジンに対応した多言語化方法</title>
		<link>http://creco.net/2009/03/02/internationalization_for_search_engine_crawl/</link>
		<comments>http://creco.net/2009/03/02/internationalization_for_search_engine_crawl/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 09:40:17 +0000</pubDate>
		<dc:creator>inagaki</dc:creator>
				<category><![CDATA[日記]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[多言語化]]></category>
		<category><![CDATA[検索エンジン]]></category>

		<guid isPermaLink="false">http://creco.net/2009/03/02/internationalization_for_search_engine_crawl/</guid>
		<description><![CDATA[検索エンジン（まぁGoogleなんだけど）って、ひとつのURIに対してひとつの言語にしか対応してないんですね。
そんなわけで、単純に内部で言語を切り替えただけではクロールされる言語がひとつになってしまい、問題になってきま [...]]]></description>
			<content:encoded><![CDATA[<p>検索エンジン（まぁGoogleなんだけど）って、ひとつのURIに対してひとつの言語にしか対応してないんですね。</p>
<p>そんなわけで、単純に内部で言語を切り替えただけではクロールされる言語がひとつになってしまい、問題になってきます。<br />
そこで、多言語に対応したサイトの作り方をメモとして書いておく。</p>
<p><span id="more-126"></span></p>
<h4>有名なウェブサイトはどうなっている？</h4>
<p>多言語化に対応しているウェブサイトなんて沢山あるわけなんだけど、どうやって対応させるかを調査。</p>
<h5>Google</h5>
<p><a href="http://creco.net/wp-content/uploads/20090302-01.jpg" rel="lightbox[126]"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" src="http://creco.net/wp-content/uploads/20090302-01-thumb.jpg" border="0" alt="20090302_01" width="438" height="296" /></a></p>
<p>Googleの場合、ドメイン自体が<br />
<em><a href="http://www.google.com">www.google.com</a><br />
<a href="http://www.google.co.jp">www.google.co.jp</a></em><br />
と２つあり、<a href="http://www.google.com/intl/ja/">www.google.com/intl/ja/</a> と <a href="http://www.google.co.jp">www.google.co.jp</a> がほとんど同じような内容で日本語対応コンテンツとなっている。</p>
<p>つまり、 <strong>/intl/ja/</strong> の部分が多言語化に対応させた部分。</p>
<h5>Skype</h5>
<p><a href="http://creco.net/wp-content/uploads/20090302-02.jpg" rel="lightbox[126]"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" src="http://creco.net/wp-content/uploads/20090302-02-thumb.jpg" border="0" alt="20090302_02" width="438" height="296" /></a></p>
<p>Skypeの場合はドメインは <a href="http://www.skype.com">www.skype.com</a> のみ。<br />
そして、日本語対応コンテンツは <a href="http://www.skype.com/intl/ja/welcomeback/">www.skype.com/intl/ja/welcomeback/</a> 。welcomebackを削ってもリダイレクトされるので、Googleと同じく</p>
<p><strong>/intl/ja/</strong> の部分が多言語化に対応させた部分。</p>
<p>２つの事例しか見てないけど、/intl/ja/ のように階層を切って多言語化させるのがよさそう（何より、Googleがやってるんだから、間違いないでしょ！）。</p>
<h6>どうでもいい話</h6>
<p><strong>intl</strong> って今までイニシャライズ（initialize：初期化）の略で、スタートページだから初期化なんだよって勘違いしてた ＞＜</p>
<p>これって、インターナショナライゼーション（internatinalization：国際化）の略なんですね。</p>
<h4>CodeIgniterでの実装例</h4>
<p>内部での言語切り替えが済んでる人は飛ばしてください。</p>
<p>僕のやり方なので、多分はずれたやり方だと思うｗ</p>
<h5>前提：内部の国際化対応</h5>
<div id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:b2084124-502c-4ef0-b478-eeac16f66b5a" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="php">// 国際化
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) &amp;&amp; ereg('ja', $_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
	$config['language'] = 'japanese';
	$config['language_min'] = 'ja';
}else{
	$config['language'] = 'english';
	$config['language_min'] = 'en';
}</pre>
</div>
<p>こんな形で設定ファイル内でブラウザの <strong>HTTP_ACCEPT_LANGUAGE</strong> を読み取って、言語を設定。</p>
<div id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:d681f373-6909-45e4-9b4a-0dcbda8bc2ac" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="php">$this-&gt;lang-&gt;load('index', $this-&gt;config-&gt;item('language'));</pre>
</div>
<p>コントローラー内で言語ファイルの読み込み。</p>
<div id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:2edfaa9c-2562-4eda-9a9a-319154ccd2df" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="php">&lt;img src="hogehoge_&lt;?=$this-&gt;config-&gt;item('language_min')?&gt;.gif" alt="&lt;?=$this-&gt;lang-&gt;line('index_hogehoge')?&gt;" /&gt;</pre>
</div>
<p>ビューでは、前で設定した言語略称（language_min）を利用したファイル名の切り分けや言語ファイルでのテキスト行の読み込みを行います。</p>
<p>言語ファイルは、 /application/language/【言語名】/【言語ファイル名】_lang.php みたいな形で言語の数だけ作成します。</p>
<p>これだけだと、URIはひとつなので、次にroutes.phpを使った切り替え。</p>
<h5>routes.phpを使った言語の切り替え</h5>
<div id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:f58b901f-ecd3-4fba-90af-f75966a2919e" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="php">$route['intl/([a-z]{2})'] = "【class】/【function】/$1";</pre>
</div>
<p>毎度便利なroutes.php。こんだけでok。</p>
<p>functionはデフォルトコントローラーを使って、</p>
<div id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:99c5b6de-0c79-4f75-9719-fe8fe95fa544" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="php">	function index($language = "") {
		// 設定
		switch ($language){
			case 'ja':
				$this-&gt;config-&gt;set_item('language', 'japanese');
				$this-&gt;config-&gt;set_item('language_min', 'ja');
				break;
			case 'en':
				$this-&gt;config-&gt;set_item('language', 'english');
				$this-&gt;config-&gt;set_item('language_min', 'en');
				break;
		}
		$this-&gt;lang-&gt;load('index', $this-&gt;config-&gt;item('language'));</pre>
</div>
<p>みたいに、設定をコントローラーで強制的に上書きしちゃえばいいんじゃないかな。</p>
<h5>最後に、</h5>
<p>手動でも言語を切り替えできるようなリンクをビューに用意してあげて、あとは検索エンジンにうまくクロールされるのを待つだけ。</p>
<p>でも、ソーシャルブックマークのリンクの固定リンクをどこに設定するとか、ルートURLの言語は何にするとかは悩むところですね。</p>
]]></content:encoded>
			<wfw:commentRss>http://creco.net/2009/03/02/internationalization_for_search_engine_crawl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://creco.net/2009/03/02/internationalization_for_search_engine_crawl/" />
	</item>
		<item>
		<title>CodeIgniterのURIルーティングで.htaccessいらず</title>
		<link>http://creco.net/2009/02/26/i_love_codeigniters_uri_routing/</link>
		<comments>http://creco.net/2009/02/26/i_love_codeigniters_uri_routing/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 13:19:07 +0000</pubDate>
		<dc:creator>inagaki</dc:creator>
				<category><![CDATA[日記]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://creco.net/2009/02/26/i_love_codeigniters_uri_routing/</guid>
		<description><![CDATA[とりあえず、開発スピードを優先させるためにフルスクラッチで作ってたジオポですけど、これから、国際化対応させたり、DB使う場面が出てくると思うので、PHPのフレームワーク CodeIgniterに変換した。
フルスクラッチ [...]]]></description>
			<content:encoded><![CDATA[<p>とりあえず、開発スピードを優先させるためにフルスクラッチで作ってたジオポですけど、これから、国際化対応させたり、DB使う場面が出てくると思うので、PHPのフレームワーク CodeIgniterに変換した。</p>
<p>フルスクラッチは、コントローラーからビューだけをinclude()する方法で作っていたので、置き換えもスムース。そして、スピーディー。</p>
<ol>
<li><a href="http://codeigniter.com/">CodeIgniter</a>をダウンロード、展開</li>
<li>.htaccess 書き換え</li>
<li>config.php の設定</li>
<ul>
<li><em>$config['base_url']&#160;&#160;&#160; = &quot;http://&quot; . $_SERVER[&quot;HTTP_HOST&quot;];</em> としてローカル環境・本番環境でも切り替え必要なし。</li>
<li><em>//$config['index_page'] = &quot;index.php&quot;;</em> コメントアウト</li>
</ul>
<li>autoload.php の設定</li>
<ul>
<li>ライブラリのuser_agentとコンフィグに独自config</li>
</ul>
<li>コントローラーをクラス化してやり、少しの書き換え</li>
<li>同時に独自configファイルを作ってやる</li>
<ul>
<li>サーバ名を見て、ローカルだったらデバッグフラグ立てる</li>
<li>Google Maps APIがローカルだと使えない（localhostならいけるけど、プロジェクトごとに projectName.localhostとしてhostsの変更してるので&#8230;）</li>
</ul>
<li>ビューを配置</li>
<li>user_agents.php の書き換え</li>
<ul>
<li>日本向けの携帯設定と、iPhone判別を追加</li>
</ul>
</ol>
<p>こんだけです。多分、1時間もかかってないんじゃないかな？</p>
<h5>気づいたこと&#8594;routes.phpが素敵</h5>
<p>routes.php でクラス、メソッドの呼び出しがマッピングできるんだけど、正規表現が使えるからとっても便利。</p>
<p>今までは、.htaccessでmod_rewriteのために正規表現の条件処理を加えて、パラメータをクエリとして渡してやって、そのクエリをバリデートと分岐させるためにPHPの内部でも正規表現で条件分けしてた。</p>
<p>CodeIgniterだとそんなのいらない、</p>
<p>
<div class="wlWriterSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:463a41dd-44f4-406a-82aa-1f846d6b9698" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre name="code" class="php">$route['([0-9a-zA-Z_-]{1,10})'] = "geopo/mapGeopo/$1";</pre>
</div>
<p>これだけで完了。記述方法もとってもわかりやすい（たしか、Cakeだともっと複雑だった気が）。</p>
<p>そんなこんなで、これから国際化に向けてがんばろうっと。</p>
<h5>ブログで取り上げてもらった</h5>
<p><a title="ヅラずれなるままに(2009-02-26) - ジオポを試してみた" href="http://www.nilab.info/zurazure/20090226.html">ヅラずれなるままに(2009-02-26) &#8211; ジオポを試してみた</a></p>
<p>書いていただき、ありがとうございます。<br />
  <br />地図からの選択はわかりにくいかな？あのマーカーがドロップしたときの動きが好きで、あんな仕様にしたんだけど、後で変えて試してみっか。</p>
]]></content:encoded>
			<wfw:commentRss>http://creco.net/2009/02/26/i_love_codeigniters_uri_routing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://creco.net/2009/02/26/i_love_codeigniters_uri_routing/" />
	</item>
	</channel>
</rss>
