locale_rails 0.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +10 -4
- data/{README → README.rdoc} +6 -1
- data/Rakefile +8 -7
- data/lib/locale_rails.rb +3 -1
- data/lib/locale_rails/action_controller.rb +4 -130
- data/lib/locale_rails/action_controller/base.rb +85 -0
- data/lib/locale_rails/action_controller/caching.rb +49 -0
- data/lib/locale_rails/action_controller/test_process.rb +44 -0
- data/lib/locale_rails/action_view.rb +10 -12
- data/lib/locale_rails/i18n.rb +20 -1
- data/lib/locale_rails/version.rb +3 -3
- data/replace.rb +21 -0
- data/sample/app/views/samples/index.html.erb +14 -5
- data/sample/app/views/samples/index.pt.html.erb +16 -0
- data/sample/app/views/samples/index_uz_UZ.html.erb +4 -3
- data/sample/config/environment.rb +1 -1
- data/sample/config/locales/en.yml +2 -0
- data/sample/config/locales/ja.yml +2 -0
- data/sample/db/development.sqlite3 +0 -0
- data/sample/db/schema.rb +10 -0
- data/sample/db/test.sqlite3 +0 -0
- data/sample/log/development.log +1492 -2273
- metadata +17 -47
- data/NEWS +0 -7
- data/doc/classes/ActionController/Base.html +0 -442
- data/doc/classes/ActionController/Caching.html +0 -348
- data/doc/classes/ActionController/Caching/Fragments.html +0 -424
- data/doc/classes/ActionView/Base.html +0 -422
- data/doc/classes/I18n.html +0 -492
- data/doc/classes/Locale.html +0 -364
- data/doc/created.rid +0 -1
- data/doc/files/ChangeLog.html +0 -355
- data/doc/files/README.html +0 -409
- data/doc/files/lib/locale_rails/action_controller_rb.html +0 -349
- data/doc/files/lib/locale_rails/action_view_rb.html +0 -349
- data/doc/files/lib/locale_rails/i18n_rb.html +0 -342
- data/doc/files/lib/locale_rails/version_rb.html +0 -342
- data/doc/files/lib/locale_rails_rb.html +0 -349
- data/doc/fr_class_index.html +0 -7
- data/doc/fr_file_index.html +0 -8
- data/doc/fr_method_index.html +0 -11
- data/doc/index.html +0 -1
- data/doc/rdoc-style.css +0 -320
- data/locale_rails-0.1.0.gem +0 -0
- data/sample/app/views/samples/#cookie.rb# +0 -3
- data/sample/db/production.sqlite3 +0 -0
- data/sample/log/production.log +0 -80
data/ChangeLog
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
-
|
1
|
+
= locale_rails-2.0.0 (2009-03-22)
|
2
2
|
|
3
|
-
|
3
|
+
* I18n.translate fallbacks to the localized message in the locale candidates.
|
4
|
+
* Support localized view both of gettext-1.93.0 style and rails-2.3.x style.
|
4
5
|
|
5
|
-
2008-
|
6
|
+
= locale_rails-0.1.0 (2008-12-04)
|
7
|
+
|
8
|
+
* Initial released.
|
9
|
+
* Auto-Detect the locales from the WWW browser
|
10
|
+
* Localized Routes
|
11
|
+
* Action/Fragment caching
|
12
|
+
* Separated Localized View template file
|
6
13
|
|
7
|
-
* Initial import.
|
data/{README → README.rdoc}
RENAMED
@@ -10,6 +10,7 @@ auto-detection and some other features includes this library.
|
|
10
10
|
* Action/Fragment caching
|
11
11
|
* Separated Localized View template file
|
12
12
|
* Localized Routes
|
13
|
+
* I18n.t fallback to localized message candidates.
|
13
14
|
|
14
15
|
== Website
|
15
16
|
* http://www.yotabanana.com/hiki/ruby-locale-rails.html
|
@@ -25,9 +26,13 @@ auto-detection and some other features includes this library.
|
|
25
26
|
($ su)
|
26
27
|
# gem install locale_rails
|
27
28
|
|
29
|
+
== Support matrix
|
30
|
+
* locale_rails-0.1.0 - rails-2.1.x
|
31
|
+
* locale_rails-2.0.0 - rails-2.3.2
|
32
|
+
|
28
33
|
== License
|
29
34
|
This program is licenced under the same licence as Ruby.
|
30
35
|
(See the file 'COPYING'.)
|
31
36
|
|
32
37
|
== Maintainer
|
33
|
-
Masao Mutoh <
|
38
|
+
Masao Mutoh <mutomasa at gmail.com>
|
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ require 'locale_rails/version'
|
|
12
12
|
#task :default => [ :test ]
|
13
13
|
|
14
14
|
PKG_NAME = "locale_rails"
|
15
|
-
PKG_VERSION =
|
15
|
+
PKG_VERSION = LocaleRails::VERSION
|
16
16
|
|
17
17
|
# Run the unit tests
|
18
18
|
task :test do
|
@@ -35,19 +35,19 @@ Rake::RDocTask.new { |rdoc|
|
|
35
35
|
rdoc.template = allison if allison.size > 0
|
36
36
|
}
|
37
37
|
|
38
|
-
desc "Create gem"
|
38
|
+
desc "Create gem and tar.gz"
|
39
39
|
spec = Gem::Specification.new do |s|
|
40
40
|
s.name = PKG_NAME
|
41
41
|
s.version = PKG_VERSION
|
42
42
|
s.summary = 'Ruby-Locale for Ruby on Rails is the pure ruby library which provides basic functions for localization based on Ruby-Locale.'
|
43
43
|
s.author = 'Masao Mutoh'
|
44
|
-
s.email = '
|
44
|
+
s.email = 'mutomasa at gmail.com'
|
45
45
|
s.homepage = 'http://locale.rubyforge.org/'
|
46
46
|
s.rubyforge_project = "locale"
|
47
|
-
s.files = FileList['**/*'].to_a.select{|v| v !~ /pkg|CVS/}
|
47
|
+
s.files = FileList['**/*'].to_a.select{|v| v !~ /pkg|CVS|git/}
|
48
48
|
s.require_path = 'lib'
|
49
49
|
s.bindir = 'bin'
|
50
|
-
s.add_dependency('locale', '>= 0.
|
50
|
+
s.add_dependency('locale', '>= 2.0.0')
|
51
51
|
s.has_rdoc = true
|
52
52
|
s.description = <<-EOF
|
53
53
|
Ruby-Locale for Ruby on Rails is the pure ruby library which provides basic functions for localization.
|
@@ -65,8 +65,9 @@ task :release => [ :package ] do
|
|
65
65
|
require 'rubyforge'
|
66
66
|
|
67
67
|
rubyforge = RubyForge.new
|
68
|
+
rubyforge.configure
|
68
69
|
rubyforge.login
|
69
|
-
rubyforge.add_release("locale", "
|
70
|
-
|
70
|
+
rubyforge.add_release("locale", "locale_rails",
|
71
|
+
PKG_VERSION,
|
71
72
|
"pkg/#{PKG_NAME}-#{PKG_VERSION}.gem")
|
72
73
|
end
|
data/lib/locale_rails.rb
CHANGED
@@ -2,7 +2,9 @@ require 'locale'
|
|
2
2
|
|
3
3
|
Locale.init(:driver => :cgi)
|
4
4
|
|
5
|
-
|
5
|
+
# localized view support was canceled.
|
6
|
+
#["i18n", "action_controller", "action_view", "version"].each do |lib|
|
7
|
+
["i18n", "action_controller", "version"].each do |lib|
|
6
8
|
require File.join(File.dirname(__FILE__), "locale_rails", lib)
|
7
9
|
end
|
8
10
|
|
@@ -1,141 +1,15 @@
|
|
1
1
|
=begin
|
2
|
-
locale_rails/
|
2
|
+
lib/locale_rails/action_controller.rb - Ruby/Locale for "Ruby on Rails"
|
3
3
|
|
4
|
-
Copyright (C) 2008 Masao Mutoh
|
4
|
+
Copyright (C) 2008-2009 Masao Mutoh
|
5
5
|
|
6
6
|
You may redistribute it and/or modify it under the same
|
7
7
|
license terms as Ruby.
|
8
8
|
|
9
|
-
$Id: action_controller.rb 25 2008-11-30 15:44:24Z mutoh $
|
10
9
|
=end
|
11
10
|
|
12
11
|
require 'action_controller'
|
13
|
-
|
14
|
-
|
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
|
12
|
+
["base", "caching", "test_process"].each do |lib|
|
13
|
+
require File.join(File.dirname(__FILE__), "action_controller", lib)
|
139
14
|
end
|
140
15
|
|
141
|
-
|
@@ -0,0 +1,85 @@
|
|
1
|
+
=begin
|
2
|
+
lib/locale_rails/action_controller/base.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? ::Rack
|
31
|
+
cgi = request
|
32
|
+
else
|
33
|
+
if defined? request.cgi
|
34
|
+
cgi = request.cgi
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
fchain = self.class.locale_filter_chain
|
39
|
+
run_before_filters(fchain.select(&:before?), 0, 0)
|
40
|
+
|
41
|
+
cgi.params["lang"] = [params["lang"]] if params["lang"]
|
42
|
+
Locale.set_cgi(cgi)
|
43
|
+
if cgi.params["lang"]
|
44
|
+
I18n.locale = cgi.params["lang"][0]
|
45
|
+
else
|
46
|
+
I18n.locale = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
run_after_filters(fchain.select(&:after?), 0)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Append a block which is called before initializing locale on each WWW request.
|
53
|
+
#
|
54
|
+
# (e.g.)
|
55
|
+
# class ApplicationController < ActionController::Base
|
56
|
+
# def before_init_i18n
|
57
|
+
# if (cookies["lang"].nil? or cookies["lang"].empty?)
|
58
|
+
# params["lang"] = "ko_KR"
|
59
|
+
# end
|
60
|
+
# end
|
61
|
+
# before_init_locale :before_init_i18n
|
62
|
+
# # ...
|
63
|
+
# end
|
64
|
+
def self.before_init_locale(*filters, &block)
|
65
|
+
locale_filter_chain.append_filter_to_chain(filters, :before, &block)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Append a block which is called after initializing locale on each WWW request.
|
69
|
+
#
|
70
|
+
# (e.g.)
|
71
|
+
# class ApplicationController < ActionController::Base
|
72
|
+
# def after_init_i18n
|
73
|
+
# L10nClass.new(locale_candidates)
|
74
|
+
# end
|
75
|
+
# after_init_locale :after_init_i18n
|
76
|
+
# # ...
|
77
|
+
# end
|
78
|
+
def self.after_init_locale(*filters, &block)
|
79
|
+
locale_filter_chain.append_filter_to_chain(filters, :after, &block)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
=begin
|
2
|
+
lib/locale_rails/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/caching'
|
13
|
+
|
14
|
+
module ActionController #:nodoc:
|
15
|
+
|
16
|
+
module Caching
|
17
|
+
module Fragments
|
18
|
+
def fragment_cache_key_with_locale(name)
|
19
|
+
ret = fragment_cache_key_without_locale(name)
|
20
|
+
if ret.is_a? String
|
21
|
+
ret.gsub(/:/, ".") << "_#{I18n.candidates}"
|
22
|
+
else
|
23
|
+
ret
|
24
|
+
end
|
25
|
+
end
|
26
|
+
alias_method_chain :fragment_cache_key, :locale
|
27
|
+
|
28
|
+
def expire_fragment_with_locale(name, options = nil)
|
29
|
+
return unless perform_caching
|
30
|
+
|
31
|
+
fc_store = (respond_to? :cache_store) ? cache_store : fragment_cache_store
|
32
|
+
key = name.is_a?(Regexp) ? name : fragment_cache_key_without_locale(name)
|
33
|
+
if key.is_a?(Regexp)
|
34
|
+
self.class.benchmark "Expired fragments matching: #{key.source}" do
|
35
|
+
fc_store.delete_matched(key, options)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
key = key.gsub(/:/, ".")
|
39
|
+
self.class.benchmark "Expired fragment: #{key}, lang = #{I18n.supported_locales}" do
|
40
|
+
supported_locales.each do |lang|
|
41
|
+
fc_store.delete("#{key}_#{lang}", options)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
alias_method_chain :expire_fragment, :locale
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
=begin
|
2
|
+
lib/locale_rails/action_controller.rb - Ruby/Locale for "Ruby on Rails"
|
3
|
+
|
4
|
+
Copyright (C) 2009 Masao Mutoh
|
5
|
+
|
6
|
+
You may redistribute it and/or modify it under the same
|
7
|
+
license terms as Ruby.
|
8
|
+
|
9
|
+
=end
|
10
|
+
|
11
|
+
require 'action_controller'
|
12
|
+
require 'action_controller/test_process'
|
13
|
+
|
14
|
+
module ActionController
|
15
|
+
if defined? AbstractRequest #:nodoc:
|
16
|
+
# for Rails-2.2.x or earlier.
|
17
|
+
class TestRequest < AbstractRequest #:nodoc:
|
18
|
+
class LocaleMockCGI < CGI #:nodoc:
|
19
|
+
attr_accessor :stdinput, :stdoutput, :env_table
|
20
|
+
|
21
|
+
def initialize(env, input=nil)
|
22
|
+
self.env_table = env
|
23
|
+
self.stdinput = StringIO.new(input || "")
|
24
|
+
self.stdoutput = StringIO.new
|
25
|
+
|
26
|
+
super()
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
@cgi = nil
|
31
|
+
def cgi
|
32
|
+
unless @cgi
|
33
|
+
@cgi = LocaleMockCGI.new("REQUEST_METHOD" => "GET",
|
34
|
+
"QUERY_STRING" => "",
|
35
|
+
"REQUEST_URI" => "/",
|
36
|
+
"HTTP_HOST" => "www.example.com",
|
37
|
+
"SERVER_PORT" => "80",
|
38
|
+
"HTTPS" => "off")
|
39
|
+
end
|
40
|
+
@cgi
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -8,36 +8,34 @@
|
|
8
8
|
|
9
9
|
Original: Ruby-GetText-Package-1.92.0
|
10
10
|
|
11
|
-
$Id: action_view.rb 23 2008-11-24 09:22:35Z mutoh $
|
12
11
|
=end
|
13
12
|
|
14
13
|
require 'action_view'
|
15
14
|
|
16
15
|
module ActionView #:nodoc:
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
class PathSet < Array
|
17
|
+
|
18
|
+
def find_template_with_locale_rails(original_template_path, format = nil, html_fallback = true)
|
19
|
+
return original_template_path if original_template_path.respond_to?(:render)
|
20
|
+
|
21
|
+
path = original_template_path.sub(/^\//, '')
|
20
22
|
if m = path.match(/(.*)\.(\w+)$/)
|
21
23
|
template_file_name, template_file_extension = m[1], m[2]
|
22
24
|
else
|
23
25
|
template_file_name = path
|
24
26
|
end
|
25
27
|
|
26
|
-
|
28
|
+
I18n.candidates.each do |v|
|
27
29
|
file_name = "#{template_file_name}_#{v}"
|
28
30
|
begin
|
29
|
-
return
|
31
|
+
return find_template_without_locale_rails(file_name, format, false)
|
30
32
|
rescue MissingTemplate => e
|
31
33
|
end
|
32
34
|
end
|
33
|
-
|
35
|
+
find_template_without_locale_rails(original_template_path, format, html_fallback)
|
34
36
|
end
|
35
|
-
|
37
|
+
alias_method_chain :find_template, :locale_rails
|
36
38
|
|
37
|
-
def _pick_template_with_locale(template_path) #: shouldn't memoize.
|
38
|
-
_pick_template_with_locale_main(template_path, I18n.candidates)
|
39
|
-
end
|
40
|
-
alias_method_chain :_pick_template, :locale
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|