locale_rails 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ = locale_rails-2.0.2 (2009-05-04)
2
+ * Remove I18n.candidates. Use Locale.candidates directly.
3
+ * Improve documentations.
4
+ * Override I18n.default_locale= to call Locale.default.
5
+
1
6
  = locale_rails-2.0.1 (2009-04-17)
2
7
  * Fixed to work localized view which was canceled.
3
8
 
data/README.rdoc CHANGED
@@ -26,10 +26,26 @@ auto-detection and some other features includes this library.
26
26
  ($ su)
27
27
  # gem install locale_rails
28
28
 
29
+ == Usage
30
+ ==== config/environment.rb
31
+ Rails::Initializer.run do |config|
32
+ :
33
+ :
34
+ config.gem 'locale'
35
+ config.gem 'locale_rails'
36
+ end
37
+
38
+ ==== config/initializer/locale.rb
39
+
40
+ # Tell the I18n library where to find your translations
41
+ I18n.supported_locales = ["ja", "en"]
42
+ I18n.default_locale = "ja"
43
+
29
44
  == Support matrix
30
- * locale_rails-0.1.0 - rails-2.1.x
31
- * locale_rails-2.0.0 - rails-2.3.2
45
+ * locale_rails-2.0.2 - rails-2.3.2
32
46
  * locale_rails-2.0.1 - rails-2.3.2
47
+ * locale_rails-2.0.0 - rails-2.3.2
48
+ * locale_rails-0.1.0 - rails-2.1.x
33
49
 
34
50
  == License
35
51
  This program is licenced under the same licence as Ruby.
data/Rakefile CHANGED
@@ -47,7 +47,7 @@ spec = Gem::Specification.new do |s|
47
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', '>= 2.0.1')
50
+ s.add_dependency('locale', '>= 2.0.2')
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.
@@ -70,7 +70,7 @@ module ActionController #:nodoc:
70
70
  # (e.g.)
71
71
  # class ApplicationController < ActionController::Base
72
72
  # def after_init_i18n
73
- # L10nClass.new(locale_candidates)
73
+ # L10nClass.new(Locale.candidates)
74
74
  # end
75
75
  # after_init_locale :after_init_i18n
76
76
  # # ...
@@ -25,7 +25,7 @@ module ActionView #:nodoc:
25
25
  template_file_name = path
26
26
  end
27
27
 
28
- I18n.candidates.each do |v|
28
+ Locale.candidates.each do |v|
29
29
  file_name = "#{template_file_name}_#{v}"
30
30
  begin
31
31
  return find_template_without_locale_rails(file_name, format, false)
@@ -10,18 +10,23 @@
10
10
  =end
11
11
 
12
12
  module I18n
13
- @@supported_locales = nil
14
13
  module_function
15
14
 
16
15
  # Gets the supported locales.
17
16
  def supported_locales
18
- @@supported_locales
17
+ Locale.app_language_tags
18
+ end
19
+
20
+ # Sets the supported locales.
21
+ # I18n.set_supported_locales("ja-JP", "ko-KR", ...)
22
+ def set_supported_locales(*tags)
23
+ Locale.set_app_language_tags(*tags)
19
24
  end
20
25
 
21
26
  # Sets the supported locales as an Array.
22
- # I18n.supported_locales = ["ja-JP", "ko-KR"]
27
+ # I18n.supported_locales = ["ja-JP", "ko-KR", ...]
23
28
  def supported_locales=(tags)
24
- @@supported_locales = tags
29
+ Locale.set_app_language_tags(*tags)
25
30
  end
26
31
 
27
32
  # Sets the locale.
@@ -30,35 +35,23 @@ module I18n
30
35
  Locale.clear
31
36
  tag = Locale::Tag::Rfc.parse(tag.to_s) if tag.kind_of? Symbol
32
37
  Locale.current = tag
