履歴: ソフトウェア/rails/言語ネゴシエーション

各行は、その日時に書かれた内容です。追加・削除は、1 つ前の版との行数の差です (全 21 版)。「差分」は比較する版、「基準」は比べる相手の版を選びます

日時タイトル文字数追加削除内容差分基準
2014/5/20 19:20:23ソフトウェア/rails/言語ネゴシエーション 最新版3,891+1 -1表示差分—
2014/5/20 19:20:23ソフトウェア/rails/言語ネゴシエーション 3,897+8 -1表示差分選択
2013/1/5 18:30:15ソフトウェア/rails/言語ネゴシエーション 3,842+3 -0表示差分選択
2009/7/14 9:35:50ソフトウェア/rails/言語ネゴシエーション 3,732+43 -27表示差分選択
2009/7/11 15:06:20ソフトウェア/rails/言語ネゴシエーション 3,727+9 -0表示差分選択
2009/6/28 2:02:38ソフトウェア/rails/言語ネゴシエーション 3,515+2 -0表示差分選択
2009/6/27 8:15:42ソフトウェア/rails/言語ネゴシエーション 3,458+4 -0表示差分選択
2009/6/21 9:14:00ソフトウェア/rails/言語ネゴシエーション 3,403+15 -0表示差分選択
2009/6/21 6:41:27ソフトウェア/rails/言語ネゴシエーション 3,126+62 -2793表示差分選択
2009/6/10 11:14:13ソフトウェア/rails/言語ネゴシエーション 84,051+327 -1表示差分選択
2009/6/10 3:14:21ソフトウェア/rails/言語ネゴシエーション 73,730+459 -3表示差分選択
2009/6/9 15:42:54ソフトウェア/rails/言語ネゴシエーション 58,379+247 -473表示差分選択
2009/6/9 11:29:37ソフトウェア/rails/言語ネゴシエーション 66,074+317 -40表示差分選択
2009/6/8 20:22:16ソフトウェア/rails/言語ネゴシエーション 58,607+75 -2表示差分選択
2009/6/8 15:18:39ソフトウェア/rails/言語ネゴシエーション 55,917+958 -223表示差分選択
2009/6/8 8:00:44ソフトウェア/rails/言語ネゴシエーション 33,858+247 -35表示差分選択
2009/6/7 13:55:06ソフトウェア/rails/言語ネゴシエーション 28,314+195 -18表示差分選択
2009/6/7 4:15:30ソフトウェア/rails/言語ネゴシエーション 23,332+140 -3表示表示中選択
2009/6/6 14:50:13ソフトウェア/rails/言語ネゴシエーション 19,622+30 -27表示差分基準
2009/6/6 6:50:47ソフトウェア/rails/言語ネゴシエーション 19,701+581 -3表示差分選択
2009/6/6 2:59:56ソフトウェア/rails/言語ネゴシエーション 2,869— —表示—選択

基準: ソフトウェア/rails/言語ネゴシエーション (2009/6/6 14:50:13) → 比較: ソフトウェア/rails/言語ネゴシエーション (2009/6/7 4:15:30)

@@ -650,8 +650,6 @@
* ページキャッシュの多言語対応 [#z6cc2a4b]
-キャッシュファイルは ActionController::Caching が作成する。
-
まずは rails そのままで、ページキャッシュ機能をONにしてみる。
LANG:console
@@ -681,4 +679,143 @@
public/test.html public/test.en
test.html というファイルができてしまうと、
-次回からは常にこれが表示されてしまうため、うまくいかない。
+次回からは言語設定にかかわらず常にこれが表示されてしまうため、うまくいかない。
+
+ページキャッシュは ActionController::Caching::Pages が作成する。~
+このときファイル名に言語指定を正しく付ければよい。
+
+ファイル名に付ける言語指定は、path として指定された物では無く、
+実際に使ったテンプレートの言語にすべき。
+
+ちなみに cache_page が暗黙に呼び出される時、引数は与えられないので、
+キャッシュファイル名は request.path から作る事になる。
+
+ LANG:ruby(linenumber)
+ module ActionController::Caching::Pages
+ def cache_page(content = nil, options = nil)
+ return unless perform_caching && caching_allowed
+
+ path = case options
+ when Hash
+ url_for(options.merge(
+ :only_path => true,
+ :skip_relative_url_root => true,
+ :format => params[:format],
+ :rails_language => request.language))
+ when String
+ options
+ else
+ p= request.path.split('.')
+ p.pop if ActionController::AbstractRequest.acceptable_language?(p.last)
+ p[0]+= self.class.page_cache_extension if p.count==1
+ p << request.language
+ p.join('.')
+ end
+
+ self.class.cache_page(content || response.body, path)
+ end
+ end
+
+** テスト [#t5c0d140]
+
+ LANG:console
+ $ rm -r public/test*
+ $ wgetc -qO- http://localhost:3000/test
+ English: Test OK
+
+ $ ls public/test* public/test*/*
+ public/test.html.en
+ $ wgetc -qO- http://localhost:3000/test.en
+ English: Test OK
+
+ $ ls public/test* public/test*/*
+ public/test.html.en
+ $ wgetc -qO- http://localhost:3000/test.ja
+ 日本語:テスト ばっちり
+
+ $ ls public/test* public/test*/*
+ public/test.html.en public/test.html.ja
+ $ wgetc -qO- http://localhost:3000/test
+ 日本語:テスト ばっちり
+
+ $ ls public/test* public/test*/*
+ public/test.html.en public/test.html.ja
+ $ wgetc -qO- http://localhost:3000/test/index
+ 日本語:テスト ばっちり
+
+ $ ls public/test* public/test*/*
+ public/test.html.en public/test.html.ja
+
+ public/test:
+ index.html.ja
+ $ wgetc -qO- http://localhost:3000/test/index/0
+ 日本語:テスト ばっちり
+
+ $ ls public/test* public/test*/*
+ public/test.html.en public/test.html.ja public/test/index.html.ja
+
+ public/test:
+ index index.html.ja
+
+ public/test/index:
+ 0.html.ja
+ $ wgetc -qO- http://localhost:3000/test/index/0.html
+ 日本語:テスト ばっちり
+
+ $ ls public/test* public/test*/*
+ public/test.html.en public/test.html.ja public/test/index.html.ja
+
+ public/test:
+ index index.html.ja
+
+ public/test/index:
+ 0.html.ja
+ $ wgetc -qO- http://localhost:3000/test/index/0.html.ja
+ 日本語:テスト ばっちり
+
+ $ ls public/test* public/test*/*
+ public/test.html.en public/test.html.ja public/test/index.html.ja
+
+ public/test:
+ index index.html.ja
+
+ public/test/index:
+ 0.html.ja
+
+* アクションキャッシュ [#gd9d14bc]
+
+まずは rails そのままで、アクションキャッシュ機能をONにしてみる。
+
+ LANG:console
+ $ jed app/controller/test_controller.rb
+ class TestController < ApplicationController
+ # caches_page :index
+ caches_action :index
+ def index
+ end
+ end
+ $ wgetc -qO- http://localhost:3000/test.en
+ English: Test OK
+
+
+ $ tail log/development.log
+ Processing TestController#index (for 127.0.0.1 at 2009-06-07 13:14:18) [GET]
+ Cached fragment hit: views/localhost:3000/test (0.1ms)
+ Rendering template within layouts/application
+ Rendering test/index
+ Rendered test/_ok (0.4ms)
+ Cached fragment miss: views/localhost:3000/test (0.1ms)
+ Completed in 15ms (View: 8, DB: 0) | 200 OK [http://localhost/test]
+ $ wgetc -qO- http://localhost:3000/test
+ English: Test OK
+
+
+ $ wgetc -qO- http://localhost:3000/test.en
+ Processing TestController#index (for 127.0.0.1 at 2009-06-07 13:04:57) [GET]
+ Parameters: {"rails_language"=>"en"}
+ Cached fragment hit: views/localhost:3000/test?format=en (0.1ms)
+ Rendering template within layouts/application
+ Rendering test/index
+ Rendered test/_ok (0.4ms)
+ Cached fragment miss: views/localhost:3000/test?format=en (0.1ms)
+ Completed in 13ms (View: 8, DB: 0) | 200 OK [http://localhost/test.en]