dm-validations-i18n 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Masaki KOMAGATA
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,22 @@
1
+ = dm-validations-i18n
2
+
3
+ Localize error messages in dm-validations.
4
+
5
+ == Usage
6
+
7
+ require 'dm-validations-i18n'
8
+ DataMapper::Validations::I18n.localize! 'ja'
9
+
10
+ == Note on Patches/Pull Requests
11
+
12
+ * Fork the project.
13
+ * Make your feature addition or bug fix.
14
+ * Add tests for it. This is important so I don't break it in a
15
+ future version unintentionally.
16
+ * Commit, do not mess with rakefile, version, or history.
17
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
18
+ * Send me a pull request. Bonus points for topic branches.
19
+
20
+ == Copyright
21
+
22
+ Copyright (c) 2010 Masaki KOMAGATA. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "dm-validations-i18n"
8
+ gem.summary = %Q{localize dm-validations}
9
+ gem.description = %Q{Localize error messages in dm-validations.}
10
+ gem.email = "komagata@gmail.com"
11
+ gem.homepage = "http://github.com/komagata/dm-validations-i18n"
12
+ gem.authors = ["Masaki KOMAGATA"]
13
+ gem.add_development_dependency "shoulda", ">= 2.11.3"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "dm-validations-i18n #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{dm-validations-i18n}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Masaki KOMAGATA"]
12
+ s.date = %q{2010-10-02}
13
+ s.description = %q{Localize error messages in dm-validations.}
14
+ s.email = %q{komagata@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "dm-validations-i18n.gemspec",
27
+ "lib/dm-validations-i18n.rb",
28
+ "locale/en.yml",
29
+ "locale/ja.yml",
30
+ "test/helper.rb",
31
+ "test/test_dm-validations-i18n.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/komagata/dm-validations-i18n}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.7}
37
+ s.summary = %q{localize dm-validations}
38
+ s.test_files = [
39
+ "test/helper.rb",
40
+ "test/test_dm-validations-i18n.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<shoulda>, [">= 2.11.3"])
49
+ else
50
+ s.add_dependency(%q<shoulda>, [">= 2.11.3"])
51
+ end
52
+ else
53
+ s.add_dependency(%q<shoulda>, [">= 2.11.3"])
54
+ end
55
+ end
56
+
@@ -0,0 +1,26 @@
1
+ require 'dm-validations'
2
+ require 'yaml'
3
+
4
+ module DataMapper
5
+ module Validations
6
+ module I18n
7
+ class << self
8
+ def localize!(locale)
9
+ data = {}
10
+ load_locale(locale).each do |key, value|
11
+ data[key.to_sym] = value
12
+ end
13
+ DataMapper::Validations::ValidationErrors.default_error_messages = data
14
+ end
15
+
16
+ def load_locale(locale)
17
+ load_yml File.join(File.dirname(__FILE__), '..', 'locale', "#{locale}.yml")
18
+ end
19
+
20
+ def load_yml(filename)
21
+ YAML::load IO.read(filename)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
data/locale/en.yml ADDED
@@ -0,0 +1,22 @@
1
+ absent: %s must be absent
2
+ inclusion: %s must be one of %s
3
+ invalid: %s has an invalid format
4
+ confirmation: %s does not match the confirmation
5
+ accepted: %s is not accepted
6
+ 'nil': %s must not be nil
7
+ blank: %s must not be blank
8
+ length_between: %s must be between %s and %s characters long
9
+ too_long: %s must be at most %s characters long
10
+ too_short: %s must be at least %s characters long
11
+ wrong_length: %s must be %s characters long
12
+ taken: %s is already taken
13
+ not_a_number: %s must be a number
14
+ not_an_integer: %s must be an integer
15
+ greater_than: %s must be greater than %s
16
+ greater_than_or_equal_to: %s must be greater than or equal to %s
17
+ equal_to: %s must be equal to %s
18
+ not_equal_to: %s must not be equal to %s
19
+ less_than: %s must be less than %s
20
+ less_than_or_equal_to: %s must be less than or equal to %s
21
+ value_between: %s must be between %s and %s
22
+ primitive: %s must be of type %s
data/locale/ja.yml ADDED
@@ -0,0 +1,22 @@
1
+ absent: %sがありません。
2
+ inclusion: %sは%sにありません。
3
+ invalid: %sは不正な値です。
4
+ confirmation: %sが一致しません。
5
+ accepted: %sは受諾できません。
6
+ nil: %sはnil以外を入力してください。
7
+ blank: %sを入力してください。
8
+ length_between: %sは%s文字以上%s文字以内で入力してください。
9
+ too_long: %sは%s文字以内で入力してください。
10
+ too_short: %sは%s文字以上で入力してください。
11
+ wrong_length: %sは%s文字で入力してください。
12
+ taken: %sは既に存在します。
13
+ not_a_number: %sは数字で入力してください。
14
+ not_an_integer: %sは整数で入力してください。
15
+ greater_than: %sは%sより大きい値にしてください。
16
+ greater_than_or_equal_to: %sは%s以上の値にしてください。
17
+ equal_to: %sは%sにしてください。
18
+ not_equal_to: %sは%s以外を入力してください。
19
+ less_than: %sは%sより小さい値にしてください。
20
+ less_than_or_equal_to: %sは%s以下の値にしてください。
21
+ value_between: %sは%s以上%s以下の値にしてください。
22
+ primitive: %sは%s型にしてください。
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'dm-validations-i18n'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,22 @@
1
+ require 'helper'
2
+
3
+ class TestDmValidationsI18n < Test::Unit::TestCase
4
+ context 'load_locale' do
5
+ should "return locale data" do
6
+ assert_equal '%s must be absent', DataMapper::Validations::I18n.load_locale('en')['absent']
7
+ assert_equal '%sがありません。', DataMapper::Validations::I18n.load_locale('ja')['absent']
8
+ end
9
+ end
10
+
11
+ context 'locale!' do
12
+ should "set to default_error_messages" do
13
+ class Foo < DataMapper::Validations::ValidationErrors
14
+ cattr_reader :default_error_messages
15
+ end
16
+
17
+ DataMapper::Validations::I18n.localize!('ja')
18
+
19
+ assert_equal '%sがありません。', Foo.default_error_messages[:absent]
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dm-validations-i18n
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Masaki KOMAGATA
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-02 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 37
30
+ segments:
31
+ - 2
32
+ - 11
33
+ - 3
34
+ version: 2.11.3
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: Localize error messages in dm-validations.
38
+ email: komagata@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.rdoc
46
+ files:
47
+ - .document
48
+ - .gitignore
49
+ - LICENSE
50
+ - README.rdoc
51
+ - Rakefile
52
+ - VERSION
53
+ - dm-validations-i18n.gemspec
54
+ - lib/dm-validations-i18n.rb
55
+ - locale/en.yml
56
+ - locale/ja.yml
57
+ - test/helper.rb
58
+ - test/test_dm-validations-i18n.rb
59
+ has_rdoc: true
60
+ homepage: http://github.com/komagata/dm-validations-i18n
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --charset=UTF-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.3.7
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: localize dm-validations
93
+ test_files:
94
+ - test/helper.rb
95
+ - test/test_dm-validations-i18n.rb