locale_rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/ChangeLog +7 -0
  2. data/NEWS +7 -0
  3. data/README +33 -0
  4. data/Rakefile +72 -0
  5. data/doc/classes/ActionController/Base.html +442 -0
  6. data/doc/classes/ActionController/Caching.html +348 -0
  7. data/doc/classes/ActionController/Caching/Fragments.html +424 -0
  8. data/doc/classes/ActionView/Base.html +422 -0
  9. data/doc/classes/I18n.html +492 -0
  10. data/doc/classes/Locale.html +364 -0
  11. data/doc/created.rid +1 -0
  12. data/doc/files/ChangeLog.html +355 -0
  13. data/doc/files/README.html +409 -0
  14. data/doc/files/lib/locale_rails/action_controller_rb.html +349 -0
  15. data/doc/files/lib/locale_rails/action_view_rb.html +349 -0
  16. data/doc/files/lib/locale_rails/i18n_rb.html +342 -0
  17. data/doc/files/lib/locale_rails/version_rb.html +342 -0
  18. data/doc/files/lib/locale_rails_rb.html +349 -0
  19. data/doc/fr_class_index.html +7 -0
  20. data/doc/fr_file_index.html +8 -0
  21. data/doc/fr_method_index.html +11 -0
  22. data/doc/index.html +1 -0
  23. data/doc/rdoc-style.css +320 -0
  24. data/lib/locale_rails.rb +18 -0
  25. data/lib/locale_rails/action_controller.rb +141 -0
  26. data/lib/locale_rails/action_view.rb +43 -0
  27. data/lib/locale_rails/i18n.rb +56 -0
  28. data/lib/locale_rails/version.rb +4 -0
  29. data/locale_rails-0.1.0.gem +0 -0
  30. data/sample/README +22 -0
  31. data/sample/Rakefile +10 -0
  32. data/sample/app/controllers/application.rb +41 -0
  33. data/sample/app/controllers/samples_controller.rb +30 -0
  34. data/sample/app/helpers/application_helper.rb +3 -0
  35. data/sample/app/views/layouts/samples.html.erb +20 -0
  36. data/sample/app/views/samples/#cookie.rb# +3 -0
  37. data/sample/app/views/samples/_part.html.erb +68 -0
  38. data/sample/app/views/samples/_part_nl.html.erb +2 -0
  39. data/sample/app/views/samples/cached_action.html.erb +6 -0
  40. data/sample/app/views/samples/index.html.erb +24 -0
  41. data/sample/app/views/samples/index_uz_UZ.html.erb +15 -0
  42. data/sample/config/boot.rb +109 -0
  43. data/sample/config/database.yml +22 -0
  44. data/sample/config/environment.rb +25 -0
  45. data/sample/config/environments/development.rb +17 -0
  46. data/sample/config/environments/production.rb +24 -0
  47. data/sample/config/environments/test.rb +22 -0
  48. data/sample/config/initializers/inflections.rb +10 -0
  49. data/sample/config/initializers/mime_types.rb +5 -0
  50. data/sample/config/initializers/new_rails_defaults.rb +17 -0
  51. data/sample/config/routes.rb +13 -0
  52. data/sample/db/development.sqlite3 +0 -0
  53. data/sample/db/production.sqlite3 +0 -0
  54. data/sample/doc/README_FOR_APP +2 -0
  55. data/sample/log/development.log +2573 -0
  56. data/sample/log/production.log +80 -0
  57. data/sample/public/404.html +30 -0
  58. data/sample/public/422.html +30 -0
  59. data/sample/public/500.html +33 -0
  60. data/sample/public/dispatch.cgi +10 -0
  61. data/sample/public/dispatch.fcgi +24 -0
  62. data/sample/public/dispatch.rb +10 -0
  63. data/sample/public/favicon.ico +0 -0
  64. data/sample/public/images/rails.png +0 -0
  65. data/sample/public/javascripts/application.js +2 -0
  66. data/sample/public/javascripts/controls.js +963 -0
  67. data/sample/public/javascripts/dragdrop.js +972 -0
  68. data/sample/public/javascripts/effects.js +1120 -0
  69. data/sample/public/javascripts/prototype.js +4221 -0
  70. data/sample/public/robots.txt +5 -0
  71. data/sample/public/stylesheets/locale.css +81 -0
  72. data/sample/public/stylesheets/scaffold.css +74 -0
  73. data/sample/script/about +4 -0
  74. data/sample/script/console +3 -0
  75. data/sample/script/dbconsole +3 -0
  76. data/sample/script/destroy +3 -0
  77. data/sample/script/generate +3 -0
  78. data/sample/script/performance/benchmarker +3 -0
  79. data/sample/script/performance/profiler +3 -0
  80. data/sample/script/performance/request +3 -0
  81. data/sample/script/plugin +3 -0
  82. data/sample/script/process/inspector +3 -0
  83. data/sample/script/process/reaper +3 -0
  84. data/sample/script/process/spawner +3 -0
  85. data/sample/script/runner +3 -0
  86. data/sample/script/server +3 -0
  87. data/sample/test/performance/browsing_test.rb +9 -0
  88. data/sample/test/test_helper.rb +38 -0
  89. metadata +195 -0
