i18n-message 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ i18n-message (0.0.1)
5
+ activesupport
6
+ i18n
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ activesupport (3.0.1)
12
+ i18n (0.4.2)
13
+ test_declarative (0.0.4)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ activesupport
20
+ i18n
21
+ i18n-message!
22
+ test_declarative
@@ -0,0 +1,11 @@
1
+ $: << File.expand_path('../lib', __FILE__)
2
+ require 'rake/testtask'
3
+ require 'i18n/message'
4
+
5
+ task :default => [:test]
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.pattern = "#{File.dirname(__FILE__)}/test/all.rb"
9
+ t.verbose = true
10
+ end
11
+ Rake::Task['test'].comment = "Run all tests"
@@ -19,8 +19,7 @@ class I18n::Message
19
19
  end
20
20
 
21
21
  def scope
22
- scopes = self.class.cascade_options[:scopes]
23
- scopes = [super] + scopes.map do |scope|
22
+ scopes = [super] + Array(self.class.cascade_options[:scopes]).map do |scope|
24
23
  if options[scope]
25
24
  value = options[scope]
26
25
  value = value.class.name unless value.is_a?(String) || value.is_a?(Symbol)
@@ -30,4 +29,4 @@ class I18n::Message
30
29
  scopes.compact.join('.')
31
30
  end
32
31
  end
33
- end
32
+ end
@@ -1,3 +1,5 @@
1
- class I18n::Message
2
- VERSION = "0.0.1"
3
- end
1
+ module I18n
2
+ class Message
3
+ VERSION = '0.0.2'
4
+ end
5
+ end
metadata CHANGED
@@ -1,35 +1,74 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-message
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
5
11
  platform: ruby
6
12
  authors:
7
13
  - Sven Fuchs
8
- - Mateo Murphy
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2010-02-25 00:00:00 +01:00
18
+ date: 2010-10-31 01:00:00 +02:00
14
19
  default_executable:
15
- dependencies: []
16
-
17
- description: |-
18
- I18n::Message is an object-oriented abstraction for looking up translations
19
- from I18n.translate. This is useful for storing lookup information in contexts
20
- such as ActiveModel validation error I18n.
21
- email:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: i18n
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: activesupport
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: test_declarative
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
63
+ description: I18n::Message is an object-oriented abstraction for looking up translations from I18n.translate. This is useful for storing lookup information in contexts such as ActiveModel validation error I18n.
64
+ email: svenfuchs@artweb-design.de
22
65
  executables: []
23
66
 
24
67
  extensions: []
25
68
 
26
- extra_rdoc_files:
27
- - README.textile
69
+ extra_rdoc_files: []
70
+
28
71
  files:
29
- - MIT-LICENSE
30
- - README.textile
31
- - RakeFile
32
- - lib/i18n/message.rb
33
72
  - lib/i18n/message/base.rb
34
73
  - lib/i18n/message/cascade.rb
35
74
  - lib/i18n/message/format.rb
@@ -37,66 +76,45 @@ files:
37
76
  - lib/i18n/message/gettext.rb
38
77
  - lib/i18n/message/variants.rb
39
78
  - lib/i18n/message/version.rb
40
- - test/all.rb
41
- - test/api.rb
42
- - test/api/base.rb
43
- - test/api/cascade.rb
44
- - test/api/formatted.rb
45
- - test/api/gettext.rb
46
- - test/api/other.rb
47
- - test/api/variants.rb
48
- - test/message/all.rb
49
- - test/message/all_features_test.rb
50
- - test/message/base_test.rb
51
- - test/message/cascade_test.rb
52
- - test/message/formatted_test.rb
53
- - test/message/gettext_test.rb
54
- - test/message/variants_test.rb
55
- - test/test_case_declarative.rb
56
- - test/test_helper.rb
79
+ - lib/i18n/message.rb
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - MIT-LICENSE
83
+ - Rakefile
84
+ - README.textile
57
85
  has_rdoc: true
58
- homepage: http://github.com/svenfuchs/i18n_message
86
+ homepage: http://github.com/svenfuchs/i18n-message
59
87
  licenses: []
60
88
 
61
89
  post_install_message:
62
- rdoc_options:
63
- - --charset=UTF-8
90
+ rdoc_options: []
91
+
64
92
  require_paths:
65
93
  - lib
66
94
  required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
67
96
  requirements:
68
97
  - - ">="
69
98
  - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
70
102
  version: "0"
71
- version:
72
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
73
105
  requirements:
74
106
  - - ">="
75
107
  - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
76
111
  version: "0"
77
- version:
78
112
  requirements: []
79
113
 
80
- rubyforge_project:
81
- rubygems_version: 1.3.5
114
+ rubyforge_project: "[none]"
115
+ rubygems_version: 1.3.7
82
116
  signing_key:
83
117
  specification_version: 3
84
- summary: Object-oriented abstraction for looking up translations from I18n.translate
85
- test_files:
86
- - test/all.rb
87
- - test/api/base.rb
88
- - test/api/cascade.rb
89
- - test/api/formatted.rb
90
- - test/api/gettext.rb
91
- - test/api/other.rb
92
- - test/api/variants.rb
93
- - test/api.rb
94
- - test/message/all.rb
95
- - test/message/all_features_test.rb
96
- - test/message/base_test.rb
97
- - test/message/cascade_test.rb
98
- - test/message/formatted_test.rb
99
- - test/message/gettext_test.rb
100
- - test/message/variants_test.rb
101
- - test/test_case_declarative.rb
102
- - test/test_helper.rb
118
+ summary: I18n::Message is an object-oriented abstraction for looking up translations from I18n.translate
119
+ test_files: []
120
+
data/RakeFile DELETED
@@ -1,28 +0,0 @@
1
- $: << File.expand_path('../lib', __FILE__)
2
- require 'rake/testtask'
3
- require 'i18n/message'
4
-
5
- task :default => [:test]
6
-
7
- Rake::TestTask.new(:test) do |t|
8
- t.pattern = "#{File.dirname(__FILE__)}/test/all.rb"
9
- t.verbose = true
10
- end
11
- Rake::Task['test'].comment = "Run all tests"
12
-
13
- begin
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |s|
16
- s.name = "i18n-message"
17
- s.version = I18n::Message::VERSION
18
- s.summary = "Object-oriented abstraction for looking up translations from I18n.translate"
19
- s.description = %(I18n::Message is an object-oriented abstraction for looking up translations
20
- from I18n.translate. This is useful for storing lookup information in contexts
21
- such as ActiveModel validation error I18n.)
22
- s.homepage = "http://github.com/svenfuchs/i18n_message"
23
- s.authors = ["Sven Fuchs", "Mateo Murphy"]
24
- s.files = FileList["[A-Z]*", "{lib,test}/**/*"]
25
- end
26
- rescue LoadError
27
- puts "Jeweler not available. Install it with: gem install jeweler"
28
- end
@@ -1,8 +0,0 @@
1
- # encoding: utf-8
2
-
3
- dir = File.dirname(__FILE__)
4
- $LOAD_PATH.unshift(dir)
5
-
6
- Dir["#{dir}/**/*_test.rb"].sort.each do |file|
7
- require file.sub(/^#{dir}\/(.*)\.rb$/, '\1')
8
- end
@@ -1,7 +0,0 @@
1
- module Api
2
- autoload :Base, 'api/base'
3
- autoload :Cascade, 'api/cascade'
4
- autoload :Formatted, 'api/formatted'
5
- autoload :Gettext, 'api/gettext'
6
- autoload :Variants, 'api/variants'
7
- end
@@ -1,51 +0,0 @@
1
- module Api
2
- module Base
3
- # NOT TRANSLATED
4
-
5
- # e.g. validates_presence_of :email, :message => "message"
6
- test "subject is a Message, no format key given" do
7
- assert_equal 'message', message('message').to_s
8
- end
9
-
10
- test "subject evaluates to a Message, no format key given" do
11
- assert_equal 'message', message(Proc.new {'message'}).to_s
12
- end
13
-
14
- # interpolation
15
- test "subject is a Message, interpolates a variable" do
16
- assert_equal 'FOO', message('%{foo}', :foo => 'FOO').to_s
17
- end
18
-
19
- test "subject evaluates to a Message, interpolates a variable" do
20
- assert_equal 'FOO', message(Proc.new {'%{foo}'}, :foo => 'FOO').to_s
21
- end
22
-
23
- test "subject is a Message, bogus interpolation variable, does not raise" do
24
- assert_nothing_raised { message('foo', :foo => 'FOO').to_s }
25
- end
26
-
27
- test "subject evaluates to a Message, bogus interpolation variable, does not raise" do
28
- assert_nothing_raised { message(Proc.new {'foo'}, :foo => 'FOO').to_s }
29
- end
30
-
31
- # TRANSLATED
32
-
33
- # e.g. validates_presence_of :email / translations :blank => 'No email?'
34
- test "subject is a Symbol, no format key given, translation is a Message" do
35
- store_translations(:blank => 'No email?')
36
- assert_equal 'No email?', message(:blank).to_s
37
- end
38
-
39
- # INTERPOLATION
40
- test "subject is a Symbol, translation is a Message, interpolates a variable" do
41
- store_translations(:foo => '{{foo}}')
42
- assert_equal 'FOO', message(:foo, :foo => 'FOO').to_s
43
- end
44
-
45
- test "subject evaluates to a Symbol, translation is a Message, interpolates a variable" do
46
- store_translations(:foo => '{{foo}}')
47
- assert_equal 'FOO', message(Proc.new { :foo }, :foo => 'FOO').to_s
48
- end
49
-
50
- end
51
- end
@@ -1,18 +0,0 @@
1
- module Api
2
- module Cascade
3
- test "returns translation from attribute scope" do
4
- store_translations(:'models.model.attributes.attribute.message' => 'message')
5
- assert_equal 'message', message(:message, :model => 'model', :attribute => 'attribute').to_s
6
- end
7
-
8
- test "returns translation from model scope" do
9
- store_translations(:'models.model.message' => 'message')
10
- assert_equal 'message', message(:message, :model => 'model', :attribute => 'attribute').to_s
11
- end
12
-
13
- test "returns translation from errors scope" do
14
- store_translations(:message => 'message')
15
- assert_equal 'message', message(:message, :model => 'model', :attribute => 'attribute').to_s
16
- end
17
- end
18
- end
@@ -1,21 +0,0 @@
1
- module Api
2
- module Formatted
3
- test "subject Message given, format Message given" do
4
- assert_equal 'formatted message', message('message', :format => 'formatted %{message}').to_s
5
- end
6
-
7
- test "subject Message given, format Hash given" do
8
- assert_equal 'formatted message', message('message', :format => { :full => 'formatted %{message}' }).to_s(:full)
9
- end
10
-
11
- test "uses a format to wrap a translated message" do
12
- store_translations(:blank => 'blank')
13
- assert_equal "formatted blank", message(:blank, :format => 'formatted %{message}').to_s
14
- end
15
-
16
- test "uses a translated format to wrap a message" do
17
- store_translations(:blank => 'blank', :'formats.full' => 'full %{message}')
18
- assert_equal "full blank", message(:blank).to_s(:full)
19
- end
20
- end
21
- end
@@ -1,8 +0,0 @@
1
- module Api
2
- module Gettext
3
- test "subject is a Message, will be translated" do
4
- store_translations('Message' => 'The Message.new')
5
- assert_equal 'The Message.new', message('Message').to_s
6
- end
7
- end
8
- end
@@ -1,51 +0,0 @@
1
- module Api
2
-
3
- module TranslatedVariants
4
- # # validates_presence_of :email / translations :blank => { :short => 'No email?' }
5
- # test "subject is a Symbol, format key :short given, translation is a Hash w/ :short key" do
6
- # store_translations(:blank => { :short => 'No email?' })
7
- # assert_equal 'No email?', message(:blank).to_s(:short)
8
- # end
9
- #
10
- # not implemented
11
- # test "subject is a Symbol, format key :full given, translation is a Hash w/ :short key" do
12
- # store_translations(:blank => { :short => 'No email?' })
13
- # assert_equal 'No email?', message(:blank).to_s(:full)
14
- # end
15
-
16
- # # validates_presence_of :email / translations :blank => { :short => 'No email?', :full => "full" }
17
- # test "subject is a Symbol, format key :short given, translation is a Hash w/ :short and :full keys" do
18
- # store_translations(:blank => { :short => 'No email?', :full => "full" })
19
- # assert_equal 'No email?', message(:blank).to_s(:short)
20
- # end
21
- #
22
- # test "subject is a Symbol, format key :full given, translation is a Hash w/ :short and :full keys" do
23
- # store_translations(:blank => { :short => 'No email?', :full => "full" })
24
- # assert_equal "full", message(:blank).to_s(:full)
25
- # end
26
- #
27
- # # e.g. validates_presence_of :email, :message => { :short => :foo } / translations :blank => { :short => 'No email?' }
28
- # test "subject is a Hash, format key :short given, translation is a Hash w/ :short key" do
29
- # store_translations(:foo => { :short => 'No email?' })
30
- # assert_equal 'No email?', message(:blank, :short => :foo).to_s(:short)
31
- # end
32
- #
33
- # # not implemented
34
- # # test "subject is a Hash, format key :full given, translation is a Hash w/ :short key" do
35
- # # store_translations(:foo => { :short => 'No email?' })
36
- # # assert_equal 'No email?', message(:blank, :short => :foo).to_s(:full)
37
- # # end
38
- #
39
- # # e.g. validates_presence_of :email, :message => { :short => :foo, :full => :foo } / translations :blank => { :short => 'No email?' }
40
- # test "subject is a Hash, format key :short given, translation is a Hash w/ :short and :full key" do
41
- # store_translations(:foo => { :short => 'No email?' })
42
- # assert_equal 'No email?', message(:blank, :short => :foo, :full => :foo).to_s(:short)
43
- # end
44
- #
45
- # # not implemented
46
- # # test "subject is a Hash, format key :full given, translation is a Hash w/ :short and :full key" do
47
- # # store_translations(:foo => { :short => 'No email?' })
48
- # # assert_equal 'No email?', message(:blank, :short => :foo, :full => :foo).to_s(:full)
49
- # # end
50
- end
51
- end
@@ -1,21 +0,0 @@
1
- module Api
2
- module Variants
3
- # e.g. validates_presence_of :email, :message => "message"
4
- test "subject is a Message, variant :short" do
5
- assert_equal 'message', message('message').to_s(:short)
6
- end
7
-
8
- test "subject is a Message, variant :full" do
9
- assert_equal 'message', message('message').to_s(:full)
10
- end
11
-
12
- # e.g. validates_presence_of :email, :message => { :short => "short", :full => "full" } }
13
- test "subject is a Hash w/ :short and :full messages, variant :short" do
14
- assert_equal 'short', message(:short => 'short', :full => "full").to_s(:short)
15
- end
16
-
17
- test "subject is a Hash w/ :short and :full messages, variant :full" do
18
- assert_equal "full", message(:short => 'short', :full => "full").to_s(:full)
19
- end
20
- end
21
- end
@@ -1,8 +0,0 @@
1
- # encoding: utf-8
2
-
3
- dir = File.dirname(__FILE__)
4
- $LOAD_PATH.unshift(dir)
5
-
6
- Dir["#{dir}/**/*_test.rb"].sort.each do |file|
7
- require file.sub(/^#{dir}\/(.*)\.rb$/, '\1')
8
- end
@@ -1,26 +0,0 @@
1
- # encoding: utf-8
2
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
3
-
4
- class I18nMessageAllFeaturesTest < Test::Unit::TestCase
5
- class Format < I18n::Message::Format
6
- include I18n::Message::Variants
7
- end
8
-
9
- class Message < I18n::Message
10
- include Cascade
11
- include Variants
12
- include Formatted
13
-
14
- self.format_class = Format
15
- end
16
-
17
- def setup
18
- I18n.backend = CascadingBackend.new
19
- Message.cascade_options = { :step => 2, :skip_root => false, :scopes => [:model, :attribute] }
20
- end
21
-
22
- include Api::Base
23
- include Api::Cascade
24
- include Api::Variants
25
- include Api::Formatted
26
- end
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
- require File.expand_path('../../test_helper', __FILE__)
3
-
4
- class I18nMessageBaseTest < Test::Unit::TestCase
5
- class Message < I18n::Message
6
- end
7
-
8
- def setup
9
- I18n.backend = I18n::Backend::Simple.new
10
- I18n.backend.send(:init_translations) # so our translations won't be overwritten by Rails
11
- end
12
-
13
- include Api::Base
14
- # include Api::NonFormatted
15
- end
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
3
-
4
- class I18nMessageCascadeTest < Test::Unit::TestCase
5
- class Message < I18n::Message
6
- include Cascade
7
- end
8
-
9
- def setup
10
- I18n.backend = CascadingBackend.new
11
- Message.cascade_options = { :step => 2, :skip_root => false, :scopes => [:model, :attribute] }
12
- end
13
-
14
- include Api::Base
15
- include Api::Cascade
16
- end
17
-
18
- class I18nMessageCascadeVariantsTest < I18nMessageCascadeTest
19
- class Message < I18nMessageCascadeTest::Message
20
- include Variants
21
- end
22
-
23
- include Api::Variants
24
- end
25
-
@@ -1,16 +0,0 @@
1
- # encoding: utf-8
2
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
3
-
4
- class I18nMessageFormattedTest < Test::Unit::TestCase
5
- class Format < I18n::Message::Format
6
- include I18n::Message::Variants
7
- end
8
-
9
- class Message < I18n::Message
10
- include Formatted
11
- self.format_class = Format
12
- end
13
-
14
- include Api::Base
15
- include Api::Formatted
16
- end
@@ -1,19 +0,0 @@
1
- # encoding: utf-8
2
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
3
-
4
- class I18nMessageGettextTest < Test::Unit::TestCase
5
- class Message < I18n::Message
6
- include Gettext
7
- end
8
-
9
- def setup
10
- store_translations(
11
- :foo => 'foo',
12
- :message => 'message',
13
- :'%{foo}' => '%{foo}'
14
- )
15
- end
16
-
17
- include Api::Base
18
- include Api::Gettext
19
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
3
-
4
- class I18nMessageVariantsTest < Test::Unit::TestCase
5
- class Message < I18n::Message
6
- include Variants
7
- end
8
-
9
- include Api::Base
10
- include Api::Variants
11
- end
@@ -1,23 +0,0 @@
1
- module Declarative
2
- def self.included(base)
3
- base.class_eval do
4
- def test(name, &block)
5
- name = "test_#{name.gsub(/\s+/,'_')}".to_sym
6
- block ||= lambda { flunk "No implementation provided for #{name}" }
7
-
8
- defined = instance_method(name) rescue false
9
- raise("#{name} is already defined in #{self}") if defined
10
-
11
- define_method(name, &block)
12
- end
13
- end
14
- end
15
- end
16
-
17
- class Test::Unit::TestCase
18
- include Declarative
19
- end
20
-
21
- class Module
22
- include Declarative
23
- end
@@ -1,27 +0,0 @@
1
- $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
- $:.unshift(File.expand_path(File.dirname(__FILE__)))
3
-
4
- require 'rubygems'
5
- require 'test/unit'
6
- require 'test_case_declarative'
7
- require 'api'
8
-
9
- require 'i18n/message'
10
-
11
- class Test::Unit::TestCase
12
- def teardown
13
- I18n.backend = nil
14
- end
15
-
16
- def message(*args)
17
- self.class.const_get(:Message).new(*args)
18
- end
19
-
20
- def store_translations(data)
21
- I18n.backend.store_translations(:en, data)
22
- end
23
- end
24
-
25
- class CascadingBackend < I18n::Backend::Simple
26
- include I18n::Backend::Cascade
27
- end