i18n_structure 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6aa22806be2e3a8738c15d783c2ef5e02c46f45a
4
+ data.tar.gz: b3f714c607553a50a81a51a4b8dd5b3f286c63ab
5
+ SHA512:
6
+ metadata.gz: c7f64fb606a68428059024885dbc781efe33100d1e86b33977c177cda06f26846eadb2e4bab816e54dddf2ee11e9b7960114b50071b4ff005c7ae5e2c586d9b6
7
+ data.tar.gz: 58a8c5b416b4acea80736855f73248d4c57214936fea108ac395121bd8915b0be0dd279e60aea7a57a8e800368d5b25ed0e8c3ab5375614556701aac2f8946be
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ # uncomment this line if your project needs to run something other than `rake`:
5
+ # script: bundle exec rspec spec`
6
+ script:
7
+ # - RAILS_ENV=test bundle exec rake db:migrate --trace
8
+ # - bundle exec rake db:test:prepare
9
+ - bundle exec rspec spec/
10
+ cache: bundler
data/README.md CHANGED
@@ -1,12 +1,16 @@
1
1
  # I18nStructure
2
2
 
3
+ [![Code Climate](https://codeclimate.com/github/KMPgroup/i18n-structure.png)](https://codeclimate.com/github/KMPgroup/i18n-structure)
4
+ [![RST](http://rst-it.com/files/rstwithpassion.png)](http://rst-it.com) [![RST](http://rst-it.com/files/howwedoapps.png)](http://howwedoapps.com)
5
+ [![Build Status](https://travis-ci.org/rstgroup/i18n-structure.svg?branch=add_views)](https://travis-ci.org/rstgroup/i18n-structure)
6
+
3
7
  ## Put in order your locale files
4
8
 
5
9
  This gem adds support of nice and nifty structure of locale files to your Rails app.
6
10
  Gem divides translations into two groups:
7
11
 
8
12
  - global namespaced translations: they could be repeated among different pages for different resources: for example **send** or **confirm**
9
- - resource (activerecord) namespaced translations: specyfic for resource, for example **send request**, **add storey**. They are stored in files named after resource (**article.yml**) inside **config/locales/LOCALE_NAME/ar** folder
13
+ - resource (activerecord) namespaced translations: specific for resource, for example **send request**, **add storey**. They are stored in files named after resource (**article.yml**) inside **config/locales/LOCALE_NAME/ar** folder
10
14
 
11
15
  **Supported locale structure:** for example polish translations
12
16
 
@@ -24,6 +28,9 @@ pl:
24
28
  - false
25
29
  tooltips: #/config/locales/pl/tooltips.yml
26
30
  name: Nazwa jest to .. #Some tooltip for name
31
+ views:
32
+ home_page:
33
+ header: naglowek
27
34
  activerecord:
28
35
  attributes:
29
36
  order: #/config/locales/pl/ar/order.yml
@@ -51,8 +58,9 @@ translate_label(key, model=nil, options={}) #alias tl()
51
58
  translate_tooltip(key, model=nil, options={}) #alias tt()
52
59
  translate_attribute(key, model=nil, options={}) #alias ta()
53
60
  translate_collection(key, model=nil, options={}) #alias tc()
61
+ translate_view(key, view_name, options={}) #alias tv()
54
62
 
55
- # and corresponding methods which tests presence of given translation:
63
+ # labels, tooltips and attributes have corresponding methods which tests presence of given translation:
56
64
  translate_label?(key, model=nil, options={}) #alias tl?()
57
65
  ...
58
66
 
@@ -110,7 +118,7 @@ Or install it yourself as:
110
118
 
111
119
  You can generate all necessary locale files by using generator
112
120
 
113
- $ rails g i18nstructure pl #for polish translations
121
+ $ rails g i18n_structure pl #for polish translations
114
122
 
115
123
  Generator also adds:
116
124
 
@@ -21,7 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_runtime_dependency 'rails', '>= 3.0.0'
22
22
  spec.add_development_dependency "bundler", "~> 1.3"
23
23
  spec.add_development_dependency "rake"
24
- spec.add_development_dependency 'rails'
25
24
  spec.add_development_dependency 'draper'
26
25
  spec.add_development_dependency 'rspec'
27
26
  end
@@ -16,11 +16,18 @@ I18n.extend( Module.new{
16
16
  if model
17
17
  translate_attribute(key.to_s+"_collection", model, options)
18
18
  else
19
- I18n.t(key, :scope => [:collections])
19
+ I18n.t(key, {:scope => [:collections]}.merge(options))
20
20
  end
21
21
  end
22
22
  alias_method :tc, :translate_collection
23
23
 
24
+ # views are handled different than other elements
25
+ def translate_view(key, view, options={})
26
+ throw "You have to define model" unless view
27
+ I18n.t(key, {:scope => [:views, view]}.merge(options))
28
+ end
29
+ alias_method :tv, :translate_view
30
+
24
31
  private
25
32
  # change passed object to key used in localization
26
33
  def to_mode_name(model)
@@ -1,3 +1,3 @@
1
1
  module I18nStructure
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -30,11 +30,25 @@ describe I18n do
30
30
 
31
31
  describe ".translate_label_exist?" do
32
32
  it "checks unexisting label" do
33
- expect(I18n.tl?(:some_dummmy_unexisted_key, :also_dummy_model)).to be_false
33
+ expect(I18n.tl?(:some_dummmy_unexisted_key, :also_dummy_model)).to eq(false)
34
34
  end
35
35
 
36
36
  it "checks existing label" do
37
- expect(I18n.translate_label_exist?(:exist_label)).to be_true
37
+ expect(I18n.translate_label_exist?(:exist_label)).to eq(true)
38
+ end
39
+ end
40
+
41
+ describe ".translate_view" do
42
+ it "translates view" do
43
+ expect(I18n.translate_view(:home, :navigation)).to eq "home page"
44
+ end
45
+
46
+ it "translates view using alias" do
47
+ expect(I18n.tv(:home, :navigation)).to eq "home page"
48
+ end
49
+
50
+ it "translates view named as partial" do
51
+ expect(I18n.tv(:first_text, :_soma_partial)).to eq "first text"
38
52
  end
39
53
  end
40
54
  end
data/spec/locales/en.yml CHANGED
@@ -18,4 +18,9 @@ en:
18
18
  attributes:
19
19
  foo: foobar_global
20
20
  labels:
21
- exist_label: it exist!
21
+ exist_label: it exist!
22
+ views:
23
+ navigation:
24
+ home: home page
25
+ _soma_partial:
26
+ first_text: first text
metadata CHANGED
@@ -1,110 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_structure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 0.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Wojciech Krysiak
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-12-04 00:00:00.000000000 Z
11
+ date: 2014-08-22 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.0.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 3.0.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '1.3'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '1.3'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: rails
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
52
+ - - ">="
76
53
  - !ruby/object:Gem::Version
77
54
  version: '0'
78
55
  - !ruby/object:Gem::Dependency
79
56
  name: draper
80
57
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
58
  requirements:
83
- - - ! '>='
59
+ - - ">="
84
60
  - !ruby/object:Gem::Version
85
61
  version: '0'
86
62
  type: :development
87
63
  prerelease: false
88
64
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
65
  requirements:
91
- - - ! '>='
66
+ - - ">="
92
67
  - !ruby/object:Gem::Version
93
68
  version: '0'
94
69
  - !ruby/object:Gem::Dependency
95
70
  name: rspec
96
71
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
72
  requirements:
99
- - - ! '>='
73
+ - - ">="
100
74
  - !ruby/object:Gem::Version
101
75
  version: '0'
102
76
  type: :development
103
77
  prerelease: false
104
78
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
79
  requirements:
107
- - - ! '>='
80
+ - - ">="
108
81
  - !ruby/object:Gem::Version
109
82
  version: '0'
110
83
  description: Create structure for I18n locale files
@@ -114,8 +87,9 @@ executables: []
114
87
  extensions: []
115
88
  extra_rdoc_files: []
116
89
  files:
117
- - .gitignore
118
- - .rspec
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
119
93
  - Gemfile
120
94
  - LICENSE.txt
121
95
  - README.md
@@ -141,27 +115,26 @@ files:
141
115
  homepage: https://github.com/KMPgroup/i18n-structure
142
116
  licenses:
143
117
  - MIT
118
+ metadata: {}
144
119
  post_install_message:
145
120
  rdoc_options: []
146
121
  require_paths:
147
122
  - lib
148
123
  required_ruby_version: !ruby/object:Gem::Requirement
149
- none: false
150
124
  requirements:
151
- - - ! '>='
125
+ - - ">="
152
126
  - !ruby/object:Gem::Version
153
127
  version: '0'
154
128
  required_rubygems_version: !ruby/object:Gem::Requirement
155
- none: false
156
129
  requirements:
157
- - - ! '>='
130
+ - - ">="
158
131
  - !ruby/object:Gem::Version
159
132
  version: '0'
160
133
  requirements: []
161
134
  rubyforge_project:
162
- rubygems_version: 1.8.24
135
+ rubygems_version: 2.2.2
163
136
  signing_key:
164
- specification_version: 3
137
+ specification_version: 4
165
138
  summary: Create structure for I18n locale files
166
139
  test_files:
167
140
  - spec/i18n_extension_spec.rb