model_to_locale 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +99 -0
- data/Rakefile +1 -0
- data/lib/generators/model_to_locale/add_model_generator.rb +17 -0
- data/lib/generators/model_to_locale/create_generator.rb +15 -0
- data/lib/model_to_locale.rb +6 -0
- data/lib/model_to_locale/to_locale.rb +49 -0
- data/lib/model_to_locale/version.rb +3 -0
- data/model_to_locale.gemspec +23 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fd20b1b67dc9e987de221b182a4234c037c67feb
|
4
|
+
data.tar.gz: dac80928482211bba9a95065f10c6d4b0f82fbd5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 397124673a964f0225844ddf17ce37844886cbc6d0e1f8f09a8abff4cbb0e67107dbd8c5c029f8017ef6cfe200c85ec267f6ef042a2fdd93031c5601dda32f0b
|
7
|
+
data.tar.gz: 9e40c852903b5e25fdb57cf5b17b635c815dfca663200c0602b4f25bc76f4aca69dcbd7fbf916fd60129faf6acdaca91a578035d9b20f48eeeafd3d6dbe9677c
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
|
2
|
+
#### [Current]
|
3
|
+
|
4
|
+
####
|
5
|
+
* [3b4d038](../../commit/3b4d038) - __(Muhammet DİLEK)__ desc added to readme.md
|
6
|
+
* [e3b9478](../../commit/e3b9478) - __(Muhammet DİLEK)__ [#1](../../issues/1) gem application created
|
7
|
+
* [ed2ad43](../../commit/ed2ad43) - __(Muhammet DİLEK)__ Initial commit
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Muhammet DİLEK
|
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,99 @@
|
|
1
|
+
# ModelToLocale
|
2
|
+
|
3
|
+
This gem creates locale file from model attributes.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'model_to_locale'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install model_to_locale
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Create a new locale file
|
22
|
+
|
23
|
+
`rails g model_to_locale:create tr`
|
24
|
+
|
25
|
+
`models.tr.yml` file created.
|
26
|
+
|
27
|
+
|
28
|
+
```yml
|
29
|
+
---
|
30
|
+
tr:
|
31
|
+
activerecord:
|
32
|
+
models:
|
33
|
+
profile: Profile
|
34
|
+
group: Group
|
35
|
+
attributes:
|
36
|
+
profile:
|
37
|
+
id: Id
|
38
|
+
first_name: First_name
|
39
|
+
last_name: Last_name
|
40
|
+
gsm: Gsm
|
41
|
+
birthday: Birthday
|
42
|
+
user_id: User_id
|
43
|
+
created_at: Created_at
|
44
|
+
updated_at: Updated_at
|
45
|
+
group:
|
46
|
+
id: Id
|
47
|
+
number: Number
|
48
|
+
name: Name
|
49
|
+
domain_id: Domain_id
|
50
|
+
created_at: Created_at
|
51
|
+
updated_at: Updated_at
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
Add model attributes to locale file
|
56
|
+
|
57
|
+
`rails g model_to_locale:add_model tr --model City`
|
58
|
+
|
59
|
+
`City` model attributes added to `models.tr.yml`.
|
60
|
+
|
61
|
+
```yml
|
62
|
+
---
|
63
|
+
tr:
|
64
|
+
activerecord:
|
65
|
+
models:
|
66
|
+
profile: Profile
|
67
|
+
group: Group
|
68
|
+
city: City
|
69
|
+
attributes:
|
70
|
+
profile:
|
71
|
+
id: Id
|
72
|
+
first_name: First_name
|
73
|
+
last_name: Last_name
|
74
|
+
gsm: Gsm
|
75
|
+
birthday: Birthday
|
76
|
+
user_id: User_id
|
77
|
+
created_at: Created_at
|
78
|
+
updated_at: Updated_at
|
79
|
+
group:
|
80
|
+
id: Id
|
81
|
+
number: Number
|
82
|
+
name: Name
|
83
|
+
domain_id: Domain_id
|
84
|
+
created_at: Created_at
|
85
|
+
updated_at: Updated_at
|
86
|
+
city:
|
87
|
+
id: Id
|
88
|
+
name: Name
|
89
|
+
|
90
|
+
```
|
91
|
+
|
92
|
+
|
93
|
+
## Contributing
|
94
|
+
|
95
|
+
1. Fork it
|
96
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
97
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
98
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
99
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/base'
|
3
|
+
require 'model_to_locale/to_locale'
|
4
|
+
|
5
|
+
module ModelToLocale
|
6
|
+
module Generators
|
7
|
+
class AddModelGenerator < ::Rails::Generators::Base
|
8
|
+
argument :locale, :type => :string, default: "tr"
|
9
|
+
|
10
|
+
class_option :model, :type => :string, :desc => "Model name for locale"
|
11
|
+
|
12
|
+
def create_locale_file
|
13
|
+
ToLocale.add_model( options[:model] , locale)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/base'
|
3
|
+
require 'model_to_locale/to_locale'
|
4
|
+
|
5
|
+
module ModelToLocale
|
6
|
+
module Generators
|
7
|
+
class CreateGenerator < ::Rails::Generators::Base
|
8
|
+
argument :locale, :type => :string, default: "tr"
|
9
|
+
|
10
|
+
def create_locale_file
|
11
|
+
ToLocale.create(locale)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class ToLocale
|
2
|
+
def self.create(locale='tr')
|
3
|
+
models = ActiveRecord::Base.connection.tables.map{|model| model.capitalize.singularize.camelize }
|
4
|
+
data = Hash.new
|
5
|
+
data["#{locale}"] = Hash.new
|
6
|
+
data["#{locale}"]['activerecord'] = Hash.new
|
7
|
+
data["#{locale}"]['activerecord']['models'] = Hash.new
|
8
|
+
data["#{locale}"]['activerecord']['attributes'] = Hash.new
|
9
|
+
|
10
|
+
models.each do |model|
|
11
|
+
data["#{locale}"]['activerecord']['models']["#{model.downcase}"] = model.capitalize
|
12
|
+
data = add_attributes(data, model, locale)
|
13
|
+
end
|
14
|
+
|
15
|
+
write_to_file(data, locale)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.add_model(model, locale='tr')
|
19
|
+
begin
|
20
|
+
data = YAML::load_file(Rails.root.join('config/locales', "models.#{locale}.yml"))
|
21
|
+
data["#{locale}"]['activerecord']['models']["#{model.downcase}"] = model.capitalize
|
22
|
+
data = add_attributes(data, model, locale)
|
23
|
+
write_to_file(data, locale)
|
24
|
+
rescue
|
25
|
+
create(locale)
|
26
|
+
puts "models.#{locale}.yml file not found. Bu it's created now."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def self.write_to_file(data, locale='tr')
|
32
|
+
File.open(Rails.root.join('config/locales', "models.#{locale}.yml"), 'w') do |fo|
|
33
|
+
fo.puts data.to_yaml
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.add_attributes(data, model, locale)
|
38
|
+
begin
|
39
|
+
columns = model.classify.constantize.column_names
|
40
|
+
data["#{locale}"]['activerecord']['attributes']["#{model.downcase}"] = Hash.new
|
41
|
+
columns.each do |column|
|
42
|
+
data["#{locale}"]['activerecord']['attributes']["#{model.downcase}"]["#{column}"] = column.capitalize
|
43
|
+
end
|
44
|
+
rescue
|
45
|
+
puts "Not found #{model} model."
|
46
|
+
end
|
47
|
+
data
|
48
|
+
end
|
49
|
+
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 'model_to_locale/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "model_to_locale"
|
8
|
+
spec.version = ModelToLocale::VERSION
|
9
|
+
spec.authors = ["lab2023"]
|
10
|
+
spec.email = ["info@lab2023.com"]
|
11
|
+
spec.description = %q{Create a locale attributes from model}
|
12
|
+
spec.summary = %q{Create a locale attributes from model}
|
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,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: model_to_locale
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- lab2023
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Create a locale attributes from model
|
42
|
+
email:
|
43
|
+
- info@lab2023.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- CHANGELOG.md
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/generators/model_to_locale/add_model_generator.rb
|
55
|
+
- lib/generators/model_to_locale/create_generator.rb
|
56
|
+
- lib/model_to_locale.rb
|
57
|
+
- lib/model_to_locale/to_locale.rb
|
58
|
+
- lib/model_to_locale/version.rb
|
59
|
+
- model_to_locale.gemspec
|
60
|
+
homepage: ''
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.0.6
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Create a locale attributes from model
|
84
|
+
test_files: []
|