i18n_rails_helpers 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -0,0 +1,119 @@
1
+ module I18nHelpers
2
+ # Returns translated identifier
3
+ def t_page_head
4
+ if params[:id] and resource
5
+ return "%s %s" % [t_title, resource.to_s]
6
+ else
7
+ return t_title
8
+ end
9
+ end
10
+
11
+ # Returns translated name for the given +attribute+.
12
+ #
13
+ # If no +model+ is given, it uses the controller name to guess the model by
14
+ # singularize it.
15
+ #
16
+ # Example:
17
+ # t_attr('first_name', Patient) => 'Vorname'
18
+ # t_attr('first_name') => 'Vorname' # when called in patients_controller views
19
+ #
20
+ def t_attr(attribute, model = nil)
21
+ if model.is_a? Class
22
+ model_class = model
23
+ elsif model.nil?
24
+ model_class = controller_name.classify.constantize
25
+ end
26
+ model_class.human_attribute_name(attribute)
27
+ end
28
+
29
+ # Returns translated name for the given +model+.
30
+ #
31
+ # If no +model+ is given, it uses the controller name to guess the model by
32
+ # singularize it. +model+ can be both a class or an actual instance.
33
+ #
34
+ # Example:
35
+ # t_model(Account) => 'Konto'
36
+ # t_model(Account.new) => 'Konto'
37
+ # t_model => 'Konto' # when called in patients_controller views
38
+ #
39
+ def t_model(model = nil)
40
+ if model.is_a? Class
41
+ model_name = model.name.underscore
42
+ elsif model.nil?
43
+ model_name = controller_name.singularize
44
+ else
45
+ model_name = model.class.name.underscore
46
+ end
47
+ I18n::translate(model_name, :scope => [:activerecord, :models])
48
+ end
49
+
50
+ # Returns translated title for current +action+ on +model+.
51
+ #
52
+ # If no +action+ is given, it uses the current action.
53
+ #
54
+ # If no +model+ is given, it uses the controller name to guess the model by
55
+ # singularize it. +model+ can be both a class or an actual instance.
56
+ #
57
+ # The translation file comming with the plugin supports the following actions
58
+ # by default: index, edit, show, new, delete
59
+ #
60
+ # You may provide controller specific titles in the translation file. The keys
61
+ # should have the following format:
62
+ #
63
+ # #{controller_name}.#{action}.title
64
+ #
65
+ # Example:
66
+ # t_title('new', Account') => 'Konto anlegen'
67
+ # t_title('delete') => 'Konto löschen' # when called in accounts_controller views
68
+ # t_title => 'Konto ändern' # when called in accounts_controller edit view
69
+ #
70
+ def t_title(action = nil, model = nil)
71
+ action ||= action_name
72
+ if model
73
+ context = model.name.pluralize.underscore
74
+ else
75
+ context = controller_name.underscore
76
+ end
77
+
78
+ I18n::translate("#{context}.#{action}.title", :default => [:"crud.title.#{action}"], :model => t_model(model))
79
+ end
80
+ alias :t_crud :t_title
81
+
82
+ # Returns translated string for current +action+.
83
+ #
84
+ # If no +action+ is given, it uses the current action.
85
+ #
86
+ # The translation file comes with the plugin supports the following actions
87
+ # by default: index, edit, show, new, delete, back, next, previous
88
+ #
89
+ # Example:
90
+ # t_action('delete') => 'Löschen'
91
+ # t_action => 'Ändern' # when called in an edit view
92
+ #
93
+ def t_action(action = nil, model = nil)
94
+ action ||= action_name
95
+ I18n::translate(action, :scope => 'crud.action', :model => t_model(model))
96
+ end
97
+
98
+ # Returns translated deletion confirmation for +record+.
99
+ #
100
+ # It uses +record+.to_s in the message.
101
+ #
102
+ # Example:
103
+ # t_confirm_delete(@account) => 'Konto Kasse wirklich löschen'
104
+ #
105
+ def t_confirm_delete(record)
106
+ I18n::translate('messages.confirm_delete', :model => t_model(record), :record => record.to_s)
107
+ end
108
+
109
+ # Returns translated drop down field prompt for +model+.
110
+ #
111
+ # If no +model+ is given, it tries to guess it from the controller.
112
+ #
113
+ # Example:
114
+ # t_select_prompt(Account) => 'Konto auswählen'
115
+ #
116
+ def t_select_prompt(model = nil)
117
+ I18n::translate('messages.select_prompt', :model => t_model(model))
118
+ end
119
+ end
File without changes
@@ -1,14 +1,11 @@
1
- require 'i18n_rails_helpers'
2
- require 'contextual_link_helpers'
3
- require 'list_link_helpers'
4
1
  require 'rails'
5
2
 
6
3
  module I18nRailsHelpers
7
4
  class Railtie < Rails::Engine
8
- initializer :after_initialize do
9
- ActionController::Base.helper I18nRailsHelpers
10
- ActionController::Base.helper ContextualLinkHelpers
11
- ActionController::Base.helper ListLinkHelpers
5
+ initializer 'i18n_rails_helpers.helper' do
6
+ ActionView::Base.send :include, I18nHelpers
7
+ ActionView::Base.send :include, ContextualLinkHelpers
8
+ ActionView::Base.send :include, ListLinkHelpers
12
9
  end
13
10
  end
14
11
  end
@@ -1,3 +1,3 @@
1
1
  module I18nRailsHelpers
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
@@ -1,121 +1 @@
1
1
  require 'i18n_rails_helpers/railtie' if defined?(::Rails::Railtie)
