localized_model_generator 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +14 -0
- data/lib/generators/rails/localized_active_record/localized_active_record_generator.rb +26 -0
- data/lib/generators/templates/rails/localized_active_record/localize.yml.erb +11 -0
- data/lib/localized_model_generator/version.rb +3 -0
- data/lib/localized_model_generator.rb +5 -0
- data/localized_model_generator.gemspec +23 -0
- metadata +90 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Bernd M. Walter
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# LocalizedModelGenerator
|
2
|
+
|
3
|
+
With this gem you can automatically implement the localized files when you generate a new model.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'localized_model_generator'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install localized_model_generator
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
After installation you can create a new model with
|
22
|
+
|
23
|
+
$ rails g localized_active_record user name:string --locale=es de
|
24
|
+
|
25
|
+
As you can see, all files where generated as if you would use the model generator except the three YML files in /config/locale.
|
26
|
+
These files contain the Active Record translations, which can be used immediatelly in your views.
|
27
|
+
|
28
|
+
If you always have the same languages, you need to translate, you can preset those in your application configuration (/config/application.rb):
|
29
|
+
|
30
|
+
config.generators.locale = %w(de,es)
|
31
|
+
|
32
|
+
Btw: the english localization file is always included!
|
33
|
+
|
34
|
+
Finally, if you want to use this model generator also in your scaffold generator, you have to add the following in your application configuration (/config/application.rb):
|
35
|
+
|
36
|
+
config,gen.orm = localized_active_record
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler"
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
# require "rspec/core/rake_task"
|
5
|
+
# Rspec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
gemspec = eval(File.read("localized_model_generator.gemspec"))
|
8
|
+
|
9
|
+
task :build => "#{gemspec.full_name}.gem"
|
10
|
+
|
11
|
+
file "#{gemspec.full_name}.gem" => gemspec.files + ["localized_model_generator.gemspec"] do
|
12
|
+
system "gem build localized_model_generator.gemspec"
|
13
|
+
system "gem install localized_model_generator-#{LocalizedModelGenerator::VERSION}.gem"
|
14
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Rails
|
2
|
+
module Generators
|
3
|
+
class LocalizedActiveRecordGenerator < NamedBase
|
4
|
+
desc 'This generator creates a model like the original, but adds corresponding locale files in /config/locale'
|
5
|
+
|
6
|
+
source_root File.expand_path("../../../templates/rails/localized_active_record", __FILE__)
|
7
|
+
|
8
|
+
argument :attributes, type: :array, :default => [], :banner => 'field[:type][:index] field[:type][:index]'
|
9
|
+
class_option :locale, required: true, type: :array
|
10
|
+
|
11
|
+
def call_original_model
|
12
|
+
invoke('active_record:model', [name, 'list_order:string', 'name:string'], {migration: true, timestamps: true})
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_localization_file
|
16
|
+
options[:locale].reject {|loc| loc == 'en'}
|
17
|
+
options[:locale].insert(0, 'en')
|
18
|
+
options[:locale].each do |loc|
|
19
|
+
@locale = loc
|
20
|
+
template 'localize.yml.erb', "config/locales/#{singular_name}.#{@locale}.yml"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%= @locale %>:
|
2
|
+
activerecord:
|
3
|
+
models:
|
4
|
+
<%= singular_table_name %>:
|
5
|
+
one: <%= human_name %>
|
6
|
+
other: <%= human_name.pluralize %>
|
7
|
+
attributes:
|
8
|
+
<%= singular_table_name %>:
|
9
|
+
<% for attribute in attributes -%>
|
10
|
+
<%= attribute.name %>: <%= attribute.human_name %>
|
11
|
+
<% end -%>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'localized_model_generator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "localized_model_generator"
|
8
|
+
spec.version = LocalizedModelGenerator::VERSION
|
9
|
+
spec.authors = ["Bernd M. Walter"]
|
10
|
+
spec.email = ["bernd.m.walter@gmail.com"]
|
11
|
+
spec.description = %q{extends the active_record:model generator with locale files in /config/locales. The Translations to the specific languages has still to be made, but the files are still there.}
|
12
|
+
spec.summary = %q{extends the active_record:model generator with locale files}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: localized_model_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bernd M. Walter
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-12-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: extends the active_record:model generator with locale files in /config/locales.
|
47
|
+
The Translations to the specific languages has still to be made, but the files are
|
48
|
+
still there.
|
49
|
+
email:
|
50
|
+
- bernd.m.walter@gmail.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- lib/generators/rails/localized_active_record/localized_active_record_generator.rb
|
61
|
+
- lib/generators/templates/rails/localized_active_record/localize.yml.erb
|
62
|
+
- lib/localized_model_generator.rb
|
63
|
+
- lib/localized_model_generator/version.rb
|
64
|
+
- localized_model_generator.gemspec
|
65
|
+
homepage: ''
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.25
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: extends the active_record:model generator with locale files
|
90
|
+
test_files: []
|