i18n_rails_helpers 0.5.5

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.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
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 ADDED
@@ -0,0 +1,13 @@
1
+ I18nRailsHelpers
2
+ ================
3
+
4
+ Introduction goes here.
5
+
6
+
7
+ Example
8
+ =======
9
+
10
+ Example goes here.
11
+
12
+
13
+ Copyright (c) 2010 [name of plugin creator], released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ # coding: utf-8
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+
6
+ begin
7
+ GEM = "i18n_rails_helpers"
8
+ AUTHOR = "Simon Hürlimann"
9
+ EMAIL = "simon.huerlimann@cyt.ch"
10
+ SUMMARY = "Rails i18n view helpers for things like crud actions, models and and attributes."
11
+ HOMEPAGE = "http://github.com/huerlisi/i18n_rails_helpers/tree/master"
12
+
13
+ gem 'jeweler', '>= 1.0.0'
14
+ require 'jeweler'
15
+
16
+ Jeweler::Tasks.new do |s|
17
+ s.name = GEM
18
+ s.summary = SUMMARY
19
+ s.email = EMAIL
20
+ s.homepage = HOMEPAGE
21
+ s.description = SUMMARY
22
+ s.author = AUTHOR
23
+
24
+ s.require_path = 'lib'
25
+ s.files = %w(MIT-LICENSE README Rakefile) + Dir.glob("{lib,test,rails}/**/*")
26
+
27
+ # Runtime dependencies: When installing i18n_rails_helpers these will be checked if they are installed.
28
+ # Will be offered to install these if they are not already installed.
29
+ s.add_dependency 'activemodel'
30
+ s.add_dependency 'i18n'
31
+ end
32
+
33
+ Jeweler::GemcutterTasks.new
34
+ rescue LoadError
35
+ puts "[i18n_rails_helpers:] Jeweler - or one of its dependencies - is not available. Install it with: sudo gem install jeweler -s http://gemcutter.org"
36
+ end
37
+
38
+ desc 'Default: run unit tests.'
39
+ task :default => :test
40
+
41
+ desc 'Test the i18n_rails_helpers plugin.'
42
+ Rake::TestTask.new(:test) do |t|
43
+ t.libs << 'lib'
44
+ t.libs << 'test'
45
+ t.pattern = 'test/**/*_test.rb'
46
+ t.verbose = true
47
+ end
48
+
49
+ desc 'Generate documentation for the i18n_rails_helpers plugin.'
50
+ Rake::RDocTask.new(:rdoc) do |rdoc|
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = 'I18nRailsHelpers'
53
+ rdoc.options << '--line-numbers' << '--inline-source'
54
+ rdoc.rdoc_files.include('README')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
@@ -0,0 +1,10 @@
1
+ require 'i18n_rails_helpers'
2
+ require 'rails'
3
+
4
+ module I18nRailsHelpers
5
+ class Railtie < Rails::Railtie
6
+ initializer :after_initialize do
7
+ ActionController::Base.helper I18nRailsHelpers
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,75 @@
1
+ module I18nRailsHelpers
2
+ # Returns translated name for the given +attribute+.
3
+ #
4
+ # If no +model+ is given, it uses the controller name to guess the model by
5
+ # singularize it.
6
+ #
7
+ # Example:
8
+ # t_attr('first_name', Patient) => 'Vorname'
9
+ # t_attr('first_name') => 'Vorname' # when called in patients_controller views
10
+ #
11
+ def t_attr(attribute, model = nil)
12
+ if model.is_a? Class
13
+ model_name = model.name.underscore
14
+ elsif model.nil?
15
+ model_name = controller_name.singularize
16
+ end
17
+ I18n::translate(attribute, :scope => [:activerecord, :attributes, model_name])
18
+ end
19
+
20
+ # Returns translated name for the given +model+.
21
+ #
22
+ # If no +model+ is given, it uses the controller name to guess the model by
23
+ # singularize it. +model+ can be both a class or an actual instance.
24
+ #
25
+ # Example:
26
+ # t_model(Account) => 'Konto'
27
+ # t_model(Account.new) => 'Konto'
28
+ # t_model => 'Konto' # when called in patients_controller views
29
+ #
30
+ def t_model(model = nil)
31
+ if model.is_a? Class
32
+ model_name = model.name.underscore
33
+ elsif model.nil?
34
+ model_name = controller_name.singularize
35
+ else
36
+ model_name = model.class.name.underscore
37
+ end
38
+ I18n::translate(model_name, :scope => [:activerecord, :models])
39
+ end
40
+
41
+ # Returns translated title for current +action+ on +model+.
42
+ #
43
+ # If no +action+ is given, it uses the current action.
44
+ #
45
+ # If no +model+ is given, it uses the controller name to guess the model by
46
+ # singularize it. +model+ can be both a class or an actual instance.
47
+ #
48
+ # Example:
49
+ # t_crud('new', Account') => 'Konto anlegen'
50
+ # t_crud('delete') => 'Konto löschen' # when called in accounts_controller views
51
+ # t_crud => 'Konto ändern' # when called in accounts_controller edit view
52
+ #
53
+ def t_crud(action = nil, model = nil)
54
+ if model.is_a? Class
55
+ model_name = model.name.underscore
56
+ elsif model.nil?
57
+ model_name = controller_name.singularize
58
+ end
59
+
60
+ action ||= action_name
61
+ I18n::translate(action, :scope => :crud, :model => model_name.capitalize)
62
+ end
63
+
64
+ # Returns translated deletion confirmation for +record+.
65
+ #
66
+ # It uses +record+.to_s in the message.
67
+ #
68
+ # Example:
69
+ # t_confirm_delete(@account) => 'Konto Kasse wirklich löschen'
70
+ #
71
+ def t_confirm_delete(record)
72
+ I18n::translate('messages.confirm_delete', :model => t_model(record), :record => record.to_s)
73
+ end
74
+ end
75
+
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class I18nRailsHelpersTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_support'
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: i18n_rails_helpers
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 5
8
+ - 5
9
+ version: 0.5.5
10
+ platform: ruby
11
+ authors:
12
+ - "Simon H\xC3\xBCrlimann"
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-24 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activemodel
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: i18n
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
44
+ description: Rails i18n view helpers for things like crud actions, models and and attributes.
45
+ email: simon.huerlimann@cyt.ch
46
+ executables: []
47
+
48
+ extensions: []
49
+
50
+ extra_rdoc_files:
51
+ - README
52
+ files:
53
+ - MIT-LICENSE
54
+ - README
55
+ - Rakefile
56
+ - lib/i18n_rails_helpers.rb
57
+ - lib/i18n_rails_helpers/railtie.rb
58
+ - test/i18n_rails_helpers_test.rb
59
+ - test/test_helper.rb
60
+ has_rdoc: true
61
+ homepage: http://github.com/huerlisi/i18n_rails_helpers/tree/master
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --charset=UTF-8
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.3.6
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Rails i18n view helpers for things like crud actions, models and and attributes.
90
+ test_files:
91
+ - test/test_helper.rb
92
+ - test/i18n_rails_helpers_test.rb