2
-
3
- module I18nRailsHelpers
4
- # Returns translated identifier
5
- def t_page_head
6
- if params[:id] and resource
7
- return "%s %s" % [t_title, resource.to_s]
8
- else
9
- return t_title
10
- end
11
- end
12
-
13
- # Returns translated name for the given +attribute+.
14
- #
15
- # If no +model+ is given, it uses the controller name to guess the model by
16
- # singularize it.
17
- #
18
- # Example:
19
- # t_attr('first_name', Patient) => 'Vorname'
20
- # t_attr('first_name') => 'Vorname' # when called in patients_controller views
21
- #
22
- def t_attr(attribute, model = nil)
23
- if model.is_a? Class
24
- model_class = model
25
- elsif model.nil?
26
- model_class = controller_name.classify.constantize
27
- end
28
- model_class.human_attribute_name(attribute)
29
- end
30
-
31
- # Returns translated name for the given +model+.
32
- #
33
- # If no +model+ is given, it uses the controller name to guess the model by
34
- # singularize it. +model+ can be both a class or an actual instance.
35
- #
36
- # Example:
37
- # t_model(Account) => 'Konto'
38
- # t_model(Account.new) => 'Konto'
39
- # t_model => 'Konto' # when called in patients_controller views
40
- #
41
- def t_model(model = nil)
42
- if model.is_a? Class
43
- model_name = model.name.underscore
44
- elsif model.nil?
45
- model_name = controller_name.singularize
46
- else
47
- model_name = model.class.name.underscore
48
- end
49
- I18n::translate(model_name, :scope => [:activerecord, :models])
50
- end
51
-
52
- # Returns translated title for current +action+ on +model+.
53
- #
54
- # If no +action+ is given, it uses the current action.
55
- #
56
- # If no +model+ is given, it uses the controller name to guess the model by
57
- # singularize it. +model+ can be both a class or an actual instance.
58
- #
59
- # The translation file comming with the plugin supports the following actions
60
- # by default: index, edit, show, new, delete
61
- #
62
- # You may provide controller specific titles in the translation file. The keys
63
- # should have the following format:
64
- #
65
- # #{controller_name}.#{action}.title
66
- #
67
- # Example:
68
- # t_title('new', Account') => 'Konto anlegen'
69
- # t_title('delete') => 'Konto löschen' # when called in accounts_controller views
70
- # t_title => 'Konto ändern' # when called in accounts_controller edit view
71
- #
72
- def t_title(action = nil, model = nil)
73
- action ||= action_name
74
- if model
75
- context = model.name.pluralize.underscore
76
- else
77
- context = controller_name.underscore
78
- end
79
-
80
- I18n::translate("#{context}.#{action}.title", :default => [:"crud.title.#{action}"], :model => t_model(model))
81
- end
82
- alias :t_crud :t_title
83
-
84
- # Returns translated string for current +action+.
85
- #
86
- # If no +action+ is given, it uses the current action.
87
- #
88
- # The translation file comes with the plugin supports the following actions
89
- # by default: index, edit, show, new, delete, back, next, previous
90
- #
91
- # Example:
92
- # t_action('delete') => 'Löschen'
93
- # t_action => 'Ändern' # when called in an edit view
94
- #
95
- def t_action(action = nil, model = nil)
96
- action ||= action_name
97
- I18n::translate(action, :scope => 'crud.action', :model => t_model(model))
98
- end
99
-
100
- # Returns translated deletion confirmation for +record+.
101
- #
102
- # It uses +record+.to_s in the message.
103
- #
104
- # Example:
105
- # t_confirm_delete(@account) => 'Konto Kasse wirklich löschen'
106
- #
107
- def t_confirm_delete(record)
108
- I18n::translate('messages.confirm_delete', :model => t_model(record), :record => record.to_s)
109
- end
110
-
111
- # Returns translated drop down field prompt for +model+.
112
- #
113
- # If no +model+ is given, it tries to guess it from the controller.
114
- #
115
- # Example:
116
- # t_select_prompt(Account) => 'Konto auswählen'
117
- #
118
- def t_select_prompt(model = nil)
119
- I18n::translate('messages.select_prompt', :model => t_model(model))
120
- end
121
- end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_rails_helpers
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
4
+ hash: 27
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 5
10
- version: 1.0.5
9
+ - 6
10
+ version: 1.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Simon H\xC3\xBCrlimann (CyT)"
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-07-17 00:00:00 +02:00
19
- default_executable:
18
+ date: 2012-08-14 00:00:00 Z
20
19
  dependencies: []
21
20
 
22
21
  description: Rails i18n view helpers for things like crud actions, models and and attributes.
@@ -28,16 +27,16 @@ extensions: []
28
27
  extra_rdoc_files:
29
28
  - README.markdown
30
29
  files:
30
+ - app/helpers/contextual_link_helpers.rb
31
+ - app/helpers/i18n_helpers.rb
32
+ - app/helpers/list_link_helpers.rb
31
33
  - config/locales/de.yml
32
34
  - config/locales/en.yml
33
- - lib/contextual_link_helpers.rb
34
35
  - lib/i18n_rails_helpers.rb
35
36
  - lib/i18n_rails_helpers/railtie.rb
36
37
  - lib/i18n_rails_helpers/version.rb
37
- - lib/list_link_helpers.rb
38
38
  - rails/init.rb
39
39
  - README.markdown
40
- has_rdoc: true
41
40
  homepage: https://github.com/huerlisi/i18n_rails_helpers
42
41
  licenses: []
43
42
 
@@ -67,9 +66,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
66
  requirements: []
68
67
 
69
68
  rubyforge_project:
70
- rubygems_version: 1.3.7
69
+ rubygems_version: 1.8.24
71
70
  signing_key:
72
71
  specification_version: 3
73
72
  summary: I18n Rails helpers
74
73
  test_files: []
75
74
 
75
+ has_rdoc: