履歴: ソフトウェア/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 6:50:47) → 比較: ソフトウェア/rails/言語ネゴシエーション (2009/6/7 4:15:30)
@@ -383,7 +383,7 @@
return template_path if template_path.respond_to?(:render)
path = template_path.sub(/^\//, '')
- if m = path.match(/(.*)\.(\w+)$/) && ActionView::Template.valid_extension?(m[2])
+ if ( m = path.match(/(.*)\.(\w+)$/) ) && ActionView::Template.template_handler_extensions.include?(m[2])
template_file_name, template_file_extension = m[1], m[2]
else
template_file_name = path
@@ -650,32 +650,172 @@
* ページキャッシュの多言語対応 [#z6cc2a4b]
-キャッシュファイルは ActionController::Caching が作成する。
-ファイルの名前を付ける部分で url_for が呼ばれているので、
-この引数に :rails_language を渡せばよい。
+まずは rails そのままで、ページキャッシュ機能をONにしてみる。
+ LANG:console
+ $ jed config/environments/development.rb
+ config.action_controller.perform_caching = true
+ $ jed app/controller/test_controller.rb
+ class TestController < ApplicationController
+ caches_page :index
+ def index
+ end
+ end
+ $ wgetc -qO- http://localhost:3000/test
+ English: Test OK
+
+
+ $ ls public/test*
+ public/test.html
+ $ cat public/test.html
+ English: Test OK
+
+
+ $ wgetc -qO- http://localhost:3000/test.en
+ English: Test OK
+
+
+ $ ls public/test*
+ public/test.html public/test.en
+
+test.html というファイルができてしまうと、
+次回からは言語設定にかかわらず常にこれが表示されてしまうため、うまくいかない。
+
+ページキャッシュは ActionController::Caching::Pages が作成する。~
+このときファイル名に言語指定を正しく付ければよい。
+
+ファイル名に付ける言語指定は、path として指定された物では無く、
+実際に使ったテンプレートの言語にすべき。
+
+ちなみに cache_page が暗黙に呼び出される時、引数は与えられないので、
+キャッシュファイル名は request.path から作る事になる。
+
LANG:ruby(linenumber)
- module ActionController
- module Caching
- def cache_page(content = nil, options = nil)
- return unless perform_caching && caching_allowed
+ 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
- request.path
- end
+ 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
+ self.class.cache_page(content || response.body, path)
end
end
-** テスト [#mee8ebea]
+** テスト [#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]