@@ -0,0 +1,7 @@
1
+
2
+ <a href="classes/ActionController/Base.html">ActionController::Base<br/></a>
3
+ <a href="classes/ActionController/Caching.html">ActionController::Caching<br/></a>
4
+ <a href="classes/ActionController/Caching/Fragments.html">ActionController::Caching::Fragments<br/></a>
5
+ <a href="classes/ActionView/Base.html">ActionView::Base<br/></a>
6
+ <a href="classes/I18n.html">I18n<br/></a>
7
+ <a href="classes/Locale.html">Locale<br/></a>
@@ -0,0 +1,8 @@
1
+
2
+ <a href="files/ChangeLog.html">ChangeLog<br/></a>
3
+ <a href="files/README.html">README<br/></a>
4
+ <a href="files/lib/locale_rails_rb.html">lib/locale_rails.rb<br/></a>
5
+ <a href="files/lib/locale_rails/action_controller_rb.html">lib/locale_rails/action_controller.rb<br/></a>
6
+ <a href="files/lib/locale_rails/action_view_rb.html">lib/locale_rails/action_view.rb<br/></a>
7
+ <a href="files/lib/locale_rails/i18n_rb.html">lib/locale_rails/i18n.rb<br/></a>
8
+ <a href="files/lib/locale_rails/version_rb.html">lib/locale_rails/version.rb<br/></a>
@@ -0,0 +1,11 @@
1
+
2
+ <a href="classes/ActionView/Base.html#M000006">_pick_template_with_locale (ActionView::Base)<br/></a>
3
+ <a href="classes/ActionView/Base.html#M000005">_pick_template_with_locale_main (ActionView::Base)<br/></a>
4
+ <a href="classes/ActionController/Base.html#M000004">after_init_locale (ActionController::Base)<br/></a>
5
+ <a href="classes/ActionController/Base.html#M000003">before_init_locale (ActionController::Base)<br/></a>
6
+ <a href="classes/I18n.html#M000010">candidates (I18n)<br/></a>
7
+ <a href="classes/ActionController/Caching/Fragments.html#M000002">expire_fragment_with_locale (ActionController::Caching::Fragments)<br/></a>
8
+ <a href="classes/ActionController/Caching/Fragments.html#M000001">fragment_cache_key_with_locale (ActionController::Caching::Fragments)<br/></a>
9
+ <a href="classes/I18n.html#M000009">locale= (I18n)<br/></a>
10
+ <a href="classes/I18n.html#M000007">supported_locales (I18n)<br/></a>
11
+ <a href="classes/I18n.html#M000008">supported_locales= (I18n)<br/></a>
data/doc/index.html ADDED
@@ -0,0 +1 @@
1
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta content="text/html; charset=utf-8" http-equiv="Content-Type"/><title>Ruby-Locale for Ruby on Rails</title><link type="text/css" href="rdoc-style.css" media="screen" rel="stylesheet"/><meta content="0;url=files/README.html" http-equiv="refresh"/></head><body><div id="container"><div class="curve" id="preheader_curve_0"></div><div class="curve" id="preheader_curve_1"></div><div class="curve" id="preheader_curve_2"></div><div class="curve" id="preheader_curve_3"></div><div class="curve" id="preheader_curve_4"></div><div class="curve" id="preheader_curve_5"></div><div id="header"><span id="title"><p>&nbsp;</p><h1>Ruby Documentation</h1></span></div><div class="clear"></div><div id="redirect"><a href="files/README.html"><h1>Redirect</h1></a></div></div></body></html>
@@ -0,0 +1,320 @@
1
+
2
+ /*;
3
+ Allison 2 template;
4
+ Copyright 2007, 2008 Cloudburst, LLC. Licensed under the AFL 3. See the included LICENSE file.;
5
+ */;
6
+
7
+ /* default styles */
8
+
9
+ * {
10
+ margin: 0;
11
+ padding: 0;
12
+ border: none;
13
+ }
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+ .clear {
25
+ clear: both;
26
+ }
27
+
28
+ a {
29
+ color: #304878;
30
+ font-weight: bold;
31
+ text-decoration: none;
32
+ }
33
+
34
+ a:hover {
35
+ text-decoration: underline;
36
+ }
37
+
38
+ html, body {
39
+ color: #000;
40
+ font-size: 13px;
41
+ font-family: helvetica, verdana, sans;
42
+ background-color: #fff;
43
+ text-align: center;
44
+ margin: 0;
45
+ padding: 0;
46
+ }
47
+
48
+ p, ul, ol {
49
+ line-height: 16px;
50
+ } li {
51
+ margin: 3px;
52
+ _margin-left: 40px;
53
+ } p, pre, table, ol, ul {
54
+ margin: 16px;
55
+ } #item_name {
56
+ margin-top: -8px;
57
+ }
58
+
59
+ h1 {
60
+ font-size: 22px;
61
+ margin-top: 16px;
62
+ } h2, h3 {
63
+ font-size: 18px;
64
+ margin: 6px;
65
+ margin-right: 0;
66
+ padding-top: 12px;
67
+ }
68
+
69
+ /* center everything */
70
+
71
+ #container {
72
+ margin: 20px auto 0 auto;
73
+ width: 900px;
74
+ text-align: left;
75
+ }
76
+
77
+ /* header stuff */
78
+
79
+ #header {
80
+ padding: 6px;
81
+ padding-top: 3px;
82
+ width: 888px;
83
+ height: 52px;
84
+ _height: 58px;
85
+ margin-bottom: 12px;
86
+ vertical-align: baseline;
87
+ background-color: #181848;
88
+ overflow: hidden;
89
+ } .curve {
90
+ background-color: #181848;
91
+ margin: 0;
92
+ padding: 0;
93
+ height: 1px;
94
+ overflow: hidden /* again, ie problem */;
95
+ }
96
+
97
+
98
+
99
+
100
+
101
+ #preheader_curve_5{border-left: 1px solid #fff; border-right: 1px solid #fff; width: 898px; _width: 888px; }
102
+ #preheader_curve_4{border-left: 1px solid #fff; border-right: 1px solid #fff; width: 898px; _width: 888px; }
103
+ #preheader_curve_3{border-left: 2px solid #fff; border-right: 2px solid #fff; width: 896px; _width: 888px; }
104
+ #preheader_curve_2{border-left: 3px solid #fff; border-right: 3px solid #fff; width: 894px; _width: 888px; }
105
+ #preheader_curve_1{border-left: 4px solid #fff; border-right: 4px solid #fff; width: 892px; _width: 888px; }
106
+ #preheader_curve_0{border-left: 6px solid #fff; border-right: 6px solid #fff; width: 888px; _width: 888px; }
107
+
108
+ #header h1 {
109
+ color: #fff;
110
+ font-size: 30px;
111
+ margin: 4px 0 0 0;
112
+ } #header p {
113
+ margin: 0;
114
+ padding: 0;
115
+ padding-left: 3px;
116
+ font-size: 16px;
117
+ color: #fff;
118
+ } #header a {
119
+ color: #fff;
120
+ text-decoration: none;
121
+ font-weight: bold;
122
+ }
123
+
124
+ /* basic layout and navigation bars */
125
+
126
+ #left {
127
+ background-color: #181848;
128
+ width: 220px;
129
+ float: left;
130
+ _width: 208px;
131
+ margin-bottom: 24px;
132
+ } #left a {
133
+ line-height: 14px;
134
+ }
135
+
136
+ /* navigation bar colors and text styles */
137
+
138
+ .navigation {
139
+ width: 196px;
140
+ margin: 6px;
141
+ padding: 6px;
142
+ text-align: left;
143
+ background-color: #fff;
144
+ overflow: hidden;
145
+ } .navigation h3 {
146
+ font-weight: bold;
147
+ margin-bottom: 5px;
148
+ } .navigation span, .navigation a {
149
+ margin-left: 6px;
150
+ } #includes .navigation span, #includes .navigation a {
151
+ margin-left: 0;
152
+ } .darker {
153
+ background-color: #e4ebed;
154
+ } #spacer {
155
+ background-color: #fff;
156
+ height: 18px;
157
+ display: none;
158
+ }
159
+
160
+ /* content area */
161
+
162
+ #content {
163
+ padding: 20px;
164
+ width: 640px;
165
+ float: left;
166
+ min-height: 450px;
167
+ margin: 0;
168
+ margin-bottom: -4px;
169
+ } #content img {
170
+ padding-top: 6px;
171
+ padding-bottom: 12px;
172
+ }
173
+
174
+ #content h1, h2 {
175
+ border-top: 1px solid #e4ebed;
176
+ } #content h1 {
177
+ padding-top: 18px;
178
+ } #content #item_name { /* why does this need to be fully qualified? */
179
+ padding-top: 0;
180
+ border: none;
181
+ }
182
+
183
+ /* footer */
184
+
185
+ #footer {
186
+ text-align: center;
187
+ background-color: #fff;
188
+ padding: 18px;
189
+ border-top: 1px solid #e4ebed;
190
+ color: #ccd5dc;
191
+ } #footer a {
192
+ font-weight: normal;
193
+ color: #ccd5dc;
194
+ }
195
+
196
+ /* for that dumb redirect index page I can't avoid */
197
+
198
+ #redirect {
199
+ text-align: center;
200
+ } #redirect a {
201
+ color: #181848;
202
+ }
203
+
204
+ /* tables */
205
+
206
+ table {
207
+ width: 585px;
208
+ margin-right: 0;
209
+ border-collapse: collapse;
210
+ border: 1px solid #e4ebed;
211
+ } td, th {
212
+ background-color: #fff;
213
+ text-align: left;
214
+ padding: 6px;
215
+ line-height: 14px;
216
+ font-size: 13px;
217
+ } td.normal {
218
+ font-family: Courier, Courier New, monospace;
219
+ font-size: 12px;
220
+ } td.highlight {
221
+ color: #304878;
222
+ }
223
+
224
+ /* method_block details */
225
+
226
+ div.method_block {
227
+ border-bottom: 1px solid #e4ebed;
228
+ margin-left: 20px;
229
+ margin-bottom: -17px;
230
+ margin-top: 17px;
231
+ } div.method_block h3 {
232
+ color: #181848;
233
+ margin-left: 0;
234
+ padding: 0;
235
+ } #content div.method_block h1, #content #description h1 {
236
+ margin-left: 6px;
237
+ color: #ccd5dc;
238
+ } div.method_block a.small { /* where is this used? */
239
+ font-size: 3px;
240
+ line-height: 3px;
241
+ }
242
+
243
+ /* index includes on the navigation bar */
244
+
245
+ div.index a {
246
+ font-size: 13px;
247
+ } #method {
248
+ display: none;
249
+ } #file, #class {
250
+ display: block;
251
+ } div.list_header {
252
+ float: left;
253
+ } div.list_header_link {
254
+ float: right;
255
+ padding-top: 3px;
256
+ } div.list_header_link a {
257
+ font-weight: normal;
258
+ } div.navigation h3, .list_header_link {
259
+ margin: 0;
260
+ margin-top: 6px;
261
+ margin-bottom: 6px;
262
+ padding: 0;
263
+ }
264
+
265
+ .index label {
266
+ font-size: 13px;
267
+ } .index form input {
268
+ width: 136px;
269
+ } .index form {
270
+ margin-bottom: 6px;
271
+ }
272
+
273
+ ol, ul {
274
+ margin-left: 6px;
275
+ }
276
+
277
+ p.source_link a {
278
+ text-align: right;
279
+ font-weight: normal;
280
+ } div.source {
281
+ display: none;
282
+ } pre, tt {
283
+ color: #181848;
284
+ font-weight: normal;
285
+ font-family: Courier, Courier New, monospace;
286
+ font-size: 12px;
287
+ } pre {
288
+ line-height: 14px;
289
+ margin-left: 12px;
290
+ overflow: auto;
291
+ /* next 4 lines because IE sucks */
292
+ _position: relative;
293
+ _width: 587px;
294
+ _overflow-x:scroll;
295
+ _overflow-y:visible;
296
+ } b tt, tt b {
297
+ font-weight: bold;
298
+ } div.source g {
299
+ margin-left: 0;
300
+ } p.source_link {
301
+ text-align: center;
302
+ }
303
+
304
+ /* source code highlighting */
305
+
306
+ .source pre {
307
+ color: black;
308
+ }
309
+ pre .ruby-value, pre .ruby-symbol {
310
+ color: #1104bb;
311
+ } pre .ruby-value.str, pre .ruby-node {
312
+ color: #181848;
313
+ } pre .ruby-ivar, pre .ruby-cvar {
314
+ } pre .ruby-comment {
315
+ color: #009500;
316
+ } pre .ruby-constant {
317
+ color: #cd8802;
318
+ } pre .ruby-keyword {
319
+ color: #8d04aa;
320
+ }
@@ -0,0 +1,18 @@
1
+ require 'locale'
2
+
3
+ Locale.init(:driver => :cgi)
4
+
5
+ ["i18n", "action_controller", "action_view", "version"].each do |lib|
6
+ require File.join(File.dirname(__FILE__), "locale_rails", lib)
7
+ end
8
+
9
+ begin
10
+ Rails::Info.property("Locale version") do
11
+ Locale::VERSION
12
+ end
13
+ Rails::Info.property("Locale for Rails version") do
14
+ Locale::LOCALE_RAILS_VERSION
15
+ end
16
+ rescue Exception
17
+ $stderr.puts "Locale's Rails::Info is not found." if $DEBUG
18
+ end
@@ -0,0 +1,141 @@
1
+ =begin
2
+ locale_rails/lib/action_controller.rb - Ruby/Locale for "Ruby on Rails"
3
+
4
+ Copyright (C) 2008 Masao Mutoh
5
+
6
+ You may redistribute it and/or modify it under the same
7
+ license terms as Ruby.
8
+
9
+ $Id: action_controller.rb 25 2008-11-30 15:44:24Z mutoh $
10
+ =end
11
+
12
+ require 'action_controller'
13
+
14
+ module ActionController #:nodoc:
15
+ class Base
16
+
17
+ prepend_before_filter :init_locale
18
+
19
+ def self.locale_filter_chain # :nodoc:
20
+ if chain = read_inheritable_attribute('locale_filter_chain')
21
+ return chain
22
+ else
23
+ write_inheritable_attribute('locale_filter_chain', FilterChain.new)
24
+ return locale_filter_chain
25
+ end
26
+ end
27
+
28
+ def init_locale # :nodoc:
29
+ cgi = nil
30
+ if defined? request.cgi
31
+ cgi = request.cgi
32
+ end
33
+
34
+ fchain = self.class.locale_filter_chain
35
+ run_before_filters(fchain.select(&:before?), 0, 0)
36
+
37
+ cgi.params["lang"] = [params["lang"]] if params["lang"]
38
+ Locale.set_cgi(cgi)
39
+ if cgi.params["lang"]
40
+ I18n.locale = cgi.params["lang"][0]
41
+ else
42
+ I18n.locale = nil
43
+ end
44
+
45
+ run_after_filters(fchain.select(&:after?), 0)
46
+ end
47
+
48
+ # Append a block which is called before initializing locale on each WWW request.
49
+ #
50
+ # (e.g.)
51
+ # class ApplicationController < ActionController::Base
52
+ # def before_init_i18n
53
+ # if (cookies["lang"].nil? or cookies["lang"].empty?)
54
+ # params["lang"] = "ko_KR"
55
+ # end
56
+ # end
57
+ # before_init_locale :before_init_i18n
58
+ # # ...
59
+ # end
60
+ def self.before_init_locale(*filters, &block)
61
+ locale_filter_chain.append_filter_to_chain(filters, :before, &block)
62
+ end
63
+
64
+ # Append a block which is called after initializing locale on each WWW request.
65
+ #
66
+ # (e.g.)
67
+ # class ApplicationController < ActionController::Base
68
+ # def after_init_i18n
69
+ # L10nClass.new(locale_candidates)
70
+ # end
71
+ # after_init_locale :after_init_i18n
72
+ # # ...
73
+ # end
74
+ def self.after_init_locale(*filters, &block)
75
+ locale_filter_chain.append_filter_to_chain(filters, :after, &block)
76
+ end
77
+ end
78
+
79
+ class TestRequest < AbstractRequest #:nodoc:
80
+ class LocaleMockCGI < CGI #:nodoc:
81
+ attr_accessor :stdinput, :stdoutput, :env_table
82
+
83
+ def initialize(env, input=nil)
84
+ self.env_table = env
85
+ self.stdinput = StringIO.new(input || "")
86
+ self.stdoutput = StringIO.new
87
+
88
+ super()
89
+ end
90
+ end
91
+
92
+ @cgi = nil
93
+ def cgi
94
+ unless @cgi
95
+ @cgi = LocaleMockCGI.new("REQUEST_METHOD" => "GET",
96
+ "QUERY_STRING" => "",
97
+ "REQUEST_URI" => "/",
98
+ "HTTP_HOST" => "www.example.com",
99
+ "SERVER_PORT" => "80",
100
+ "HTTPS" => "off")
101
+ end
102
+ @cgi
103
+ end
104
+ end
105
+
106
+ module Caching
107
+ module Fragments
108
+ def fragment_cache_key_with_locale(name)
109
+ ret = fragment_cache_key_without_locale(name)
110
+ if ret.is_a? String
111
+ ret.gsub(/:/, ".") << "_#{I18n.candidates}"
112
+ else
113
+ ret
114
+ end
115
+ end
116
+ alias_method_chain :fragment_cache_key, :locale
117
+
118
+ def expire_fragment_with_locale(name, options = nil)
119
+ return unless perform_caching
120
+
121
+ fc_store = (respond_to? :cache_store) ? cache_store : fragment_cache_store
122
+ key = name.is_a?(Regexp) ? name : fragment_cache_key_without_locale(name)
123
+ if key.is_a?(Regexp)
124
+ self.class.benchmark "Expired fragments matching: #{key.source}" do
125
+ fc_store.delete_matched(key, options)
126
+ end
127
+ else
128
+ key = key.gsub(/:/, ".")
129
+ self.class.benchmark "Expired fragment: #{key}, lang = #{I18n.supported_locales}" do
130
+ supported_locales.each do |lang|
131
+ fc_store.delete("#{key}_#{lang}", options)
132
+ end
133
+ end
134
+ end
135
+ end
136
+ alias_method_chain :expire_fragment, :locale
137
+ end
138
+ end
139
+ end
140
+
141
+