33
- Thread.current[:locale] = candidates(:rfc)[0]
34
- end
35
-
36
- # Get the locale candidates as a Locale::TagList.
37
- # This is the utility function which calls Locale.candidates with
38
- # supported_language_tags.
39
- #
40
- # I18n.locale is also overrided by Ruby-Locale and it returns
41
- # the result of this method with :rfc option.
42
- #
43
- # +type+ :simple, :common(default), :rfc, :cldr.
44
- #
45
- # This is used by Rails application, but it may be better not to
46
- # use this method in Rails plugins/libraries, because they have their
47
- # own supported languages.
48
- def candidates(type = :common)
49
- default = [I18n.default_locale.to_s]
50
- default = ["en-US", "en"] if default[0] == "en-US"
51
- Locale.candidates(:type => type,
52
- :supported_language_tags => supported_locales,
53
- :default_language_tags => default)
38
+ Thread.current[:locale] = Locale.candidates(:type => :rfc)[0]
54
39
  end
55
40
 
41
+ # Sets the default locale.
42
+ # I18n.default_locale = "ja"
43
+ def default_locale=(tag)
44
+ tag = Locale::Tag::Rfc.parse(tag.to_s) if tag.kind_of? Symbol
45
+ Locale.default = tag
46
+ @@default_locale = tag
47
+ end
48
+
56
49
  class << self
57
50
 
58
51
  # MissingTranslationData is overrided to fallback messages in candidate locales.
59
52
  def locale_rails_exception_handler(exception, locale, key, options) #:nodoc:
60
53
  ret = nil
61
- candidates(:rfc).each do |loc|
54
+ Locale.candidates(:type => :rfc).each do |loc|
62
55
  begin
63
56
  ret = backend.translate(loc, key, options)
64
57
  break
@@ -1,4 +1,4 @@
1
1
  module LocaleRails
2
2
  RAILS_VERSION = "2.3.2"
3
- VERSION = "2.0.1"
3
+ VERSION = "2.0.2"
4
4
  end
@@ -16,6 +16,7 @@ class ApplicationController < ActionController::Base
16
16
  # Set the charset of Content-Type.
17
17
  # This is not Ruby-Locale method but useful.
18
18
  # self.default_charset = "iso8859-1"
19
+ #I18n.supported_locales = ["en", "ja", "fr"]
19
20
 
20
21
  =begin
21
22
  def before_init_i18n
@@ -3,14 +3,14 @@
3
3
  %>
4
4
 
5
5
  <h2>Get the current locale</h2>
6
- <h3>I18n.candidates(with no option)</h3>
6
+ <h3>Locale.candidates(with no option)</h3>
7
7
  <p>Requested Locales order by the priority. This method is added by Ruby-Locale for Ruby on Rails.</p>
8
8
  <div class="result">
9
- <%=h I18n.candidates.inspect %>
9
+ <%=h Locale.candidates.inspect %>
10
10
  </div>
11
11
 
12
12
  <h3>I18n.locale (with inspect)</h3>
13
- <p>I18n.locale is set the result(Locale::TagList) of locale_candidates(:type => :rfc).<br/>
13
+ <p>I18n.locale is set the result(Locale::TagList) of Locale.candidates(:type => :rfc).<br/>
14
14
  This method is extended by Ruby-Locale for Ruby on Rails and returns all candidates as the Locale::TagList.
15
15
  </p>
16
16
  <div class="result">
@@ -13,7 +13,7 @@
13
13
  </table>
14
14
  <p>
15
15
  (*1) Fallback to "en" if the localized message is not found in the locale.
16
- Currently, <%= Dir.glob(File.join(RAILS_ROOT, "config/locales/*.yml")).collect {|v| File.basename(v, ".yml")}.inspect %> are supported.
16
+ Currently, <%= Dir.glob(File.join(RAILS_ROOT, "config/locales/*.yml")).collect {|v| File.basename(v, ".yml")}.inspect %> are available.
17
17
  </p>
18
18
 
19
19
  <%= render :partial => 'part' %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locale_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masao Mutoh
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-18 00:00:00 +09:00
12
+ date: 2009-05-09 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 2.0.1
23
+ version: 2.0.2
24
24
  version:
25
25
  description: Ruby-Locale for Ruby on Rails is the pure ruby library which provides basic functions for localization.
26
26
  email: mutomasa at gmail.com